mysql manchester tt - performance tuning

42
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. | MySQL Server Performance Tuning 101 Ligaya Turmelle Principal Technical Support Engineer MySQL [email protected] @lig hKps://legacy.joind.in/16770 Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | 1

Upload: mark-swarbrick

Post on 12-Jan-2017

290 views

Category:

Technology


9 download

TRANSCRIPT

1  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

MySQL  Server    Performance  Tuning  101  

Ligaya  Turmelle  Principal  Technical  Support  Engineer  -­‐  MySQL  [email protected]  @lig    hKps://legacy.joind.in/16770  

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |   1  

2  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Safe  Harbor  Statement  The  following  is  intended  to  outline  our  general  product  direcTon.  It  is  intended  for  informaTon  purposes  only,  and  may  not  be  incorporated  into  any  contract.  It  is  not  a  commitment  to  deliver  any  material,  code,  or  funcTonality,  and  should  not  be  relied  upon  in  making  purchasing  decisions.  The  development,  release,  and  Tming  of  any  features  or  funcTonality  described  for  Oracle’s  products  remains  at  the  sole  discreTon  of  Oracle.  

3  Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Laying  the  FoundaTon  

4  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Step  0  

• General  -­‐ No  easy  answers  -­‐  Benchmark  and  test  

-­‐ Under  allocate  

5  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Step  0  

• The Server - OS

- Network

- Filesystem

6  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Step  0  

• MySQL  Server  -­‐ OpTmize  the  queries  

-­‐  Database  schema  

7  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

MySQL  and  Memory  

2  

Global Per Connection

Server Start As Needed

Large Values Small Values

Allocated Once Allocated 0-N Times

Global Memory + (Max Connections * Per Connection Buffers)

8  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Current  Seangs  

•  mysql>  SHOW  GLOBAL  VARIABLES;  

•  mysql>  SELECT  *  FROM  INFORMATION_SCHEMA.GLOBAL_VARIABLES;  

•  (5.7)  mysql>  SELECT  *  FROM  PERFORMANCE_SCHEMA.GLOBAL_VARIABLES;  

mysql> SHOW GLOBAL VARIABLES;+-----------------------------------------+------------------| Variable_name | Value +-----------------------------------------+------------------| auto_increment_increment | 1| auto_increment_offset | 1 | autocommit | ON | automatic_sp_privileges | ON | back_log | 80 | basedir | /Users/ligaya/mysql_installs/mysql-5.6.16-osx10.7-x86_64 | big_tables | OFF | bind_address | * | binlog_cache_size | 32768 | binlog_checksum | CRC32 | binlog_direct_non_transactional_updates | OFF | binlog_format | STATEMENT | binlog_max_flush_queue_time | 0 | binlog_order_commits | ON | binlog_row_image | FULL | binlog_rows_query_log_events | OFF | binlog_stmt_cache_size | 32768 | bulk_insert_buffer_size | 8388608 | character_set_client | latin1 | character_set_connection | latin1 | character_set_database | latin1 | character_set_filesystem | binary | character_set_results | latin1 | character_set_server | latin1 | character_set_system | utf8 | character_sets_dir | /Users/ligaya/mysql_installs/mysql-5.6.16-osx10.7-x86_64/share/charsets/ | collation_connection | latin1_swedish_ci

8  

9  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Current  Seangs  

• my.cnf  /  my.ini  # The following options will be passed to all

MySQL clients[client]#password = your_passwordport = 5626socket

= /tmp/mysql.5.6.26.sock# The MySQL server[mysqld]##################### specific to this test instanceport = 5626socket = /tmp/mysql.5.6.26.socklog-error = /mysql-5.6.26/data/error.logbasedir = /mysql-5.6.26datadir = /mysql-5.6.26/datasafe-user-create

server-id = 1####################

9  

10  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Anything  Else?  

• RAM?  

• Dedicated?  • 32/64  bit  OS/MySQL?  

• Workload?  •  Storage  Engines?  

11  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Current  Status  

•  mysql>  SHOW  GLOBAL  STATUS;  

•  mysql>  SELECT  *  FROM  INFORMATION_SCHEMA.GLOBAL_STATUS;  

