20-30 concurrent mysql connections causes RDS to spike above 80%

给你一囗甜甜゛ 提交于 2021-02-20 00:20:34

问题


So We have an Amazon RDS server running with the following specs.

Instance Class: r3.xlarge

My issue is when the MySQL server experiences multiple concurrent connections (connections in range of 30-40), The CPU reaches its peak.

However according to the monitoring stats, it should be able to handle connections well above that. Here is the output for mysqltuner

>>  MySQLTuner 1.7.1 - Major Hayden <major@mhtx.net>
>>  Bug reports, feature requests, and downloads at http://mysqltuner.com/
>>  Run with '--help' for additional options and output filtering
[--] Skipped version check for MySQLTuner script
[OK] Logged in using credentials passed on the command line
[--] Assuming 31500 MB of physical memory
[!!] Assuming 0 MB of swap space (use --forceswap to specify)
[OK] Currently running supported MySQL version 5.7.16-log

-------- Log file Recommendations ------------------------------------------------------------------
[--] Log file: /rdsdbdata/log/error/mysql-error.log(0B)
[!!] Log file /rdsdbdata/log/error/mysql-error.log doesn't exist
[!!] Log file /rdsdbdata/log/error/mysql-error.log isn't readable.

-------- Storage Engine Statistics -----------------------------------------------------------------
[--] Status: +ARCHIVE +BLACKHOLE +CSV -FEDERATED +InnoDB +MEMORY +MRG_MYISAM +MyISAM +PERFORMANCE_SCHEMA 
[--] Data in InnoDB tables: 31G (Tables: 318)
[OK] Total fragmented tables: 0

-------- CVE Security Recommendations --------------------------------------------------------------
[--] Skipped due to --cvefile option undefined

-------- Performance Metrics -----------------------------------------------------------------------
[--] Up for: 35d 16h 32m 26s (396M q [128.632 qps], 22M conn, TX: 605G, RX: 157G)
[--] Reads / Writes: 77% / 23%
[--] Binary logging is enabled (GTID MODE: OFF)
[--] Physical Memory     : 30.8G
[--] Max MySQL memory    : 30.6G
[--] Other process memory: 3.1G
[--] Total buffers: 22.6G global + 3.2M per thread (2540 max threads)
[--] P_S Max memory usage: 0B
[--] Galera GCache Max memory usage: 0B
[OK] Maximum reached memory usage: 23.0G (74.65% of installed RAM)
[!!] Maximum possible memory usage: 30.6G (99.63% of installed RAM)
[!!] Overall possible memory usage with other process exceeded memory
[OK] Slow queries: 0% (0/396M)
[OK] Highest usage of available connections: 4% (119/2540)
[OK] Aborted connections: 0.07%  (15572/22176276)
[!!] Query cache may be disabled by default due to mutex contention.
[!!] Query cache efficiency: 0.0% (0 cached / 160M selects)
[OK] Query cache prunes per day: 0
[OK] Sorts requiring temporary tables: 0% (42K temp sorts / 7M sorts)
[!!] Joins performed without indexes: 67554
[!!] Temporary tables created on disk: 30% (4M on disk / 13M total)
[OK] Thread cache hit rate: 99% (23K created / 22M connections)
[!!] Table cache hit rate: 0% (2K open / 532K opened)
[OK] Open file limit used: 0% (33/65K)
[OK] Table locks acquired immediately: 100% (155K immediate / 155K locks)
[OK] Binlog cache memory access: 99.97% (39502400 Memory / 39516081 Total)

-------- Performance schema ------------------------------------------------------------------------
[--] Performance schema is disabled.
[--] Memory used by P_S: 0B
[--] Sys schema is installed.

-------- ThreadPool Metrics ------------------------------------------------------------------------
[--] ThreadPool stat is disabled.

-------- MyISAM Metrics ----------------------------------------------------------------------------
[!!] Key buffer used: 18.3% (3M used / 16M cache)
[OK] Key buffer size / total MyISAM indexes: 16.0M/51.0K
[!!] Read Key buffer hit rate: 83.5% (36K cached / 5K reads)

