2016-09-20 67 views
1

我開發了一個PHP和MySQL web應用程序。最近它顯示出放緩的跡象。我在090516上運行了mysql-tuner,正常運行時間爲12天。MySQL數據庫性能調整

服務器規格如下:
- 的Linux的CentOS 6個
- 48處理器
- 64GB RAM

這裏是MySQL調諧器日誌輸出從090516與12D的正常運行時間:

[email protected] [~/mysqltuner]# perl mysqltuner.pl --outputfile /~/mysqltuner/result_mysqltuner.txt 
String found where operator expected at mysqltuner.pl line 3096, near 
     "get_wsrep_option 'gcache.mem_size'" (#1) 
    (S syntax) The Perl lexer knows whether to expect a term or an operator. 
    If it sees what it knows to be a term when it was expecting to see an 
    operator, it gives you this warning. Usually it indicates that an 
    operator or delimiter was omitted, such as a semicolon. 

     (Do you need to predeclare get_wsrep_option?) 
Use of implicit split to @_ is deprecated at mysqltuner.pl line 3179 (#2) 
    (D deprecated, W syntax) It makes a lot of work for the compiler when you 
    clobber a subroutine's argument list, so it's better if you assign the results 
    of a split() explicitly to an array (or list). 

>> MySQLTuner 1.6.10 - Major Hayden <[email protected]> 
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/ 
>> Run with '--help' for additional options and output filtering 

[--] Skipped version check for MySQLTuner script 
[OK] Currently running supported MySQL version 5.6.31-log 
[OK] Operating on 64-bit architecture 

-------- Storage Engine Statistics ----------------------------------------------------------------- 
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA 
[--] Data in MyISAM tables: 913M (Tables: 11) 
[--] Data in InnoDB tables: 12M (Tables: 63) 
[!!] Total fragmented tables: 11 

-------- Security Recommendations ------------------------------------------------------------------ 
[OK] There are no anonymous accounts for any database users 
[OK] All database users have passwords assigned 
[!!] User '[email protected]' has user name as password. 
[--] There are 605 basic passwords in the list. 

-------- CVE Security Recommendations -------------------------------------------------------------- 
[OK] NO SECURITY CVE FOUND FOR YOUR VERSION 
Argument "gcache.mem_size" isn't numeric in addition (+) at mysqltuner.pl line 
     1965 (#3) 
    (W numeric) The indicated string was fed as an argument to an operator 
    that expected a numeric value instead. If you're fortunate the message 
    will identify which operator was so unfortunate. 

Argument "gcache.mem_size" isn't numeric in addition (+) at mysqltuner.pl line 
     1972 (#3) 

-------- Performance Metrics ----------------------------------------------------------------------- 
[--] Up for: 12d 6h 21m 24s (2 q [0.000 qps], 1M conn, TX: 192B, RX: 240B) 
[--] Reads/Writes: 100%/0% 
[--] Binary logging is disabled 
[--] Physical Memory  : 62.8G 
[--] Max MySQL memory : 338.9M 
[--] Other process memory: 505.0M 
[--] Total buffers: 169.0M global + 1.1M per thread (151 max threads) 
[--] P_S Max memory usage: 0B 
Argument "*main::get_wsrep_option" isn't numeric in numeric ge (>=) at 
     mysqltuner.pl line 285 (#3) 
Argument "*main::get_wsrep_option" isn't numeric in numeric ge (>=) at 
     mysqltuner.pl line 288 (#3) 
Argument "*main::get_wsrep_option" isn't numeric in numeric ge (>=) at 
     mysqltuner.pl line 291 (#3) 
[--] Galera GCache Max memory usage: *main::get_wsrep_optionB 
[OK] Maximum reached memory usage: 340.0M (0.53% of installed RAM) 
[OK] Maximum possible memory usage: 338.9M (0.53% of installed RAM) 
[OK] Overall possible memory usage with other process is compatible with memory available 
[OK] Slow queries: 0% (0/2) 
[!!] Highest connection usage: 100% (152/151) 
[OK] Aborted connections: 0.00% (34/1098331) 
[OK] Query cache is disabled by default due to mutex contention. 
[OK] No Sort requiring temporary tables 
[OK] No joins without indexes 
[OK] No tmp tables created on disk 
[OK] Thread cache hit rate: 98% (17K created/1M connections) 
[OK] Table cache hit rate: 100% (381 open/0 opened) 
[OK] Open file limit used: 2% (228/10K) 
[!!] Table locks acquired immediately: 94% 

-------- ThreadPool Metrics ------------------------------------------------------------------------ 
[--] ThreadPool stat is disabled. 

-------- Performance schema ------------------------------------------------------------------------ 
[--] Performance schema is disabled. 
[--] Memory used by P_S: 0B 

-------- MyISAM Metrics ---------------------------------------------------------------------------- 
[OK] Key buffer used: 100.0% (8M used/8M cache) 
[!!] Key buffer size/total MyISAM indexes: 8.0M/147.7M 
[!!] Read Key buffer hit rate: 87.6% (16M cached/1M reads) 
[!!] Write Key buffer hit rate: 56.8% (1M cached/777K writes) 

-------- AriaDB Metrics ---------------------------------------------------------------------------- 
[--] AriaDB is disabled. 

-------- InnoDB Metrics ---------------------------------------------------------------------------- 
[--] InnoDB is enabled. 
[OK] InnoDB buffer pool/data size: 128.0M/12.1M 
[!!] InnoDB buffer pool <= 1G and innodb_buffer_pool_instances(!=1). 
[!!] InnoDB Used buffer: 17.82% (1460 used/ 8192 total) 
[OK] InnoDB Read buffer efficiency: 100.00% (290756388 hits/ 290757478 total) 
[!!] InnoDB Write Log efficiency: 12.12% (3691 hits/ 30446 total) 
[OK] InnoDB log waits: 0.00% (0 waits/34137 writes) 

-------- TokuDB Metrics ---------------------------------------------------------------------------- 
[--] TokuDB is disabled. 

-------- Galera Metrics ---------------------------------------------------------------------------- 
[--] Galera is disabled. 

-------- Replication Metrics ----------------------------------------------------------------------- 
[--] Galera Synchronous replication: NO 
[--] No replication slave(s) for this server. 
[--] This is a standalone server. 

-------- Recommendations --------------------------------------------------------------------------- 
General recommendations: 
    Run OPTIMIZE TABLE to defragment tables for better performance 
    Set up a Secure Password for [email protected] (SET PASSWORD FOR 'user'@'SpecificDNSorIp' = PASSWORD('secure_password');) 
    Reduce or eliminate persistent connections to reduce connection usage 
    Optimize queries and/or use InnoDB to reduce lock wait 
Variables to adjust: 
    max_connections (> 151) 
    wait_timeout (< 28800) 
    interactive_timeout (< 28800) 
    key_buffer_size (> 147.7M) 
    innodb_buffer_pool_instances (=1) 

我很少有東西會跳出來,但我不是經驗豐富的MySQL DBA,因此我正在從堆棧社區尋求建議。請告知我應該在my.cnf中修改哪些設置,並且如果我需要在PHPMYADMIN中對錶進行碎片整理,是否需要在非工作時間內完成。

我沒有注意到我的網絡應用程序放慢速度,直到最近,最近我做了一次內核更新後重新啓動了服務器。目前這篇文章的正常運行時間爲19小時。

**額外信息:** Web應用程序有一個用戶使用移動設備登錄的前端和一個辦公室員工管理提交(這是表單)並將它們發送到不同部門的後端。

如果需要,我可以用munin圖表更新。我知道服務器嚴重過度配置(意味着它有更多的RAM和處理器,而不是必要的,但我希望有更多的不足)。我的問題是,我可以簡單地調整一些my.cnf設置(如mysqltuner建議的和/或由phpmyadmin建議)以提高效率?

+0

請[編輯]你的問題來解釋你的整個應用程序好一點。你的服務器嚴重超配MySQL。它看起來像數據庫客戶端軟件的連接速率非常高。如果這是一個Web應用程序,請嘗試使用連接池並減少處理Web連接的同時進程或線程的數量。 –

+0

感謝您的回覆。 Web應用程序有一個前端,用戶使用移動設備進行登錄,後端則由辦公室員工管理提交(表單)並將其發送到不同的部門。如果需要,我可以用munin圖表更新。我知道服務器嚴重過度配置(意味着它有更多的RAM和處理器,而不是必要的,但我希望有更多的不足)。 我的問題是,我可以簡單地調整一些my.cnf設置(如mysqltuner建議的和/或由phpmyadmin建議)以提高效率? – Aaron

回答

0

在接下來的十年中,MySQL不太可能被重構,使得它可以有效地使用四個以上的處理器。所以,您的供應浪費了44個處理器內核。這似乎太多了。另外,它看起來像MySQL使用的內存少於1GiB。

通常情況下,MySQL是建立起來的,不是up的。含義:大多數擴展基於MySQL的應用程序的人通過使用數據庫的鏡像來完成這項工作。 MariaDB的最新版本有一個多主鏡像方案。

您遇到麻煩的唯一明顯區域就是攪動。您應該編輯您的my.cnf文件以增加您使用的同時連接數。

您需要調查您的Web應用程序是否使用連接池。 Web應用程序需要一段時間才能建立與數據庫的連接,並且如果您要爲每個Web請求重新建立連接,則開放操作可能成爲瓶頸。您的統計信息每天24小時,每天12天,每秒顯示一個以上的新連接。除非您的工作量在一天中的所有24小時內都非常穩定地分佈,否則這意味着您的網絡應用正在以非常高的新連接速度達到峯值。這很可能是你放緩的原因。

你沒有說你正在使用什麼樣的web應用程序平臺。大多數平臺都有連接池操作。大多數Web應用程序使用一套或兩套DBMS憑據(用戶名)來執行所有Web應用程序操作,因此它們可以重用池中的連接。你的統計數據表明你在數據庫上有600多個不同的用戶。這對於一個網絡應用程序來說非常重要。

此外(這是違反直覺的)有時太多的web應用程序線程可能會損害性能。有時用戶體驗限制線程數量會更好,並讓Web服務器排隊來自客戶端的請求,而不是一次嘗試執行太多操作。現代服務器上的TCP堆棧允許SYN請求的合理深度隊列,因此排隊不會顯着。

這是基於您顯示的有限數據的觀點:您的瓶頸不是MySQL。