Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Mysql performance tuning

2,717 views

Published on

Mysql performance tuning

Published in: Technology, Education
  • Be the first to comment

Mysql performance tuning

  1. 1. MYSQL Performance TuningPhilip Zhong© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 1
  2. 2. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 2
  3. 3. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 3
  4. 4. • Types of I/O schedulers (introduced in 2.6.10: RHEL5) – noop: Sorting incoming i/o requests by logical block address, that’s all – deadlilne: Prioritize read (sync) requests rather than write requests (async) to some extent (to avoid “write-starving-reads” problem) – cfq(default): Fairly scheduling i/o requests per i/o thread – anticipatory: Removed in 2.6.33 (bad scheduler. Don’t use it)• Default is cfq, but noop / deadline is better in many cases # echo noop > /sys/block/sdX/queue/scheduler© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 4
  5. 5. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 5
  6. 6. • Make sure to use Flash Back Write Cache(FBWC) or Battery Backed up Write Cache (BBWC) on raid cards – 10,000+ fsync() per second, without BBWC less than 200 on HDD – Disable write cache on disks for safety reasons• Do not set “write barrier” on file systems (enabled by default in some cases) – Write-through to disks even though BBWC is enabled (very slow) – ext3: mount -o barrier=0 – xfs: mount -o nobarrier – drbd: no-disk-barrier in drbd.conf• Consider disabling atime updates on files and directories – mount -o noatime,nodiratime© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 6
  7. 7. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 7
  8. 8. • Put sequentially written files on HDD – ibdata, ib_logfile, binary log files – HDD is fast enough for sequential writes – Write performance deterioration can be mitigated – Life expectancy of SSD will be longer• Put randomly accessed files on SSD – *ibd files, index files(MYI), data files(MYD) – SSD is 10x -100x faster for random reads than HDD – Archive less active tables/records to HDD – SSD is still much expensive than HDD• Use 5.1 InnoDB Plugin – Higher scalability & concurrency matters on faster storage© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 8
  9. 9. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 9
  10. 10. • RAM access speed is much faster than HDD/SSD RAM: -60ns HDD: -5ms SSD: 100-500us• 16-100+GB RAM is now pretty common• Sharding hot application data is important• Do not create unnecessary indexes• Delete records or move to archived tables, to keep hot tables smaller© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 10
  11. 11. • Network• CPU• ……© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 11
  12. 12. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 12
  13. 13. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 13
  14. 14. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 14
  15. 15. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 15
  16. 16. • EXPLAIN SELECT – Tells you what MYSQL is thinking – Which keys (indexes) can it use – Which keys will it use – How many rows must it examine (roughly)© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 16
  17. 17. • EXPLAIN doesn’t tell you anything about how triggers, stored functions, or UDFs will affect your query.• It doesn’t work for stored procedures, although you can extract the queries manually and EXPLAIN them individually.• Some of the statistics it shows are estimates and can be very inaccurate.• It doesn’t show you everything there is to know about a query’s execution plan.• It doesn’t distinguish between some things with the same name. For example, it uses “file sort” for in-memory sorts and for temporary files, and it displays “Using temporary” for temporary tables on disk and in memory. It can be misleading© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 17
  18. 18. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 18
  19. 19. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 19
  20. 20. SIMPLE:Simple SELECT (not using UNION or subqueries) PRIMARY: outer select. UNION:Second or later SELECT statement in a UNION DEPENDENT UNION:Second or later SELECT statement in a UNION, dependent on outer query UNION RESULT:Result of a UNION. SUBQUERY:First SELECT in subquery DEPENDENT SUBQUERY: First SELECT in subquery, dependent on outer query DERIVED:Derived table SELECT (subquery in FROM clause) UNCACHEABLE SUBQUERY:A subquery for which the result cannot be cached and must be reevaluated for each row of the outer query UNCACHEABLE UNION:The second or later select in a UNION that belongs to an uncacheable subquery (see UNCACHEABLE SUBQUERY)© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 20
  21. 21. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 21
  22. 22. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 22
  23. 23. • Mysql>SET profiling = 1;• Mysql>SHOW PROFILES;• Mysql>SHOW PROFILE CPU FOR QUERY 1;© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 23
  24. 24. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 24
  25. 25. select tag_id,tag_text from Tags where tag_id+1>1 and tag_id+1<11;© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 25
  26. 26. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 26
  27. 27. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 27
  28. 28. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 28
  29. 29. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 29
  30. 30. © 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 30
  31. 31. Thank you.© 2011 Cisco and/or its affiliates. All rights reserved. Cisco Confidential 31

×