2011-11-29 34 views
2

我的mysql只滿足讀取請求。我認爲,完全利用緩存將是一個好主意。我在虛擬機中運行MySQL,這是在虛擬機內部運行的唯一應用程序。我爲該VM分配2GB內存。我在虛擬機上使用了64位的centos。如果您認爲它已經使用了可以使用的最大內存,那麼我也可以爲該VM分配更多內存。我對理解mysql設置和找出進程使用的內存佔用不是很好,但我有興趣學習如何進行。非常感謝您的幫助。增加MySQL的緩存能力

以上是一些相關的信息我的MySQL:

mysql> show global variables like "%cache%"; 
+------------------------------+----------------------+ 
| Variable_name    | Value    | 
+------------------------------+----------------------+ 
| binlog_cache_size   | 32768    | 
| have_query_cache    | YES     | 
| key_cache_age_threshold  | 300     | 
| key_cache_block_size   | 1024     | 
| key_cache_division_limit  | 100     | 
| max_binlog_cache_size  | 18446744073709547520 | 
| query_cache_limit   | 1048576    | 
| query_cache_min_res_unit  | 4096     | 
| query_cache_size    | 0     | 
| query_cache_type    | ON     | 
| query_cache_wlock_invalidate | OFF     | 
| table_cache     | 64     | 
| thread_cache_size   | 0     | 
+------------------------------+----------------------+ 
13 rows in set (0.00 sec) 


mysql> show global variables like "%buffer%"; 
+-------------------------------+---------+ 
| Variable_name     | Value | 
+-------------------------------+---------+ 
| bulk_insert_buffer_size  | 8388608 | 
| innodb_buffer_pool_awe_mem_mb | 0  | 
| innodb_buffer_pool_size  | 8388608 | 
| innodb_log_buffer_size  | 1048576 | 
| join_buffer_size    | 131072 | 
| key_buffer_size    | 8384512 | 
| myisam_sort_buffer_size  | 8388608 | 
| net_buffer_length    | 16384 | 
| preload_buffer_size   | 32768 | 
| read_buffer_size    | 131072 | 
| read_rnd_buffer_size   | 262144 | 
| sort_buffer_size    | 2097144 | 
+-------------------------------+---------+ 
12 rows in set (0.00 sec) 

mysql> show table status where name="items" 
    -> ; 
+-------+--------+---------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ 
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time   | Update_time   | Check_time | Collation   | Checksum | Create_options | Comment | 
+-------+--------+---------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ 
| items | MyISAM |  10 | Dynamic | 42667 |   346 | 14775916 | 281474976710655 |  1970176 |   0 |   341337 | 2009-07-22 13:31:00 | 2010-10-20 15:37:18 | NULL  | latin1_swedish_ci |  NULL |    |   | 
+-------+--------+---------+------------+-------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+---------------------+------------+-------------------+----------+----------------+---------+ 

這是我的ulimit的輸出-a

[[email protected] root]$ ulimit -a 
core file size   (blocks, -c) 0 
data seg size   (kbytes, -d) unlimited 
scheduling priority    (-e) 0 
file size    (blocks, -f) unlimited 
pending signals     (-i) 8191 
max locked memory  (kbytes, -l) unlimited 
max memory size   (kbytes, -m) unlimited 
open files      (-n) 1024 
pipe size   (512 bytes, -p) 8 
POSIX message queues  (bytes, -q) 819200 
real-time priority    (-r) 0 
stack size    (kbytes, -s) 10240 
cpu time    (seconds, -t) unlimited 
max user processes    (-u) 8191 
virtual memory   (kbytes, -v) unlimited 
file locks      (-x) unlimited 

請讓我知道如果你需要更多的信息。

+0

Doggy SQL比其他任何東西都更致命。 – ajreal

+2

如果你想充分利用你的RAM,不要使用MyISAM存儲引擎 - 只要忘記它。將錶轉換爲InnoDB,並將'innodb_buffer_pool_size'的大小增加到您分配給虛擬機的內存的90%。緩存查詢是好的,執行這些查詢有什麼不好的。這是數據從硬盤中取出的時間。 InnoDB將數據集的工作副本存儲在RAM中,因此顯着提高了性能。正如ajreal所言,狡猾的SQL是致命的。 –

回答

1

對於基本的統計和建議,你可以從mysqltuner.pl腳本開始。不要盲目應用建議,否則可能會降低性能。

MySQLTuner Github page

一個班輪獲取最新版本的腳本並運行它:

curl -sSL mysqltuner.pl | perl 
2

您可以通過啓用查詢緩存實現快速的性能提升!

添加到您的my.cnf:

query_cache_type=1 
query_cache_limit=1M 
query_cache_size=32M 
0

也許你可以考慮使用memcached?然而,去InnoDB表應該立即改進(正如N.B.在評論中所說)