Tuning: WPMU + MySQL + nginx + PHP
I need some help figuring out the best route to take with the following scenario:
I have a Linode 1024 running 5 seperate WPMU installs. Each install has around ~2000 blogs on it. Despite the large number of blogs there is very little new content - around 1 new post per blog per 2 days.
The Linode is configured with:
nginx
mySQL
PHP with APC
The blog sites themselves are running fine (no noticeable slowdowns so far) but I'm starting to see that my swap is being used so I know that something is misconfigured.
1) Do I need a larger linode? In your opinion does the setup described above absolutely require more resources?
Let me share some configuration files as well:
my.cnf:
[mysqld]
key_buffer = 256M
sort_buffer_size = 4M
read_buffer_size = 4M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 20M
query_cache_size = 60M
#
# * Basic Settings
#
#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#
user = mysql
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
skip-external-locking
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#
# * Fine Tuning
#
#key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
table_cache = 1024
#thread_concurrency = 10
#
# * Query Cache Configuration
#
query_cache_limit = 1M
#query_cache_size = 16M
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
log_error = /var/log/mysql/error.log
# Here you can see queries with especially long duration
#log_slow_queries = /var/log/mysql/mysql-slow.log
#long_query_time = 2
#log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
expire_logs_days = 10
max_binlog_size = 100M
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
#
# * InnoDB
#
# InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
# Read the manual for more InnoDB related options. There are many!
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
'free -m' output:
total used free shared buffers cached
Mem: 1005 986 18 0 8 109
-/+ buffers/cache: 868 136
Swap: 255 255 0
mysqltuner.pl output:
>> 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
Please enter your MySQL administrative login: root
Please enter your MySQL administrative password:
-------- General Statistics --------------------------------------------------
[--] Skipped version check for MySQLTuner script
[OK] Currently running supported MySQL version 5.1.49-1ubuntu8.1
[OK] Operating on 32-bit architecture with less than 2GB RAM
-------- Storage Engine Statistics -------------------------------------------
[--] Status: -Archive -BDB -Federated +InnoDB -ISAM -NDBCluster
[--] Data in MyISAM tables: 3G (Tables: 117982)
[--] Data in InnoDB tables: 20M (Tables: 8)
[!!] Total fragmented tables: 15247
-------- Performance Metrics -------------------------------------------------
[--] Up for: 1m 25s (2K q [28.506 qps], 77 conn, TX: 4M, RX: 323K)
[--] Reads / Writes: 99% / 1%
[--] Total buffers: 386.0M global + 12.3M per thread (151 max threads)
[!!] Allocating > 2GB RAM on 32-bit systems can cause system instability
[!!] Maximum possible memory usage: 2.2G (223% of installed RAM)
[OK] Slow queries: 0% (8/2K)
[OK] Highest usage of available connections: 35% (54/151)
[!!] Key buffer size / total MyISAM indexes: 300.0M/605.5M
[!!] Key buffer hit rate: 84.1% (10K cached / 1K reads)
[OK] Query cache efficiency: 50.8% (1K cached / 2K selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (0 temp sorts / 372 sorts)
[!!] Temporary tables created on disk: 43% (299 on disk / 688 total)
[!!] Thread cache hit rate: 29% (54 created / 77 connections)
[!!] Table cache hit rate: 0% (64 open / 21K opened)
[OK] Open file limit used: 12% (126/1K)
[OK] Table locks acquired immediately: 100% (1K immediate / 1K locks)
[!!] InnoDB data size / buffer pool: 20.7M/8.0M
-------- Recommendations -----------------------------------------------------
General recommendations:
Run OPTIMIZE TABLE to defragment tables for better performance
MySQL started within last 24 hours - recommendations may be inaccurate
Enable the slow query log to troubleshoot bad queries
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:
*** MySQL's maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
key_buffer_size (> 605.5M)
tmp_table_size (> 16M)
max_heap_table_size (> 16M)
thread_cache_size (> 8)
table_cache (> 64)
innodb_buffer_pool_size (>= 20M)</major@mhtx.net>
tuning-primer.sh output:
-- MYSQL PERFORMANCE TUNING PRIMER --
- By: Matthew Montgomery -
MySQL Version 5.1.49-1ubuntu8.1 i686
Uptime = 0 days 1 hrs 52 min 55 sec
Avg. qps = 50
Total Questions = 340356
Threads Connected = 4
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 NOT enabled.
Current long_query_time = 10.000000 sec.
You have 0 out of 340379 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.1/en/point-in-time-recovery.html
WORKER THREADS
Current thread_cache_size = 8
Current threads_cached = 6
Current threads_per_sec = 0
Historic threads_per_sec = 0
Your thread_cache_size is fine
MAX CONNECTIONS
Current max_connections = 151
Current threads_connected = 3
Historic max_used_connections = 15
The number of used connections is 9% of the configured maximum.
You are using less than 10% of your configured max_connections.
Lowering max_connections could help to avoid an over-allocation of memory
See "MEMORY USAGE" section to make sure you are not over-allocating
INNODB STATUS
Current InnoDB index space = 0 bytes
Current InnoDB data space = 22 M
Current InnoDB buffer pool free = 0 %
Current innodb_buffer_pool_size = 8 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 : 609 M
Configured Max Per-thread Buffers : 1.81 G
Configured Max Global Buffers : 326 M
Configured Max Memory Limit : 2.13 G
Physical Memory : 1005 M
nMax memory limit exceeds 90% of physical memory
KEY BUFFER
Current MyISAM index space = 662 M
Current key_buffer_size = 256 M
Key cache miss rate is 1 : 19
Key buffer free ratio = 88 %
Your key_buffer_size seems to be fine
QUERY CACHE
Query cache is enabled
Current query_cache_size = 60 M
Current query_cache_used = 47 M
Current query_cache_limit = 1 M
Current Query cache Memory fill ratio = 79.58 %
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 = 4 M
Sort buffer seems to be fine
JOINS
Current join_buffer_size = 132.00 K
You have had 20 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 = 10161 files
The open_files_limit should typically be set to at least 2x-3x
that of table_cache if you have heavy MyISAM usage.
You currently have open more than 75% of your open_files_limit
You should set a higher value for open_files_limit in my.cnf
TABLE CACHE
Current table_open_cache = 5000 tables
Current table_definition_cache = 256 tables
You have a total of 133343 tables
You have 5000 open tables.
Current table_cache hit rate is 1%
, while 100% of your table cache is in use
You should probably increase your table_cache
You should probably increase your table_definition_cache value.
TEMP TABLES
Current max_heap_table_size = 16 M
Current tmp_table_size = 16 M
Of 47016 temp tables, 44% 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 = 4 M
Current table scan ratio = 15 : 1
read_buffer_size seems to be fine
TABLE LOCKING
Current Lock Wait ratio = 1 : 726
You may benefit from selective use of InnoDB.
If you have long running SELECT's against MyISAM tables and perform
frequent updates consider setting 'low_priority_updates=1'
If you have a high concurrency of inserts on Dynamic row-length tables
consider setting 'concurrent_insert=2'.
I've been playing around with my.cnf. Before the free memory (+/- buffers on free -m) was around 400mb but the swap was completely filled.
I would really appreciate some tuning tips either for this linode or for a proposed larger one if you think thats necessary. I would prefer not to put the DB on a seperate server for now but would look into it if you think that performance would be drastically affected.
Thanks in advance,
Mem
1 Reply
How much memory are you giving APC? Does it have a good hit ratio? Is it filling up?
@memzback:
1) Do I need a larger linode? In your opinion does the setup described above absolutely require more resources?
If it's running fine now, then it doesn't absolutely require more resources, just limits to make sure it doesn't go out of control.