This article related to: the use and performance tuning of MySQL comes with several performance testing tool mysqlslap method
Performance testing tools -mysqlslap
mysqlslap is MySQL comes with a very good performance testing tool. It can be used
to simulate multiple concurrent client issues a query to the server, update request, and then outputs the simple report
Optional parameters
- -engines: representative of the engine to be tested, there can be multiple, separated by a delimiter
- -iterations: To run these tests on behalf of how many times
- -auto-generate-sql: represented by a system of self-generated SQL scripts to test
- -auto-generate-sql-load-type: representatives to be tested is a read or write, or a combination of both (read, write, update, mixed)
- -number-of-queries: represents the total number of queries to be run. The number of queries each customer can run with the total number of queries / concurrent calculated
- Related information represents -debug-info to extra output from the CPU and memory
- The number of type int field to create a test table: -number-int-cols
- -auto-generate-sql-add-autoincrement: Representative columns are automatically added to the table generated auto_increment
- The number of type char field -number-char-cols to create a test table
- -create-schema database testing
- -query use custom scripts to perform tests, such as a stored procedure can be called from sql statement or defined to perform the test
- -only-print if you want only to see what SQL statements, you can use this option
The following is a simple example of use:
1 2 3 4 5 |
[root@syj ~]# mysqlslap -uroot -proot --concurrency=500 --iterations=1 --create-schema='test' --query='select * from u_trade_pay_order limit1000;' --number-of-queries=10 |
Factors affecting the performance of MySQL
The number of connections is not enough
When the number of connections using more than 85% there is a connection number has almost not enough
Check connections related method
1 2 |
show global status like 'Max_used_connections'; show variables like 'max_connections%'; |
Reason enough connections
- Number of connections set too low or too high
- IO slow query causes blockage, resulting in a long time not to release the connection
- SQL executed, the connection is not released
Modify the number of connections MySQL
1 |
set global max_connections = 1024; |
Slow query
In principle should be single than 100ms execution time of SQL optimization need to consider things
Slow SQL View
1 |
show global status like 'Slow_queries’; |
The reason appears slow queries
- No index or index unreasonable
- Data Query is too large
- Latched
Cache hit rate
If the query cache hit ratio <95% indicates that the cache size may be set too low or there is a lot of debris cache
Cache hit rate calculation method
1 |
(Qcache_hits – Qcache_inserts) / Qcache_hits * 100% |
Enabling query caching
1 |
set session query_cache_type=on; |
Improve the cache utilization
- Using the same SQL, such as use in MyBatist # instead of $
- The client and server use the same character set
- Increasing the size of the buffer
- insert and update causes cache invalidation
Recommended Reading
- SpringCloud Learning Series summary
- Why interview tier companies will ask redis, so what better to ask?
- Multithreading interview necessary foundation knowledge summary
- Collection of Java source code analysis summary -JDK1.8
- Linux Quick commonly used commands - Summary articles
- JVM series summary