核心優化參數
- myisam_max_extra_sort_file_size:設足夠大,避免排序文件過大報錯
- delay_key_write:延遲鍵寫入,減少 I/O,提升寫入性能
- bulk_insert_buffer_size:批量插入緩衝區大小
- concurrent_insert = 2:允許並發插入(表尾無洞時)
- read_rnd_buffer_size:隨機掃描緩衝區
- read_buffer_size:順序掃描緩衝區
Key Cache 三種模式與預熱
-- 建立熱/冷緩存
SET GLOBAL hot_cache.key_buffer_size = 16M;
SET GLOBAL cold_cache.key_buffer_size = 16M;
-- 指定表使用對應緩存
CACHE INDEX example.top_message IN hot_cache;
CACHE INDEX example.event IN cold_cache;
-- 預載索引到緩存(忽略葉節點)
LOAD INDEX INTO CACHE example.top_message, example.event IGNORE LEAVES;
LOAD INDEX INTO CACHE example.user IGNORE LEAVES, example.groups;
優化步驟建議
- 基線測試現狀性能
- 調整上述參數
- 配置 Key Cache 分離熱點/冷門表
- 執行預熱腳本
- 壓測驗證效果