-------- InnoDB Metrics ----------------------------------------------------------------------------
[--] InnoDB is enabled.
[--] InnoDB Thread Concurrency: 0
[OK] InnoDB File per table is activated
[!!] InnoDB buffer pool / data size: 22.5G/31.4G
[OK] InnoDB log file size / InnoDB Buffer pool size: 2.5G * 2/22.5G should be equal 25%
[!!] InnoDB buffer pool instances: 20
[--] Number of InnoDB Buffer Pool Chunk : 180 for 20 Buffer Pool Instance(s)
[OK] Innodb_buffer_pool_size aligned with Innodb_buffer_pool_chunk_size & Innodb_buffer_pool_instances
[OK] InnoDB Read buffer efficiency: 100.00% (1166286556754 hits/ 1166290082453 total)
[!!] InnoDB Write Log efficiency: 89.64% (179749039 hits/ 200515885 total)
[OK] InnoDB log waits: 0.00% (0 waits / 20766846 writes)

-------- AriaDB Metrics ----------------------------------------------------------------------------
[--] AriaDB is disabled.

-------- TokuDB Metrics ----------------------------------------------------------------------------
[--] TokuDB is disabled.

-------- XtraDB Metrics ----------------------------------------------------------------------------
[--] XtraDB is disabled.

-------- RocksDB Metrics ---------------------------------------------------------------------------
[--] RocksDB is disabled.

-------- Spider Metrics ----------------------------------------------------------------------------
[--] Spider is disabled.

-------- Connect Metrics ---------------------------------------------------------------------------
[--] Connect is disabled.

-------- Galera Metrics ----------------------------------------------------------------------------
[--] Galera is disabled.

-------- Replication Metrics -----------------------------------------------------------------------
[--] Galera Synchronous replication: NO
[--] No replication slave(s) for this server.
[--] This is a standalone server.

-------- Recommendations ---------------------------------------------------------------------------
General recommendations:
Reduce your overall MySQL memory footprint for system stability
Dedicate this server to your database for highest performance.
Adjust your join queries to always utilize indexes
When making adjustments, make tmp_table_size/max_heap_table_size equal
Reduce your SELECT DISTINCT queries which have no LIMIT clause
Increase table_open_cache gradually to avoid file descriptor limits
Beware that open_files_limit (65535) variable 
should be greater than table_open_cache (2000)
Performance should be activated for better diagnostics
Variables to adjust:
*** MySQL's maximum memory usage is dangerously high ***
*** Add RAM before increasing MySQL buffer variables ***
query_cache_size (=0)
query_cache_type (=0)
query_cache_limit (> 1M, or use smaller result sets)
join_buffer_size (> 2.0M, or always use indexes with joins)
tmp_table_size (> 64M)
max_heap_table_size (> 64M)
table_open_cache (> 2000)
performance_schema = ON enable PFS
innodb_buffer_pool_size (>= 31G) if possible.
innodb_buffer_pool_instances(=22)

Can someone help on how can we improve the max_number_of_connections in our current scenario?


回答1:


Based on provided mysqltuner information, suggestions to consider for your .cnf (or .ini) in [mysqld] section. Do NOT change more than 1 item per day. Keep a copy of last 3 .cnf just in case. Invest in more RAM, if possible. max_connections=200 # from 2540 08/18/2017, only 119 used in 35 days have_query_cache= NO # from YES mm/dd/ccyy, to avoid QC overhead query_cache_size=0 # is 0 mm/dd/ccyy, to ensure QC not available thread_cache_size=100 # 5.7 calc is 8 + (max_connections / 100 ) cap at 100 - to support your 22M connections in 35 days key_buffer_size=8M # from 16M mm/dd/ccyy only ~20% used in 35 days

innodb_thread_concurrency=25  # from 0 mm/dd/ccyy to manage activity
innodb_buffer_pool_size=20G  # from 22.5G mm/dd/ccyy to reduce memory footprint
innodb_buffer_pool_instances=8  # from 20 mm/dd/ccyy should be fine
table_open_cache=10000  # from 2000 mm/dd/ccyy for your 532K opened in 35 days

For a more thorough analysis, after 7 days of UPTIME please provide SHOW GLOBAL STATUS; SHOW GLOBAL VARIABLES; SHOW ENGINE INNODB STATUS;

The 3.2M per thread reported by tuner should be analyzed with the assistance of mysqlcalculator.com to compare defaults to your values as reported by SHOW GLOBAL VARIABLES; some items appear to be excessive.



来源:https://stackoverflow.com/questions/43844706/20-30-concurrent-mysql-connections-causes-rds-to-spike-above-80

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!