• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
MySQL Performance - SydPHP October 2011
 

MySQL Performance - SydPHP October 2011

on

  • 1,133 views

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 ...

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

Statistics

Views

Total Views
1,133
Views on SlideShare
1,039
Embed Views
94

Actions

Likes
1
Downloads
9
Comments
0

4 Embeds 94

http://joefrancisninal.xtreemhost.com 55
http://joefrancisninal.info 30
http://coderwall.com 8
http://localhost 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \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 MySQL Performance - SydPHP October 2011 Presentation Transcript

  • MySQL Performance It ain’t just indexing!
  • OverviewYou’ve done indexingYou’ve optimised queriesYou need more oomphYou’ll need to dig around a bit moreMySQL config and server admin
  • 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”)
  • 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)
  • In-MySQL SolutionsClever indexingQuery and Dataset reorganisationDenormalise / Summarised dataUse “SELECT *” sparinglySubqueries can be fasterBenchmark differences
  • In-MySQL SolutionsIn-Memory temporary tablesStored procedures are super fast
  • 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)
  • 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?
  • Is my MySQL app Memory Bound?Most definitelyDefault my.cnf is probably okay
  • 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
  • Basic OS TheoryIf the operation doesn’t fit inmemoryThe operation swaps to diskPHP and DB on the same diskNot a good idea for performance
  • my.cnfQuick guides on my.cnf http://bit.ly/VKmcQ http://bit.ly/3pqQc
  • my.cnfHeap sizes max_heap_size >= max_temp_table_size Tweak... SHOW GLOBAL STATUS LIKE ‘Created_%’ Compare before and after values for temporary tables
  • Processor CrackEvery process is competing for IO“top” is a great tool for checkingShows %age of run queue that is IO
  • Are we swapping?Swapping is bad...mkay?Swapping != lotsof disk IOIts compsumptionof Memory
  • iostatShows IO activity Bytes read, writtenEasy to see IO
  • iostatOnly works on a per-partition basisPlan your disk structure!!Separate heavy IO areas /var/lib/mysql /var/www /tmp
  • atoptop. On CRACK.Per-process IO statsSimilar output to iostat
  • 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
  • What did I learn?Try to avoid MySQL being disk bound Increase buffer pools Increase max temp table size Research why MySQL is slow
  • I did all that...Use tools to identify disk access Check for high swap iostat atop block_dump
  • Show me the money! AKA: I’m bored, just show me the solution
  • PHP Fixes APCOpcode cache => APCFree optimisationapc.stat = 0 (don’t check mtime)
  • PHP Fixes MemcacheGreat for distributed environmentsUse for configsFaster than MySQL query cache
  • PHP Fixes Whaaaa?I thought we were talking about MySQLLimit PHP’s access to the diskGive MySQL free reign when needed
  • 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
  • Disk mountingUse the “noatime” option for mountsMySQL - No big dealWeb server JACKPOT Every read results in a small write
  • noatimeBenefits Only read when we go to readWhatever the opposite of benefit is We don’t know when files were last accessed Acceptable casualties?
  • Its over!You may now emerge from your semi-comatose in-chair sleep, and ask questions.