보관함

MySQL 튜닝 (from 나프다)

먼저

  1. Subscription을 받아라
  2. 기술지원 업체에게 의지해라
  3. HW 의 중요성
    mysql community < mysql enterprize 쓰레드풀이 있고 없고 차이 (12 core 이상에서 성능 차이) -> maria DB는 쓰레드풀이 존재
  4. 스토리지 엔진이 따로 있다.
  5. my.cnf 를 잘 써라
    default로 있는 것은 낮은 시스템에서 돌리게끔 되어 있는 것이다.
  6. 성능 한계가 있다.
  7. BMT 수치는 맹신하지 마라

튜닝

아르노 Adant MySQL Connect 2013 발표
http://aadant.com/blog/wp-content/uploads/2013/09/50-Tips-for-Boosting-MySQL-Performance-CON2655.pdf

  1. Make sour you have enough RAM
  2. Use fast and multi-core processors
  3. Use fast and reliable storage
  4. Choose the right OS
    • MySQL is excellent on Linux
    • WIndows need 2012 R2
  5. Adjust the OS limits
    • Max open files per process
    • Max threads per user
  6. Consider using alternative malloc
    • [mysqld_safe]
      malloc-lib=/usr/lib64/libjemalloc.so.1
    • [mysqld_safe]
      malloc-lib=tcmalloc
  7. Set CPI affinity
    • taskset command on linux
      taskset -c 1-4 ‘pidof mysqld’
    • On Windows
      START /AFFINITY 0x1111 bin\mysqld -console
  8. Choose the right file system
    • xfs is excellent > ext4 > ext3
  9. Mount options
    • ext4 (rw,noatime, nodiration, nobarrier, data=ordered)
    • xfs (rw, noatime, nodiratime, nobarrier, logbufs=8, logbsize=32k)
    • SSD specific
      • trim
      • innodb_page_size = 4k
      • innodb_flush_neighbors = 0
  10. Choose the best I/O scheduler (Use deadline or noop on Linux)
    • deadline is generally the best I/O scheduler
      echo deadline > /sys/block/{DEVICE-NAME}/queue/scheduler
    • the best value is HW and WL specific
      noop on high end controller
  11. Use a battery backed disk cache
  12. Balance the load on several disks (SSD)
  13. Turn Off the Query Cache
    • query_cache_type = 0
    • query_cache_size = 0
    • qcache_free_blocks > 5-10k
  14. Use the Thread Pool
  15. Configure table caching
    • table_open_cache
      • not too small, not too big, used to size PS
      • opened_tables / sec
    • table_definition_cache
      • do not forget to increase
      • opened_table_definitions / sec
    • table_cache_instances = 8 or 16
    • innodb_open_files
    • mdl_hash_instances = 256
  16. Cache the threads
    • thread_cache_size
  17. Reduce per thread memory usage
    • Memory allocation is expensive = max_used_connections *(
      read_buffer_size +
      read_rnd_buffer_size +
      join_buffer_size +
      sort_buffer_size +
      binlog_cache_size +
      thread_stack +
      2 * net_buffer_length…
      )
  18. Beware of sync_binlog = 1
  19. Move your tables to InnoDB
  20. Use a large buffer pool (80% buffer pool)
    • innodb_buffer_pool_size
    • Do not swap !
  21. Reduce the buffer pool contention
    • 테이블이 많으면 많을수록 버퍼풀이 큰게 좋다
  22. Use large redo logs
    • 버전 5.6 이상에서는 2기가 이상 사용이 가능하다
  23. Adjust the IO capacity
    • 5200 RPM 에서 만들어진 기능으로 그다지…
    • 디폴트 값이 너무 낮긴 하지만 성능 향상에 그렇게까지큰 도움이 되지는 않는다.
  24. Configure the InnoDB flushing
    • 커밋할때 로그를 플러쉬 어떻게 할것인가?
    • 안정성을 중요시하면 1
    • 엔간하면 2로 놔도…
    • innodb_flush_method = O_DIRECT // 커널 복사 비용 없이 DMA를 사용 가끔 linux 커널 버전이 이상해서 파일 시스템에서 Direct IO가 켜져있지 않은 경우 골때릴수는 있다. 윈도우는 옵션이 다르다
  25. Enable innodb_file_per_table
    • 5.6부터 디폴트 이므로…
  26. Configure the thread concurrency
    • 디폴트로 놔도 됨
  27. Reduce the transaction isolation
  28. Design the tables
    • latin1 -> utf-8
    • primary key -> int
  29. Add indexes
    • innodb 는 data와 index가 같은 파일 안에 들어가서 무조건 많이 잡는게 꼭 좋아지지는 않는다.
  30. Remove unused indexes
    • 안쓰는 인덱스는 삭제하자
  31. Reduce rows_examined
    • 쿼리 쓸때 자료 확인하는 데이터 수를 줄이는 것은 당연
  32. Reduce rows_sent
    • 쿼리 쓸때 select 해서 가져오는 자료 갯수 줄이는 것도 당연
  33. Reduce locking
    • lock을 줄이는 것도 당연
    • 특히 mysql은 auto commit 이 디폴트인데 이걸 쓰지 않도록…
  34. Mine the slow query log
    • 슬로우 쿼리 잡는 것도 당연
  35. Use the performance_schema
    • 퍼포먼스 툴을 잘 사용해야 한다
    • 퍼포먼스 툴을 사용하는 시점에 10% 의 성능 하향이 일어난다.
    • 버전 8정도부터는 그렇게 성능의 하향이 일어나지는 않는다
  36. Tune the replication thread
    • 알려진 버그가 좀 있어서…
    • 만약 사용하려면 binlog_format=ROW 옵션이 필요하다
  37. Avoid temporary tables on disk
    • mysql은 join을 하거나 할때 용량이 크면 temp table을 다 disk에다 쓴다.
    • temp table을 ram에 올려야 한다.
    • temp file system을 사용하더라도 너무 크게 잡으로 swap을 사용하기 때문에
  38. Cache data in the App
  39. Avoid long running transactions
  40. Close idle connections
    • 가능하면 클라이언트에서 timeout을 사용해서 어느정도 시간이 지나면 저절로 끊어지게 해라
  41. Close prepare statements
    • prepare 하고 제발좀 close 해라
  42. Configure Connector / J
    • JDBC Connector 인데 굳이 JDBC를 사용할일은 없으니까
    • mysql connector 와 maria connector등을 같이 쓰지 말고 제발 제대로 된 프로그램을 써라
  43. Do not use the information_schema in your App
  44. View are not good for performance
  45. Sacle out, shard
  46. Monitor the database and OS
  47. Backup the database
  48. Optimize table and data files
    • 주기적으로 해야 하는 게 맞다
    • 라이브서버에서는 하지 마라
  49. Upgrade regularly
  50. Perform regular health checks

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

  

  

  

이 사이트는 스팸을 줄이는 아키스밋을 사용합니다. 댓글이 어떻게 처리되는지 알아보십시오.