MySQL Performance Tuning (VII): Other optimization

Original: MySQL Performance Tuning (VII): Other optimization

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/vbirdbest/article/details/81084853

A: Database configuration optimization

mysql is a highly customized database system that provides a lot of configuration parameters, are generally required depending on the characteristics and circumstances of the application of hardware to do mysql configuration optimization, windows configuration file my.ini, linux is my.cnf

Optimization common variables are:

# 端口
port=3306

# 关闭查询缓存
query_cache_type=0
query_cache_size=0


# 内存是影响数据库性能的重要资源,也是mysql性能优化的一个重要方面,
innodb_additional_mem_pool_size=64M
innodb_buffer_pool_size=1G
innodb_log_buffer_size=1MB

# 并发连接数 
max_connections=1000




binlog_cache_size=4M
key_buffer_size=16MB
bulk_insert_buffer_size=8MB
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • query_cache_type: If you use all innodb storage engine, it is recommended to 0, if you use MyISAM storage engine, it is recommended to 2, while in SQL statements to explicitly control whether yo you gquery cache

  • query_cache_size: (* 100 Qcache_hits / (Qcache_hits + Qcache_inserts))) according to the hit rate adjustment is generally not recommended too, 256MB may have almost the same, large-type static configuration data may be appropriate to transfer large

  • binlog_cache_size: 2MB ~ 4MB general environment is a suitable choice matters large and heavy write-large database environment can be appropriately adjusted, but does not recommend more than 32MB

  • key_buffer_size: key_buffer_size parameter used to set the size of the cache memory area for storage engine MyISAM index file. All MyISAM engine to index all of us at the table if we have enough memory, the cache area is best able to store, in order to maximize performance. In addition, when we have the time to use the MyISAM storage and an important point to note, due to the characteristics of the MyISAM engine of his only limit will only cache index blocks into memory without cache database blocks. Therefore, we must let the SQL filter conditions are possible in the index, so that the cache help us improve query efficiency. If no MyISAM storage engine, 16MB sufficient for some systems the cache information table. If you use MyISAM storage engine, in the case of memory allows, as far as possible all indexes into memory, in short, it is the "bigger is better"

  • bulk_insert_buffer_size: If frequent use a special statement bulk inserts (above described) to insert the data, the parameters may be suitably adjusted to a large 16MB ~ 32MB, it is not recommended to continue to increase, a person 8MB

  • innodb_buffer_pool_size: to set the size of the cache memory area for the index and data blocks InnoDB, MyISAM similar key_buffer_size parameter storage engine. If you do not use InnoDB storage engine, you can not adjust this parameter, if you need to use, in the case of memory allows, as far as possible all the InnoDB data files, such as memory, but the same is also the "bigger is better"
    innodb_additional_mem_pool_size: recommended to adjust the general database to 8MB ~ 16MB, particularly if the table can be adjusted to 32MB, may need to be increased is determined based on the information in the error log

  • innodb_log_buffer_size: transaction log buffer InnoDB storage engine being used. The default is 1MB, such as frequent-based system may be appropriately increased to 4MB ~ 8MB. Of course, as mentioned above, described, and this actually further parameter related parameters flush. Generally not recommended to exceed 32MB

  • innodb_max_dirty_pages_pct: Based on past experience, if you want to restart the recovery of more than 1GB of data, it can be slow start, almost difficult to accept, it is recommended that not more than 1GB / innodb_buffer_pool_size (GB) * 100 value. Of course, if you can tolerate relatively long start-up time, and want to minimize flush memory to disk, you can adjust this value to 90, but not more than 90 recommendations

After opening the query cache will return results in the cache under the same circumstances, and data query directly. Here's query including query some information may affect the outcome of itself, the current database to query, client protocol version number. So any queries on any two different characters will cause the cache miss. In addition, if the query contains any user-defined functions, stored functions, user variables, temporary tables, Mysql database system tables, which query will not be cached. After the establishment of the cache, Mysql query cache system tracks each table involved in the query, if the tables (or data structure) changes, then all cache data and related this table will fail.

Although the cache can improve database query performance, but also brought a cache overhead after each query to do a cache operation, but also destroyed after failure. Therefore, open the cache query to be careful, especially for write-intensive applications even more so. If enabled, pay attention to the reasonable control of the buffer space, in general, its size is set to MB dozens more appropriate. It can also be controlled by sql_cache and sql_no_cache a query whether the cache: SELECT SQL_NO_CACHE * FROM tbl_user WHERE email = '[email protected]';

II: separate read and write

If the pressure is large database, a server can not support, it can be used mysql master synchronization of multiple servers, the database is dispersed pressure to multiple servers from a database replication. Pruning will increase to master the implementation of the query to the slaver query.

A primary server assumes the updating operation, assume the query multiple servers, synchronization is achieved by copying the data between master and slave. Multiple servers on the one hand to ensure the availability, on the other hand can create different indexes to meet different query

III: Application Optimization

As the performance limitations of the database server itself, it must be some optimization of the foreground application, reducing the pressure on the database.

  • Use the database connection pool
  • Reduce access to the mysql
    • All results can be able to extract a connection, do not connect the two, such as batch inserts, batch updates
    • Performance is very low, especially in comparison multi-table joins when multi-table joins, can be divided into multiple sql query and then use the application data assembled into the desired format, which is to solve a multi-table join query performance of low very important tool.
    • Database cache, the cache is enabled by default for example mybatis
    • Increase the buffer layer, such as redis, memcache, elasticsearch

Four: mysql server hardware upgrade

Five: the timing to clear unwanted data, regular defragmentation (MYISAM)

Six: MySQL server resides on the linux parameter optimization

/etc/sysctl.conf
/etc/security/limit.conf
/etc/fstab

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/11865888.html