Optimizing MySQL and Apache - Help

Hello,

I have been having some load issues with my server due to the response time in the MySQL server (I suspect that it is due to that). The load hits to 15/20 at peak hours (like just about 2 hours) and is below 1 most of the time.

I have been tracking down the process on what is causing it and it seems it is the ajax chat on about 3 websites on the server. I would like to optimize the server in such a way that the ajax chat does not cause any issue to the server and slow down the other websites on the server.

Here are my 'my.cnf' configs:

[mysqld]
back_log = 75
max_connections = 100
key_buffer = 64M
myisam_sort_buffer_size = 64M
join_buffer_size = 1M
read_buffer_size = 1M
sort_buffer_size = 4M
table_cache = 10M
thread_cache_size = 384
wait_timeout = 106
connect_timeout = 10
tmp_table_size = 32M
max_heap_table_size = 32M
max_allowed_packet = 16M
max_connect_errors = 1000
read_rnd_buffer_size = 524288
bulk_insert_buffer_size = 8M
query_cache_limit = 4M
query_cache_size = 10485760
query_cache_type = 1
query_prealloc_size = 65536
query_alloc_block_size = 131072
local-infile=0
table_cache = 3084
table_definition_cache = 12336
max_heap_table_size = 32M
tmp_table_size = 32M
thread_stack = 128K
innodb_buffer_pool_size = 20M
log_slow_queries = /var/log/mysql/mysql-slow.log
long_query_time = 2
log-queries-not-using-indexes
open_files_limit = 64M
concurrent_insert = 2
default-storage-engine = MyISAM

server-id = 1

[mysqld_safe]
nice = -5
open_files_limit = 8192

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer = 64M
sort_buffer = 64M
read_buffer = 16M
write_buffer = 16M

Output from mysqltuner.pl

 >>  MySQLTuner 1.0.1 - Major Hayden <major@mhtx.net>>>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
 >>  Run with '--help' for additional options and output filtering

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

-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 415M (Tables: 3728)
[--] Data in InnoDB tables: 20M (Tables: 229)
[--] Data in MEMORY tables: 1020K (Tables: 1)
[!!] Total fragmented tables: 358

-------- Performance Metrics -------------------------------------------------
[--] Up for: 1d 8h 19m 15s (5M q [50.661 qps], 401K conn, TX: 16B, RX: 1B)
[--] Reads / Writes: 67% / 33%
[--] Total buffers: 128.0M global + 6.6M per thread (100 max threads)
[OK] Maximum possible memory usage: 790.5M (39% of installed RAM)
[!!] Slow queries: 8% (495K/5M)
[OK] Highest usage of available connections: 77% (77/100)
[OK] Key buffer size / total MyISAM indexes: 64.0M/92.5M
[OK] Key buffer hit rate: 99.7% (41M cached / 112K reads)
[OK] Query cache efficiency: 58.4% (2M cached / 3M selects)
[!!] Query cache prunes per day: 102220
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 348K sorts)
[!!] Joins performed without indexes: 6244
[!!] Temporary tables created on disk: 33% (15K on disk / 47K total)
[OK] Thread cache hit rate: 99% (77 created / 401K connections)
[!!] Table cache hit rate: 4% (3K open / 71K opened)
[OK] Open file limit used: 8% (5K/65K)
[OK] Table locks acquired immediately: 99% (3M immediate / 3M locks)
[!!] InnoDB data size / buffer pool: 20.1M/20.0M

-------- Recommendations -----------------------------------------------------
General recommendations:
    Run OPTIMIZE TABLE to defragment tables for better performance
    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
Variables to adjust:
    query_cache_size (> 10M)
    join_buffer_size (> 1.0M, or always use indexes with joins)
    tmp_table_size (> 32M)
    max_heap_table_size (> 32M)
    table_cache (> 3084)
    innodb_buffer_pool_size (>= 20M)</major@mhtx.net> 

tuning-primer.sh output:

        -- MYSQL PERFORMANCE TUNING PRIMER --
             - By: Matthew Montgomery -

MySQL Version 5.1.41-log x86_64

Uptime = 1 days 8 hrs 20 min 15 sec
Avg. qps = 50
Total Questions = 5899556
Threads Connected = 1

Warning: Server has not been running for at least 48hrs.
It may not be safe to use these recommendations

To find out more information on how each of these
runtime variables effects performance visit:
http://dev.mysql.com/doc/refman/5.1/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 enabled.
Current long_query_time = 2.000000 sec.
You have 496006 out of 5899662 that take longer than 2.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.1/en/point-in-time-recovery.html

WORKER THREADS
Current thread_cache_size = 384
Current threads_cached = 76
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine

MAX CONNECTIONS
Current max_connections = 100
Current threads_connected = 1
Historic max_used_connections = 77
The number of used connections is 77% of the configured maximum.
Your max_connections variable seems to be fine.

INNODB STATUS
Current InnoDB index space = 5 M
Current InnoDB data space = 20 M
Current InnoDB buffer pool free = 12 %
Current innodb_buffer_pool_size = 20 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 : 606 M
Configured Max Per-thread Buffers : 662 M
Configured Max Global Buffers : 96 M
Configured Max Memory Limit : 758 M
Physical Memory : 1.95 G
Max memory limit seem to be within acceptable norms

KEY BUFFER
Current MyISAM index space = 92 M
Current key_buffer_size = 64 M
Key cache miss rate is 1 : 368
Key buffer free ratio = 80 %
Your key_buffer_size seems to be fine

QUERY CACHE
Query cache is enabled
Current query_cache_size = 10 M
Current query_cache_used = 6 M
Current query_cache_limit = 4 M
Current Query cache Memory fill ratio = 63.17 %
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 = 4 M
Current read_rnd_buffer_size = 512 K
Sort buffer seems to be fine

JOINS
Current join_buffer_size = 1.00 M
You have had 6183 queries where a join could not use an index properly
You have had 62 joins without keys that check for key usage after each row
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 = 65535 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 = 3084 tables
Current table_definition_cache = 12336 tables
You have a total of 3981 tables
You have 3084 open tables.
Current table_cache hit rate is 3%
, while 100% of your table cache is in use
You should probably increase your table_cache

TEMP TABLES
Current max_heap_table_size = 32 M
Current tmp_table_size = 32 M
Of 31438 temp tables, 33% 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 = 1 M
Current table scan ratio = 21 : 1
read_buffer_size seems to be fine

TABLE LOCKING
Current Lock Wait ratio = 1 : 13158
Your table locking seems to be fine

I don't understand many of the bits as I have already set them right and it still says that they can be improved?

I have also optimized my Apache to a certain extent although it hasn't made any significant difference.

Server Details:

Core2Duo - (2 processors)

2GB DDRII RAM

WHM/Cpanel + Easy Apache + MySQL 5.1

PHP module - suPHP, PHP 5.2.9

Can anyone help me please to optimize it further?

1 Reply

Ok couple of things

1) schedule a cron job tun run mysqlcheck -A -a -o on your server once a day, that will analyze and optimze your tables.

2) What size linode are you using?

3) Check your /var/log/mysql/mysql-slow.log for slow queries that will give you an indication of what queries are problematic.

4) Once checking /var/log/mysql/mysql-slow.log add indexes on whatever's in the WHERE clause.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct