2014-05-06 125 views
-1

我管理,它流式视频网站,该网站流失:100%MySQL的CPU使用率

英特尔(R)至强(R)CPU E31220 @ 3.10GHz

16 GB RAM

2×2TB RAID1

不计量的1Gbit带宽不是一个问题,因为使用仅150-250mbit等

在这个机器上,我运行以下命令: - 阿帕奇如果你有任何问题,请联系我们,我们会尽快为你解答。如果您有任何疑问,请联系我们。 。所以现在我注意到网站加载速度较慢..我相信这是因为mysql使用了100%cpu。下面我粘贴我的顶部,也是我的MySQL设置..有人可以帮助我的MySQL设置,以减缓这一点?

我意识到在某些时候我需要将mysql服务器自己移动到另一台机器上,但我仍然认为即使在即将发布的当前设置下,它仍然会使用100%cpu, ..所以我认为这些设置需要改变?或有人可以指导我。此外,我不能降低wait_timeout,因为当我这样做时,它会导致视频转换脚本中的错误,它获取视频并转换它们,有时可能需要一段时间,所以我不知道这是否是问题或什么

my.cnf: 
# * Fine Tuning 
# 
max_allowed_packet  = 16M 
thread_stack   = 1M 
thread_cache_size  = 50 
# This replaces the startup script and checks MyISAM tables if needed 
# the first time they are touched 
myisam-recover   = BACKUP 
max_connections  = 1000 
wait_timeout   = 20000 
tmp_table_size   = 500M 
max_heap_table_size  = 1000M 
table_cache   = 1000 
#thread_concurrency  = 10 
# 
# * Query Cache Configuration 
# 
query_cache_limit  = 4M 
query_cache_size  = 64M 
# 
# * 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 
#log_slow_queries  = /var/log/mysql/mysql-slow.log 
#long_query_time = 2 
#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 



[mysqldump] 
quick 
quote-names 
max_allowed_packet  = 16M 

[mysql] 
#no-auto-rehash # faster start of mysql but no tab completition 

[isamchk] 
key_buffer_size    = 64M 

---------------------------------------- 

    >> MySQLTuner 1.1.1 - Major Hayden <[email protected]> 
    >> Bug reports, feature requests, and downloads at [url]http://mysqltuner.com/[/url] 
    >> Run with '--help' for additional options and output filtering 
    [!!] Successfully authenticated with no password - SECURITY RISK! 

-------- General Statistics -------------------------------------------------- 

    [--] Skipped version check for MySQLTuner script 
    [OK] Currently running supported MySQL version 5.5.37-0ubuntu0.13.10.1 
    [OK] Operating on 64-bit architecture 

-------- Storage Engine Statistics ------------------------------------------- 

    [--] Status: +Archive -BDB -Federated +InnoDB -ISAM -NDBCluster 
    [--] Data in MyISAM tables: 1G (Tables: 41) 
    [--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17) 
    [!!] InnoDB is enabled but isn't being used 
    [!!] Total fragmented tables: 4 

-------- Security Recommendations ------------------------------------------- 

    [OK] All database users have passwords assigned 

-------- Performance Metrics ------------------------------------------------- 
[--] Up for: 22h 23m 46s (5M q [69.809 qps], 1M conn, TX: 8B, RX: 4B) 
[--] Reads/Writes: 29%/71% 
[--] Total buffers: 716.0M global + 3.5M per thread (1000 max threads) 
[OK] Maximum possible memory usage: 4.1G (26% of installed RAM) 
[OK] Slow queries: 0% (2/5M) 
[OK] Highest usage of available connections: 77% (775/1000) 
[OK] Key buffer size/total MyISAM indexes: 8.0M/119.0M 
[OK] Key buffer hit rate: 99.4% (33M cached/208K reads) 
[OK] Query cache efficiency: 67.6% (1M cached/1M selects) 
[OK] Query cache prunes per day: 0 
[OK] Sorts requiring temporary tables: 0% (0 temp sorts/921 sorts) 
[!!] Temporary tables created on disk: 28% (244 on disk/849 total) 
[OK] Thread cache hit rate: 98% (17K created/1M connections) 
[OK] Table cache hit rate: 62% (428 open/681 opened) 
[OK] Open file limit used: 9% (476/5K) 
[!!] Table locks acquired immediately: 55% 

-------- Recommendations ----------------------------------------------------- 
General recommendations: 
    Add skip-innodb to MySQL configuration to disable InnoDB 
    Run OPTIMIZE TABLE to defragment tables for better performance 
    MySQL started within last 24 hours - recommendations may be inaccurate 
    Enable the slow query log to troubleshoot bad queries 
    Temporary table size is already large - reduce result set size 
    Reduce your SELECT DISTINCT queries without LIMIT clauses 
    Optimize queries and/or use InnoDB to reduce lock wait 
------------------------------------------------------- 

它说运行优化表,但我该怎么做?在网上我试图搜索,发现运行mysql检查命令,但我得到

# mysqlcheck -u root -p --auto-repair --check --optimize --all-databases 
Error: mysqlcheck doesn't support multiple contradicting commands. 

此外,是否可以安全地只是优化数据库?它不会伤害它或任何东西?当然,生病先备份

我现在已经启用慢查询日志,但到目前为止,还没有什么..

在一个点上,Mysqltuner是说我已经达到千分之九百九十六连接..但是当我去去提高max_connections到2000年,然后我重新启动mysql服务器,该网站变得比以前更慢..也许我不应该重新启动mysql服务器,只是调整全球?

