Successfully reported this slideshow.
Your SlideShare is downloading. ×

Mysql talk


More Related Content


Related Books

Free with a 30 day trial from Scribd

See all

Mysql talk

  1. 1. Linux and Mysql Tuning Getting the most from your hardware
  2. 2. The Ubiquitous “About Me” <ul><li>Ran datacenters for: </li></ul><ul><ul><li>National Geographic </li></ul></ul><ul><ul><li>ExpertCity (now Citrix Online) </li></ul></ul><ul><ul><li>Fastclick (now Valueclick) </li></ul></ul><ul><ul><li>University of California (now broke); </li></ul></ul><ul><li>Now CEO/founder of </li></ul><ul><li>Probably just like you. (Not a kernel committer, or poring over MySQL source code). </li></ul>
  3. 3. Your Mileage May Vary <ul><li>Nothing I am going to say will have any impact in your environment. </li></ul><ul><li>Unless it does. </li></ul><ul><li>So...test, measure, rinse, repeat. </li></ul>
  4. 4. What to measure? <ul><li>Everything! </li></ul><ul><li>Database (innodb, MyISAM, replication), OS, disk, application – all in as much detail as possible. </li></ul>
  5. 5. Measure YOUR application <ul><li>Get monitoring that can query db directly, and slice/dice (registrations/sec; customer updates received, etc). </li></ul><ul><li>Also instrument front ends (via JMX, WMI, web status, etc) so you can measure effect on app of db adjustments </li></ul>
  6. 6. Talk outline <ul><li>Kernel IO scheduler tuning </li></ul><ul><li>InnoDB thread tuning </li></ul><ul><li>Stopping swapping </li></ul><ul><ul><li>Swappiness </li></ul></ul><ul><ul><li>NUMA factors </li></ul></ul><ul><ul><li>Huge pages </li></ul></ul>
  7. 7. Why? <ul><li>Limits are always one of CPU, RAM, Disk, Network. </li></ul><ul><li>But with better <CPU|RAM|Disk|network> the limit will move to next object </li></ul><ul><li>Default configurations may be for: </li></ul><ul><li>Your server: </li></ul>
  8. 8. IO Scheduler Tuning <ul><li>Kernel decides how to order disk operations, in order to combine IO ops into one op, and also minimize disk seeks, or not. </li></ul><ul><li>Defaults work. No benefit in other policies, only harm. Don't bother testing. </li></ul><ul><li>But, it's trivial to test, so don't take my word for it. With battery backed RAID cache, others have reported good results with noop. </li></ul><ul><li>Kernel, hardware dependent. Test! echo noop > /sys/block/sda/queue/scheduler </li></ul>
  9. 9. VM on ESX with no-cache RAID1 <ul><li>Switching from CFQ to Noop </li></ul><ul><li>Amount of non-merged writes overwhelmed disk. </li></ul>Switch to NoOP Switch to NoOP
  10. 10. VM on ESX no-cache RAID1 <ul><li>Switch from anticipatory to CFQ at 13:10 </li></ul><ul><li>CFQ has slightly more reads merged, slightly better performance time. </li></ul>Switch to CFQ
  11. 11. Lots of IO where ordering doesn't matter <ul><li>4000 disk operations to SSD </li></ul><ul><li>Switching from CFQ to NoOP – slightly worse IO completion time. </li></ul>Switch to NoOP Switch to NoOP
  12. 12. But it saves CPU, right? <ul><li>Not significantly, if at all. </li></ul>Policy switched
  13. 13. Innodb Thread Concurrency <ul><li>If database is slow, but CPU not busy...this may be issue. </li></ul><ul><li>Defaults range from 4 (in some distro's) to infinite, depending on version. 8 seems most common default in real world. </li></ul><ul><li>“ Infinite” changes between versions. </li></ul><ul><li>Default probably too low for “real” DB server. </li></ul>
  14. 14. Test! Benchmark first, then real life <ul><li>Use a threaded benchmark. </li></ul><ul><li>sysbench --test=oltp --mysql-table-engine=innodb --mysql-socket=/var/lib/mysql/mysql.sock --max-time=300 --db-driver=mysql --num-threads=10 --max-requests=300000 run </li></ul><ul><li>Use same benchmark, vary server config. </li></ul>
  15. 15. Results will vary with # users <ul><li>How many user threads to test? Use real data. </li></ul>
  16. 16. My results, not yours <ul><li>This is true on some hardware, with some version of MySQL, with 10 client threads. </li></ul><ul><li>Your mileage WILL vary. Test. </li></ul><ul><li>Higher settings not always better. </li></ul>
  17. 17. More InnoDB threads – more efficient use of CPU 8 Innodb threads 4 Innodb Threads 16 Innodb Threads ∞ Innodb Threads
  18. 18. Swapping <ul><li>Use of swap not bad – swapping is bad. </li></ul><ul><li>OK (but not ideal): </li></ul><ul><li>Performance Killer: </li></ul>
  19. 19. Disable swap? <ul><li>Erm … probably not. </li></ul><ul><li>“ Because new pages are always being read in and processes are always allocating new memory, the OS will have to make a decision of what pages to evict from physical memory. If a page is dirty, it can only be evicted if there's swap. So if you have dirty pages that are very rarely used, swap allows you to keep more hot, clean pages in memory.” </li></ul><ul><li> </li></ul>
  20. 20. Easy things first <ul><li>echo 0 > /proc/sys/vm/swappiness </li></ul><ul><li>echo “vm.swappiness = 0” >> /etc/sysctl.conf; sysctl -p </li></ul><ul><li>This may be enough. If so, KISS. </li></ul>
  21. 21. NUMA factors <ul><li>System tries to allocate memory local to the CPU a process runs on. </li></ul><ul><li>In dual processor system, if one process tries to grab > 50% of system's memory, it will use all free memory local to one processor. </li></ul><ul><li>other process on that CPU requesting memory may cause swap activity to get local memory – even though there is free non-local memory. </li></ul><ul><li> </li></ul>
  22. 22. Numa, II <ul><li>I couldn't reproduce: </li></ul><ul><ul><li>Run mysql with affinity to a physical CPU, with buffer pool that consumes all local memory. </li></ul></ul><ul><ul><li>Start Java process with affinity to same CPU. Mem was allocated from other core. But.. no swap used. </li></ul></ul><ul><li>But just in case...easy to address: </li></ul><ul><li>numactl --interleave all mysqld If you are allocating more than 50% memory to innodb (or any other single process), you are guaranteed non-local memory access. So may as well be deterministic, and possibly benefit from this swap-fix. </li></ul>
  23. 23. HugePages <ul><li>Currently huge pages are not swapped (may change) </li></ul><ul><li>Will have some (probably very minor) performance benefit (big in some cases) </li></ul><ul><li>But.. more complex (and thus risky.) </li></ul><ul><li>Need to enable in kernel, configure kernel,ulimits, security groups, configure mysql. See </li></ul>
  24. 24. HugePages <ul><li>Set nr_hugepages too low – Mysql wont use, and you just wasted memory. Ditto too high. </li></ul><ul><li>Pins Innodb buffer pool cache – but will increase pressure on other memory if swapping is triggered </li></ul><ul><li>Will reduce TLB cache lookups/misses. Does that matter? Test! </li></ul>
  25. 25. Summary <ul><li>My app/kernel/hardware/DB version is not yours. YMMV. </li></ul><ul><li>Test IO scheduler, as its so easy. </li></ul><ul><li>Test InnoDB thread concurrency. </li></ul><ul><li>Address swapping in the simplest way you can. </li></ul><ul><li>Trend everything. All the time. Compare pre- and post releases. </li></ul>
  26. 26. That's it! <ul><li>Questions? </li></ul><ul><li>[email_address] </li></ul><ul><li> </li></ul><ul><li> </li></ul>