พี่ๆช่วยด้วย คือยังงี้ ในทุกๆวินาทีจะมีคำสั่ง queryประมาณ 100 transaction(จากuser) และ query ลักษณะแบบนี้คะ เพื่อเช็คว่ามี id ไหมถ้าไม่มี insert
select A from tableA where id = '123456'
ลองทำ index แล้วทำ query cache แล้ว ก็ช่วยให้ query ไวขึ้นประมาณ 0.12วิ
แต่ก็กิน cpuเยอะอยู่ดี ( แต่ ram ใช้ไปแค่ 2 gb จาก 16gb)
ไฟล์ mysqld.cnf อยู่ด้านล่างคะ
นี่สเปคค่ะ
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 24
On-line CPU(s) list: 0-19
Off-line CPU(s) list: 20-23
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 20
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 85
Model name: Intel(R) Xeon(R) Gold 6130 CPU @ 2.10GHz
Stepping: 4
CPU MHz: 2095.077
BogoMIPS: 4190.15
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 1024K
L3 cache: 22528K
NUMA node0 CPU(s): 0-19
=====================================================
ปล.ไฟล์ mysqld.cnf คะ
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
# comment by kridsada 11.12.19
bind-address = 0.0.0.0
#
# * Fine Tuning
#
# add on 2021 08 11
key_buffer_size = 1024M
max_allowed_packet=64M
thread_stack = 256K
#thread_cache_size = 8
sort_buffer_size=2M # from 1M to reduce sort_merge_passes
read_buffer_size=256K # from 1M to reduce handler_read_next RPS
read_rnd_buffer_size=256K # from ? may reduce handler_read_rnd_next RPS
join_buffer_size=128K # from 1M for join row pointers
#start1
thread_cache_size = 100
#test3
#innodb_fast_shutdown=0
#eof3
#innodb_io_capacity=1500 # from 200 to enable higher RD & WD IOPS
#read_rnd_buffer_size=192K # from 256K to reduce handler_read_rnd_next RPS
#innodb_lru_scan_depth=512 # from 1024 for minimum to reduce CPU busy every SECOND
#innodb_change_buffer_max_size=15 # from 25 percent since less than 1% used Del,Ins,Upd
#innodb_flushing_avg_loops=5 # from 30 to reduce innodb_buffer_pool_pages_dirty
#innodb_thread_concurrency=8 # from 6 to utilize more of your 8 core capacity
#innodb_buffer_pool_dump_pct=90 # from 25 percent to warm more of BP on start of
#
#innodb_buffer_pool_size=12G
# improvements for InnoDB:
innodb_buffer_pool_size=8G
innodb_flush_log_at_trx_commit=2
#innodb_log_buffer_size=512M
#innodb_log_file_size=256M
# improvements for MyISAM:
#key_buffer_size=2G
#innodb_buffer_pool_instances=4
# eof
#
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
max_connections = 1300
#max_connections=350
#table_open_cache = 64
#thread_concurrency = 10
#
# * Query Cache Configuration
# n
#
query_cache_limit = 50M
query_cache_size = 1024M
query_cache_type=1
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
#slow_query_log = 1
#slow_query_log_file = /var/log/mysql/mysql-slow.log
#long_query_time = 6
#slow_query_log_file = /var/log/mysql/mysql-slow.log
#long_query_time = 1
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
# Table and TMP Setting
max_heap_table_size=5120M # from 16M to keep same size as tmp_table_size
bulk_insert_buffer_size=5120M
tmp_table_size =5120M
# Table Cache setting
table_open_cache=1024
ที่บอกว่า สร้าง index แล้ว ต้องถามว่า index ที่สร้าง require field ที่ใช้ในการค้นหาหรือไม่
เช่น where id = $search_id ได้นำ field id มาสร้างเป็น index หรือไม่
หรือถ้าใช่แล้วยังช้าอยู๋ อาจจำเป็นต้องกำหนด default order field ใหม่ ใน sql statement ด้วย order clause
select id from tablename where id=$id order by id limit 1