MySQL Performance - SydPHP October 2011

1,232 views
1,155 views

Published on

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

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,232
On SlideShare
0
From Embeds
0
Number of Embeds
95
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • MySQL Performance - SydPHP October 2011

    1. 1. MySQL Performance It ain’t just indexing!
    2. 2. OverviewYou’ve done indexingYou’ve optimised queriesYou need more oomphYou’ll need to dig around a bit moreMySQL config and server admin
    3. 3. Optimisation CostsConsider cheaper alternativesAssess the situation How long will current system last? How much effort to correct it? Can I hack in some performance later (Probably “Yes”)
    4. 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. 5. In-MySQL SolutionsClever indexingQuery and Dataset reorganisationDenormalise / Summarised dataUse “SELECT *” sparinglySubqueries can be fasterBenchmark differences
    6. 6. In-MySQL SolutionsIn-Memory temporary tablesStored procedures are super fast
    7. 7. That didn’t work...Time to look at MySQL configAssess what can be done with the OSOS can hit these walls: CPU (Run queue, Load average) Memory (Cheap fix) Disk (Minimise this if possible)
    8. 8. What else?MySQL is usually memory or disk bound Memory bound can lead to disk boundPHP is normally CPU bound Mostly waiting on a disk or DB Profile your app - How long waiting for DB?
    9. 9. Is my MySQL app Memory Bound?Most definitelyDefault my.cnf is probably okay
    10. 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. 11. Basic OS TheoryIf the operation doesn’t fit inmemoryThe operation swaps to diskPHP and DB on the same diskNot a good idea for performance
    12. 12. my.cnfQuick guides on my.cnf http://bit.ly/VKmcQ http://bit.ly/3pqQc
    13. 13. my.cnfHeap sizes max_heap_size >= max_temp_table_size Tweak... SHOW GLOBAL STATUS LIKE ‘Created_%’ Compare before and after values for temporary tables
    14. 14. Processor CrackEvery process is competing for IO“top” is a great tool for checkingShows %age of run queue that is IO
    15. 15. Are we swapping?Swapping is bad...mkay?Swapping != lotsof disk IOIts compsumptionof Memory
    16. 16. iostatShows IO activity Bytes read, writtenEasy to see IO
    17. 17. iostatOnly works on a per-partition basisPlan your disk structure!!Separate heavy IO areas /var/lib/mysql /var/www /tmp
    18. 18. atoptop. On CRACK.Per-process IO statsSimilar output to iostat
    19. 19. View disk activity/proc/sys/vm/block_dump echo “1” to this file dmesg buffer now contains low level disk activity information Its noisy / long
    20. 20. What did I learn?Try to avoid MySQL being disk bound Increase buffer pools Increase max temp table size Research why MySQL is slow
    21. 21. I did all that...Use tools to identify disk access Check for high swap iostat atop block_dump
    22. 22. Show me the money! AKA: I’m bored, just show me the solution
    23. 23. PHP Fixes APCOpcode cache => APCFree optimisationapc.stat = 0 (don’t check mtime)
    24. 24. PHP Fixes MemcacheGreat for distributed environmentsUse for configsFaster than MySQL query cache
    25. 25. PHP Fixes Whaaaa?I thought we were talking about MySQLLimit PHP’s access to the diskGive MySQL free reign when needed
    26. 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. 27. Disk mountingUse the “noatime” option for mountsMySQL - No big dealWeb server JACKPOT Every read results in a small write
    28. 28. noatimeBenefits Only read when we go to readWhatever the opposite of benefit is We don’t know when files were last accessed Acceptable casualties?
    29. 29. Its over!You may now emerge from your semi-comatose in-chair sleep, and ask questions.

    ×