Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยด้วยคะ Mysql กิน CPU 1000% ตลอดไม่รู้จะแก้ยังไงดี



 

ช่วยด้วยคะ Mysql กิน CPU 1000% ตลอดไม่รู้จะแก้ยังไงดี

 



Topic : 136335



โพสกระทู้ ( 4 )
บทความ ( 0 )



สถานะออฟไลน์




help2

พี่ๆช่วยด้วย คือยังงี้ ในทุกๆวินาทีจะมีคำสั่ง 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_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[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

#innodb_buffer_pool_size=13G


# eof1
#test2
#eoftest2
#innodb_log_buffer_size=512M
#innodb_log_file_size=256M

# 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



Tag : PHP, MySQL









ประวัติการแก้ไข
2021-08-13 18:04:39
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2021-08-13 18:02:42 By : doodd View : 1761 Reply : 5
 

 

No. 1



โพสกระทู้ ( 296 )
บทความ ( 0 )



สถานะออฟไลน์


ปัญหา performance ลองโพสต์ถามที่นี่
https://forums.mysql.com/list.php?24






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-13 18:47:29 By : TheGreatGod_of_Death
 


 

No. 2



โพสกระทู้ ( 9,544 )
บทความ ( 2 )



สถานะออฟไลน์


ลองใส่ limit 1 ต่อท้ายเข้าไปด้วย

select id from tablename where id=$id limit 1

แน่่ใจนะว่า ใส่ index เข้าไปแล้ว ข้อมูลมีเท่าไหร่ แล้ว index สร้างตอนไหน สร้างพร้อม create table หรือเปล่า
หรือเพิ่งสร้างตอนข้อมูลเยอะแล้ว
ถ้าข้อมูลเยอะมากๆ แล้วมาสร้าง index ตอนหลัง ต้องรอให้ มันสร้าง index ให้เสร็จก่อน ถีงจะเห็นผล
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-13 19:03:56 By : Chaidhanan
 

 
ตอบความคิดเห็นที่ : 2 เขียนโดย : Chaidhanan เมื่อวันที่ 2021-08-13 19:03:56
รายละเอียดของการตอบ ::
ขอบคุณคะ พอใส่ limit แล้ว cpu ลดลงเห็นได้ชัดเลยเดาว่าเพราะค้นหาไวขึ้นเลยเข้าไวออกไว

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-13 19:41:22 By : doonee
 


 
ตอบความคิดเห็นที่ : 1 เขียนโดย : TheGreatGod_of_Death เมื่อวันที่ 2021-08-13 18:47:29
รายละเอียดของการตอบ ::
ขอบคุณคะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-13 19:42:21 By : doonee
 


 

No. 5



โพสกระทู้ ( 9,544 )
บทความ ( 2 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 3 เขียนโดย : doonee เมื่อวันที่ 2021-08-13 19:41:22
รายละเอียดของการตอบ ::
จากคำตอบนี้


ที่บอกว่า สร้าง 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
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2021-08-14 09:19:40 By : Chaidhanan
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยด้วยคะ Mysql กิน CPU 1000% ตลอดไม่รู้จะแก้ยังไงดี
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่