•  (5.7)  mysql>  SELECT  *  FROM  PERFORMANCE_SCHEMA.GLOBAL_STATUS;  

mysql> SHOW GLOBAL STATUS; +--------------------------------------+---------------+

| Variable_name | Value |

+--------------------------------------+---------------+ | Aborted_clients | 9363 |

| Aborted_connects | 15925 |

| Binlog_cache_disk_use | 15684 | | Binlog_cache_use | 272758675 |

| Bytes_received | 1219816389366 |

| Bytes_sent | 5227022143540 | | Com_admin_commands | 12803263 |

| Com_assign_to_keycache | 0 |

| Com_alter_db | 0 | | Com_alter_db_upgrade | 0 |

| Com_alter_event | 0 |

| Com_alter_function | 0 |

| Com_alter_procedure | 0 | | Com_alter_server | 0 |

| Com_alter_table | 37 |

| Com_alter_tablespace | 0 | | Com_analyze | 0 |

| Com_begin | 33025640 |

| Com_binlog | 0 |

11  

12  Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Time  to  Start  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Areas  We  Will  Cover  

•  General  Info  

•  InnoDB    

•  MyISAM  -­‐  Older  systems  

1  

2  

3  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Areas  We  Will  Cover  

•  Query  Cache  -­‐  Older  systems    

•  Thread  and  Table  Cache  

•  Session  Level  

5  

4  

6  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Areas  We  Will  Cover  

•  General  Info  

•  InnoDB    

•  MyISAM  -­‐  Older  systems  

1  

2  

3  

16  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Et  Al.  

• ConnecTons  and  Max_used_connecTons  

• Queries  and  QuesTons  •  Slow_queries  • Handler_read_*  

17  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

max_connecTons  

• Max  permiKed  concurrent  connecTons.  • Value  affects  memory  usage  • higher  values  (1000+)  consider/invesTgate    

-­‐  thread  pooling  -­‐  connecTon  pooling  

18  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

skip_name_resolve  

• Do  not  resolve  host  name  for  client  connecTons  • Removes  DNS  lookups    

-­‐  faster  connecTons  -­‐  no  need  to  worry  about  slow  DNS  

• Drawback:  Use  only  IP  addresses  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Areas  We  Will  Cover  

•  General  Info  

•  InnoDB    

1  

2  

1  

2  

20  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

How  is  InnoDB  doing?  

•  Efficiency  - Innodb_buffer_pool_reads_requests- Innodb_buffer_pool_reads

 

Formula: 1 - (Innodb_buffer_pool_read / Innodb_buffer_pool_read_requests)

= buffer pool hit ratio

21  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

innodb_buffer_pool_size  

• Global  • Dynamic  (5.7.5)  • Caches  data  and  indexes  •  Larger  values  reduces  IO  •  Self-­‐contained  • Max  value  -­‐  Manual:  80%  ;  Personal:  60-­‐70%    

22  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

innodb_buffer_pool_instances  

•  5.5+  • Problem:  contenTon  for  the  buffer  pool  resources  •  For  systems  with  large  mulT-­‐GB  buffer  pools  •  Total  buffer  pool  size  divided  between  this  many  instances  •  Each  instance  

-­‐ Manages  its  own  resources  -­‐  Has  its  own  mutex  

23  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

innodb_log_file_size  

•  Size  of  file  on  disk  •  Larger  the  file,  the  less  checkpoint  acTvity  •  Size  for  each  log  file  • Max  combined  log  file  size  

-­‐  4G  <  5.5  -­‐  5.6  =  512G  

•  Larger  the  log  file  ➯  longer  recovery  Tme  

24  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

innodb_log_buffer_size  

• Global  • Buffer  for  wriTng  to  log  files  on  disk  •  Large  transacTons?  Write  heavy?  

-­‐  Yes  -­‐  increasing  can  help  with  IO  • Default:  8M  

25  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

innodb_file_per_table  

•  .ibd  files  • Default:  Off  <=  5.6.5  >  On  •  Easier  to  reclaim  space  •  TRUNCATE  for  a  table  is  faster  • Can  monitor  table  size  on  the  file  system  • Can  store  specific  tables  on  different  storage  devices  •  (5.6)  Transportable  tablespaces  