top - 23:27:42 up 11 days, 5:28, 3 users, load average: 2.41, 4.40, 5.97 
Tasks: 269 total, 3 running, 265 sleeping, 0 stopped, 1 zombie 
%Cpu(s): 24.3 us, 5.6 sy, 0.0 ni, 69.3 id, 0.3 wa, 0.0 hi, 0.5 si, 0.0 st 
KiB Mem: 16408692 total, 16237624 used, 171068 free,  9552 buffers 
KiB Swap: 15624184 total,  8220 used, 15615964 free, 15072644 cached 

    PID USER  PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND                
29178 mysql  20 0 2662m 73m 7280 S 100.4 0.5 4:49.03 /usr/sbin/mysqld              
29428 daemon 20 0 544m 19m 7048 S 2.7 0.1 0:07.81 /usr/sbin/apache2 -k start            
29943 daemon 20 0 543m 17m 5428 S 2.0 0.1 0:02.57 /usr/sbin/apache2 -k start            
29945 daemon 20 0 543m 17m 5352 S 2.0 0.1 0:00.76 /usr/sbin/apache2 -k start            
29672 daemon 20 0 543m 16m 4696 S 1.7 0.1 0:00.63 /usr/sbin/apache2 -k start            
29792 daemon 20 0 544m 17m 5396 S 1.3 0.1 0:00.15 /usr/sbin/apache2 -k start            
    183 root  20 0  0 0 0 S 1.0 0.0 8:51.20 [md0_raid1]               
29445 daemon 20 0 543m 16m 4700 S 0.7 0.1 0:01.04 /usr/sbin/apache2 -k start            
29744 daemon 20 0 543m 16m 5384 S 0.7 0.1 0:00.23 /usr/sbin/apache2 -k start            
7705 root  35 15  0 0 0 D 0.3 0.0 2:27.65 [md0_resync]               
29435 daemon 20 0 543m 17m 5596 S 0.3 0.1 0:00.37 /usr/sbin/apache2 -k start            
29451 daemon 20 0 543m 17m 5356 S 0.3 0.1 0:00.44 /usr/sbin/apache2 -k start            
29453 daemon 20 0  0 0 0 Z 0.3 0.0 0:00.07 [apache2] <defunct>             
29501 daemon 20 0 543m 16m 5324 S 0.3 0.1 0:00.10 /usr/sbin/apache2 -k start            
29518 daemon 20 0 543m 17m 5948 S 0.3 0.1 0:00.31 /usr/sbin/apache2 -k start            
29534 daemon 20 0 543m 17m 5456 S 0.3 0.1 0:00.42 /usr/sbin/apache2 -k start            
29539 daemon 20 0 543m 16m 5348 S 0.3 0.1 0:00.24 /usr/sbin/apache2 -k start            
29542 daemon 20 0 543m 16m 4680 S 0.3 0.1 0:00.51 /usr/sbin/apache2 -k start            
29549 daemon 20 0 543m 17m 5352 S 0.3 0.1 0:00.90 /usr/sbin/apache2 -k start            
29656 daemon 20 0 543m 16m 4792 S 0.3 0.1 0:00.25 /usr/sbin/apache2 -k start            
29673 daemon 20 0 543m 16m 5392 R 0.3 0.1 0:00.20 /usr/sbin/apache2 -k start            
29682 daemon 20 0 543m 16m 4704 S 0.3 0.1 0:00.58 /usr/sbin/apache2 -k start            
29791 daemon 20 0 543m 17m 5392 S 0.3 0.1 0:00.81 /usr/sbin/apache2 -k start            
29793 daemon 20 0 543m 17m 5712 S 0.3 0.1 0:00.12 /usr/sbin/apache2 -k start            
29926 daemon 20 0 543m 16m 4704 S 0.3 0.1 0:00.44 /usr/sbin/apache2 -k start            
29956 daemon 20 0 543m 16m 4700 S 0.3 0.1 0:00.33 /usr/sbin/apache2 -k start  

===================================== 


# free -tm 
      total  used  free  shared buffers  cached 
Mem:   16024  15861  162   0   4  14351 
-/+ buffers/cache:  1506  14517 
Swap:  15257   8  15249 
Total:  31282  15870  15411 

其他问题: 如果我做了MySQL迁移到自己的机器,如果硬盘是固态硬盘?是更好的MySQL?并且将RAM的32 GB的足够

在数据库中的最重要的事情是会话表,可以得到一样大的1.5 GB迄今..但我清楚它和数据库缩小到小于100MB

+1

应该在[服务器故障](http://www.serverfault.com)上询问这个问题。 – vvanasten

+0

增加查询缓存后,mysql仍然使用100%cpu。我把key_buffer_size增加到了256mb,现在它做得稍微好一些,但总体上仍然使用50到90%cpu的时间..这是正常的吗? – user3609978

回答

0

我相信你同时不能--check--optimize,因为--check的意思是“只检查,不要碰任何东西”。

MySQL使用大量的CPU并不正常,因为它的主要目标是存储和获取信息,而不是处理它。它应该使用大量的内存,事实上允许MySQL使用尽可能多的内存是很好的。毕竟,未使用的内存浪费了内存。我看到MySQL正在使用0.5%。这确实是一个不好的迹象。调整您的查询缓存。

您可能会在您的网站中过度使用SQL查询,但如果我不得不猜测,我认为您的问题可能是表中没有正确的索引。

当您执行诸如SELECT * FROM parent, child WHERE child.parent_id = parent.id之类的操作时,parent.idPRIMARY KEY以便允许MySQL更高效地执行任务非常重要。

+0

我应该如何将我的query_cache_limit设置为?从4米到?如果机器有16gb的内存条 当我设置查询缓存大小说.. 264或.. 1600 ..然后我重新启动mysql服务器 其喜欢的网站永远加载 – user3609978

+0

设置它为8GB可能是一个好的开始。如果您不认为Apache或其他进程需要剩下的8GB的东西,您可以将其调整到12GB。 – Havenard