A talk on optimisations around MySQL on the server side, and through the use of PHP extensions to reduce disk writes to provide for more IO access for MySQL. This was presented at SydPHP in October 2011
3. Optimisation Costs
Consider cheaper alternatives
Assess the situation
How long will current system last?
How much effort to correct it?
Can I hack in some performance
later (Probably “Yes”)
4. Optimisation Options
Switch to InnoDB
Avoid table locks
CPU / RAM is cheap
Developer / Admin time is not
Process heavy queries asynchronously
Use a replicated slave (Long queries)
5. In-MySQL Solutions
Clever indexing
Query and Dataset reorganisation
Denormalise / Summarised data
Use “SELECT *” sparingly
Subqueries can be faster
Benchmark differences
7. That didn’t work...
Time to look at MySQL config
Assess what can be done with the OS
OS can hit these walls:
CPU (Run queue, Load average)
Memory (Cheap fix)
Disk (Minimise this if possible)
8. What else?
MySQL is usually memory or disk bound
Memory bound can lead to disk bound
PHP is normally CPU bound
Mostly waiting on a disk or DB
Profile your app - How long waiting
for DB?
9. Is my MySQL app
Memory Bound?
Most definitely
Default my.cnf is probably okay
10. Where can I improve?
SHOW GLOBAL STATUS
Good insight to where to tweak
created_tmp_tables vs
created_tmp_disk_tables
threads_created
sort_merge_passes
11. Basic OS Theory
If the operation doesn’t fit in
memory
The operation swaps to disk
PHP and DB on the same disk
Not a good idea for performance
13. my.cnf
Heap sizes
max_heap_size >=
max_temp_table_size
Tweak... SHOW GLOBAL STATUS LIKE
‘Created_%’
Compare before and after values
for temporary tables
14. Processor Crack
Every process is competing for IO
“top” is a great tool for checking
Shows %age of run queue that is IO
24. PHP Fixes
Memcache
Great for distributed environments
Use for configs
Faster than MySQL query cache
25. PHP Fixes
Whaaaa?
I thought we were talking about MySQL
Limit PHP’s access to the disk
Give MySQL free reign when needed
26. Reduce memory usage
.. or get more memory (its cheap!)
Reduce apache min spares
Or get a better http server
I suggest Nginx!
OS Swap tendency: /proc/sys/vm/
swapiness
27. Disk mounting
Use the “noatime” option for mounts
MySQL - No big deal
Web server
JACKPOT
Every read results in a small
write
28. noatime
Benefits
Only read when we go to read
Whatever the opposite of benefit is
We don’t know when files were last
accessed
Acceptable casualties?
29. Its over!
You may now emerge from your semi-comatose
in-chair sleep, and ask questions.