-­‐  (5.7)  ParTToned  tables  supported  

26  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

innodb_flushlog_at_trx_commit  

• Performance  Vs  Durability  •  1  -­‐  Default  

-­‐  ACID  Compliant  

•  2  -­‐  Can  lose  up  to  1  second  of  transacTons  -­‐  InnoDB  log  buffer  wriKen  to  log  file  at  each  commit    -­‐  flushed  to  disk  once  per  second  

•  0  -­‐  Can  lose  up  to  1  second  of  transacTons  -­‐  InnoDB  log  buffer  wriKen  to  log  file  once  per  second  and  then  flushed  to  disk  

27  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

innodb_flush_method  

•  For  Unix  and  Linux  • Method  used  to  flush  data  and  log  files  to  disk  • Dependent  on  hardware  • Default:  fdatasync  • O_DIRECT  recommended  if  you  use  a  hardware  RAID  controller  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Areas  We  Will  Cover  

 

•  Threads  and  Table  Cache  

•  Session  Level  

5  

6  

29  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Gotchas!  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Areas  We  Will  Cover  

•  Query  Cache  -­‐  Older  systems    

•  Threads  and  Table  Caches  

•  Session  Level  

5  

4  

6  

31  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Threads  

•  Threads  ==  ConnecTon  •  Thread  Cache  

-­‐  Threads_cached  -­‐  Threads_connected  -­‐  Threads_created  

Formula: Threads_created / Connections = Thread cache miss rate

32  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

thread_cache_size  

• Global  but  grows  as  needed  • Number  to  be  cached  unTl  needed  • May  increase  performance  with  lots  of  new  connecTons  

-­‐ Or  may  not  

Formula: 100 - ((Threads_created / Connections) * 100) =

Thread cache efficiency

33  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

table_open_cache  

•  table_cache  <=  5.1.3  >  table_open_cache  • Global  but  expands  as  needed  • Number  of  open  tables  for  all  connecTons  

-­‐  higher  max_connecTons,  more  you  need  

• Watch  Opened_tables  

34  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

table_open_cache_instances  

• Reduces  contenTon  between  sessions  • Default  1  

-­‐  Consider  8  or  16  on  16+  core  systems  

•  5.6+  

35  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

table_definiTon_cache  

• Global  but  expands  as  needed  • Number  of  table  definiTons  (.frm  file)  to  hold  •  Large  number  of  tables  ➯large  definiTon  cache  =  speed  up  table  opening  •  InnoDB  

-­‐  Sow  limit  for  open  table  instances  in  data  dicTonary  -­‐  Sow  limit  for  number  of  InnoDB  file  per  table  tablespaces  open  at  1  Tme  

•  5.1+  • Autosizes  >=5.6.8  

Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Areas  We  Will  Cover  

•  Query  Cache  -­‐  Older  systems    

•  Threads  and  Table  Cache  

•  Session  Level  

5  

4  

6  

37  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

Temporary  Tables  

max_heap_table_size

• Dynamic• Set maximum size of all

MEMORY tables

tmp_table_size

• Dynamic• In-memory - MEMORY table• max size of internal in-

memory temp tables• Becomes on-disk table

38  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

sort_buffer_size  

• Dynamic  • Doing  a  sort  -­‐  allocates  a  buffer  this  size  • Helps  with  ORDER  BY  and/or  GROUP  BY  •  256K  is  a  decent  starTng  place  • Watch  Sort_merge_passes  

39  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

join_buffer_size  

• Use  with  care  • Use  for  

-­‐  Plain  index  scan  -­‐  Range  index  scan  -­‐  Joins  that  do  not  use  indexes  -­‐  full  table  scan  

• One  buffer  for  each  full  join  between  tables  

40  Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

QuesTons?  

41  Copyright  ©  2015,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |  

MySQL  Server    Performance  Tuning  101  

Ligaya  Turmelle  Principal  Technical  Support  Engineer  -­‐  MySQL  [email protected]  @lig      hKps://legacy.joind.in/16770  

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |   41  

Copyright  ©  2014,  Oracle  and/or  its  affiliates.  All  rights  reserved.    |