Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL NOT using the available memory

I'm moving from a shared web hosting company to a VPS. And I'm trying to find the optimum configuration for my system.

For 1 specific table with half a million record, 1 query that was taking few seconds on the previous server is now taking minutes.

I'm trying to improve the response time of my server, so I bought more memory (I have 2GB of RAM, and I can still buy more resources if needed and 2 cores). I have also "cheated" by copying my.cnf of the old company to my VPS:

[mysqld]
read_buffer_size=8M
read_rnd_buffer_size=8M
sort_buffer_size=32M
innodb_additional_mem_pool_size=503M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=16M
innodb_buffer_pool_size=1007M
innodb_log_file_size=256M
innodb_thread_concurrency=8
innodb_autoextend_increment=128
max_connections=8059
max_user_connections=50
thread_cache_size=128
thread_stack=196608
binlog_cache_size=2M
net_read_timeout=30
net_retry_count=10
net_write_timeout=30
thread_concurrency=10
open_files_limit=9940
max_heap_table_size=32M
tmp_table_size=64M
key_buffer_size=512M
key_buffer=128M
myisam_sort_buffer_size=64M
join_buffer=16M
record_buffer=8M
wait_timeout=300
connect_timeout=10
max_allowed_packet=16M
max_connect_errors=100
table_cache=1024
query_cache_size=32M
query_cache_type=1
ft_min_word_len=4
datadir=/var/lib/mysql
tmpdir=/tmp
socket=/var/lib/mysql/mysql.sock
old-passwords=0
[mysqldump]
quick
max_allowed_packet=16M
[myisamchk]
key_buffer=64M
sort_buffer=64M
read_buffer=16M
write_buffer=16M

The problem is that the query is still slow, and the server does not use the available memory!

              total       used       free     shared    buffers     cached
Mem:          2002       1986         15          0          6       1079
-/+ buffers/cache:        901       1101
Swap:         1747          2       1745

Any suggestions?

Regards

like image 774
mossaab Avatar asked Oct 09 '22 15:10

mossaab


1 Answers

You can have a look at using https://github.com/rackerhacker/MySQLTuner-perl

Which you can use to analyse MySQL and it will output recommended settings.

Your settings seem way high for 2gb memory. IE max_connections=8059 That in its self would require way more memory than you have.

[mysqld]
max_connections=100
innodb_buffer_pool_size=256M
query_cache_size=256M
key_buffer_size=256M
innodb_flush_log_at_trx_commit=0
innodb_flush_method=O_DIRECT
query_cache_type=1
query_cache_limit=2M
table_cache=1024
join_buffer_size=4M
thread_cache_size=128
tmp_table_size=256M
max_heap_table_size=256MB

For 2gb RAM you could try using these settings in MySQL These are the recommended settings for one of the 2gb servers I am currently using

like image 125
oOo--STAR--oOo Avatar answered Oct 13 '22 11:10

oOo--STAR--oOo