(Debian 7 32 位元 KVM,帶 512mb RAM - SSD 儲存 - 1 個 CPU)
伺服器不是mysql專用的。
它在上面運行一個小型論壇。 (Mysql -> 主要讀取)
有人對如何最佳化 MySQL 安裝有任何建議嗎?
伺服器在高峰時段沒有延遲。
謝謝
我的 my.cnf 檔案中目前的配置是:
[mysqld]
#skip-locking
#skip-innodb
#skip-name-resolve
#skip-networking
#skip-bdb
local-infile=0
# Logs
log_error=/var/log/mysql/mysql_error.log
#log_slow_queries=/var/log/mysql/mysql_slow.log
#long_query_time=10
#log-queries-not-using-indexes
# Buffers
key_buffer_size=16M
sort_buffer_size=1M
join_buffer_size=1M
max_join_size=2M
#Threads
thread_concurrency=2
thread_cache_size=1
#Table_cache
table_cache=1024
#Temp tables
max_heap_table_size=128M
tmp_table_size=128M
#Query_cache
query_cache_limit=1M
query_cache_size=16M
#Timeouts
interactive_timeout=90
wait_timeout=90
#Connections
max_connections=50
#[innodb]
innodb_buffer_pool_size=128M
innodb_file_per_table=1
innodb_log_file_size=5M
innodb_thread_concurrency=1
當我運行 MySQLTuner 時,我得到的是:
>> MySQLTuner 1.3.0 - Major Hayden <[email protected]>
>> Bug reports, feature requests, and downloads at http://mysqltuner.com/
>> Run with '--help' for additional options and output filtering
[OK] Logged in using credentials from debian maintenance account.
[OK] Currently running supported MySQL version 5.5.36-34.2-648.wheezy
[OK] Operating on 32-bit architecture with less than 2GB RAM
-------- Storage Engine Statistics -------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MRG_MYISAM
[--] Data in MyISAM tables: 5M (Tables: 64)
[--] Data in InnoDB tables: 82M (Tables: 195)
[--] Data in PERFORMANCE_SCHEMA tables: 0B (Tables: 17)
[--] Data in MEMORY tables: 252K (Tables: 3)
[!!] Total fragmented tables: 26
-------- Security Recommendations -------------------------------------------
[OK] All database users have passwords assigned
-------- Performance Metrics -------------------------------------------------
[--] Up for: 8d 4h 46m 25s (2M q [3.459 qps], 181K conn, TX: 7B, RX: 521M)
[--] Reads / Writes: 54% / 46%
[--] Total buffers: 304.0M global + 2.6M per thread (50 max threads)
[!!] Maximum possible memory usage: 432.1M (86% of installed RAM)
[OK] Slow queries: 0% (0/2M)
[OK] Highest usage of available connections: 62% (31/50)
[OK] Key buffer size / total MyISAM indexes: 16.0M/5.1M
[OK] Key buffer hit rate: 99.8% (1M cached / 2K reads)
[OK] Query cache efficiency: 74.4% (1M cached / 1M selects)
[!!] Query cache prunes per day: 3959
[OK] Sorts requiring temporary tables: 0% (21 temp sorts / 81K sorts)
[!!] Joins performed without indexes: 30762
[!!] Temporary tables created on disk: 46% (74K on disk / 160K total)
[OK] Thread cache hit rate: 86% (25K created / 181K connections)
[!!] Table cache hit rate: 10% (347 open / 3K opened)
[OK] Open file limit used: 8% (178/2K)
[OK] Table locks acquired immediately: 99% (1M immediate / 1M locks)
[OK] InnoDB buffer pool / data size: 128.0M/82.8M
[OK] InnoDB log waits: 0
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
Reduce your overall MySQL memory footprint for system stability
Enable the slow query log to troubleshoot bad queries
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries without LIMIT clauses
Increase table_cache gradually to avoid file descriptor limits
Read this before increasing table_cache over 64: http://bit.ly/1mi7c4C
Variables to adjust:
query_cache_size (> 16M)
join_buffer_size (> 1.0M, or always use indexes with joins)
tmp_table_size (> 128M)
max_heap_table_size (> 128M)
table_cache (> 1024)
當我運行 TUNING PRIMER 時,我得到的是:
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 5.5.36-34.2-648.wheezy i686
Uptime = 8 days 4 hrs 47 min 29 sec
Avg. qps = 3
Total Questions = 2450393
Threads Connected = 1
Server has been running for over 48hrs.
It should be safe to follow these recommendations
To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html
Visit http://www.mysql.com/products/enterprise/advisors.html
for info about MySQL's Enterprise Monitoring and Advisory Service
SLOW QUERIES
The slow query log is NOT enabled.
Current long_query_time = 10.000000 sec.
You have 0 out of 2450414 that take longer than 10.000000 sec. to complete
Your long_query_time seems to be fine
BINARY UPDATE LOG
The binary update log is NOT enabled.
You will not be able to do point in time recovery
See http://dev.mysql.com/doc/refman/5.5/en/point-in-time-recovery.html
WORKER THREADS
Current thread_cache_size = 1
Current threads_cached = 0
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine
MAX CONNECTIONS
Current max_connections = 50
Current threads_connected = 1
Historic max_used_connections = 31
The number of used connections is 62% of the configured maximum.
Your max_connections variable seems to be fine.
INNODB STATUS
Current InnoDB index space = 25 M
Current InnoDB data space = 82 M
Current InnoDB buffer pool free = 13 %
Current innodb_buffer_pool_size = 128 M
Depending on how much space your innodb indexes take up it may be safe
to increase this value to up to 2 / 3 of total system memory
MEMORY USAGE
Max Memory Ever Allocated : 255 M
Configured Max Per-thread Buffers : 128 M
Configured Max Global Buffers : 176 M
Configured Max Memory Limit : 304 M
Physical Memory : 502 M
Max memory limit seem to be within acceptable norms
KEY BUFFER
Current MyISAM index space = 5 M
Current key_buffer_size = 16 M
Key cache miss rate is 1 : 513
Key buffer free ratio = 67 %
Your key_buffer_size seems to be fine
QUERY CACHE
Query cache is enabled
Current query_cache_size = 16 M
Current query_cache_used = 9 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 60.50 %
Current query_cache_min_res_unit = 4 K
MySQL won't cache query results that are larger than query_cache_limit in size
SORT OPERATIONS
Current sort_buffer_size = 1 M
Current read_rnd_buffer_size = 256 K
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 1.00 M
You have had 30765 queries where a join could not use an index properly
You should enable "log-queries-not-using-indexes"
Then look for non indexed joins in the slow query log.
If you are unable to optimize your queries you may want to increase your
join_buffer_size to accommodate larger joins in one pass.
Note! This script will still suggest raising the join_buffer_size when
ANY joins not using indexes are found.
OPEN FILES LIMIT
Current open_files_limit = 2109 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
Your open_files_limit value seems to be fine
TABLE CACHE
Current table_open_cache = 1024 tables
Current table_definition_cache = 400 tables
You have a total of 303 tables
You have 348 open tables.
The table_cache value seems to be fine
TEMP TABLES
Current max_heap_table_size = 128 M
Current tmp_table_size = 128 M
Of 86516 temp tables, 46% were created on disk
Perhaps you should increase your tmp_table_size and/or max_heap_table_size
to reduce the number of disk-based temporary tables
Note! BLOB and TEXT columns are not allow in memory tables.
If you are using these columns raising these values might not impact your
ratio of on disk temp tables.
TABLE SCANS
Current read_buffer_size = 128 K
Current table scan ratio = 489 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 178950
Your table locking seems to be fine
答案1
有幾點考慮:
- 您注意到資料庫在高峰期間沒有任何問題。為什麼要修復沒有損壞的東西
- 效能調整從您擁有的架構/資料庫開始。在您開始調優之前,資料類型、限制、索引都會對您的效能產生影響。
- 你的讀/寫百分比是多少?
- 您執行的一些效能檢查可能會顯示傾斜的資料。
- 硬體是另一回事。你說你使用SSD來儲存。對於您的大小/負載的資料庫伺服器來說,這會讓任何配置調整都變得困難重重。資料庫喜歡 ram :) 特別是像 innodb 這樣的引擎。
- 將儲存引擎與您在資料庫中儲存的資料類型相符。
- 根據系統記憶體調整緩衝區。例如:您最多有 50 個連接,每個連接獲得 2.6m,因此您的伺服器上已經有 +100m,並且已經佔總 RAM 的 25%。
- 開啟關閉未使用的引擎和功能。
- 查詢快取可能非常好,也可能非常糟糕。如果您有很多獨特的查詢,您不妨將其關閉。修剪的數量也可以表示快取太小。不要去大公司,那樣會很容易造成開銷。
- 使用 Slowquery 日誌查看哪些查詢可能會對您的伺服器造成麻煩並分析這些查詢。
- 例如,閱讀真正了解事物的人;)這裡
- 如果您只有一個地方可以“測試”,請務必小心!
你問的問題別人很難回答。你運行的腳本是一個好的開始。使用幾個不同的腳本來測試您傳回的資料是否符合您的預期並且彼此一致。
我目前的開箱即用建議是確保不會對伺服器的其餘部分造成不穩定,因為伺服器目前可能會耗盡機器中的大部分記憶體。當然,512m 並不是一個很大的工作空間,但仍然..所以從降低全域緩衝區開始,而不損失效能。
mysqltuner 腳本中的 A 是磁碟上的 tmp 表。在較大的環境中,這些通常是效能殺手。
看到您使用的是 SSD,我認為最小配置和超級調整的 cnf 之間的差異不會產生明顯的差異。當然,如果沒有任何設計不良的模式/資料庫的話。
當您認為效能良好時停止效能調優。這是一項從未真正完成的任務。這是一個核心主題,可能性是無限的。您可能會浪費大量時間來調整資料庫的一小部分......而人類永遠不會注意到您規模的環境中的差異。
我絕不是專業人士,所以我可能是錯的。但我去過那裡,只是想分享我的經驗。我希望他們能幫忙