当前位置:网站首页>Database optimization
Database optimization
2022-06-27 20:02:00 【Invincible Dragon Warrior】
List of articles
1、SQL And index optimization
( Large amount of data , perform SQL Low efficiency , To optimize )
Open slow query log -》 Set a reasonable slow query time for the corresponding amount of item table data –》 Find record slow query SQL–》 use explain analysis SQL Implementation plan of –》 The corresponding optimization measures are given –》 If the amount of data is too large , Paging with . No index . The first column is not used in multi column indexing . Size table settings for federated queries . Multi table query does not need in, Replace the belt with an external connection in The process of subquery , Use index reasonably , No intermediate table will be generated .
2、 Application optimization
- 1、 Connect to database , Connection pool can be imported ( middleware )
- 2、 Introduce caching ( Store hot data ,redis, If the client's request comes , First in redis Check it out , If redis If you find it directly on the database, you don't go through the database , If you don't find it, visit MySQL database , Visit back , First, send the accessed data to redis Let's cache it , And then return the results to the user .redis It's a memory based database )
Increase in business redis、memcache, Cache is generally used to cache frequently accessed data .
introduce redis Cache words , It is necessary to prevent these problems : Cache data consistency problem . Cache penetration and cache avalanche .
Besides optimization SQL And index , A lot of times , In the actual production environment , Due to the performance limitations of the database server itself , We must optimize the application of the upper layer , So that the pressure of the upper application accessing the database can be minimized .
Connection pool
Generally, the application accesses the database , All first MySQL Server Create connection , And then send SQL sentence ,Server After processing , Then return the result to the application through the network , Then close and MySQL Server The connection of , Therefore, a large number of database accesses in a short time , The consumption of TCP Three handshakes and four waves take a lot of time , A slightly larger project , We will all be on the layer where the application accesses the database , Add connection pool module , Equivalent to application and MySQL Server Create a set of connections in advance , When the application needs to request MySQL Server when , There's no need to go on TCP Connect and release the connection , Generally, the connection pool will maintain the following resources :
1、 A fixed number of connections remain active in the pool TCP Connect , Supply and use .
2、 If the application has instant access MySQL The amount of is relatively large , Then the connection pool will create more connections for applications in real time .
3、 When in the connection pool TCP The connection has not been used for some time , The connection pool will free up redundant connection resources , Just keep the maximum number of free connections it sets .
The connection pool can be implemented by itself , You can also use a library written by a third party .
MySQL The query cache
MySQL The query cache is to put select Record the last query result of the query statement and put it in the cache , The next time you query the same content , Just take it out of the cache , You don't have to do it again SQL Inquire about . ( Divide a space in memory for cache )
But when two select Appear in the middle of query insert,update,delete At the time of statement , The query cache will be emptied . Query caching is suitable for tables that are not updated frequently , Frequently queried tables , Because when the table is updated frequently , The query cache is always emptied , Too many queries add and delete cached data , It will affect MySQL Efficiency of execution , It's better to check it from the disk every time ( Cache refers to a piece of memory , Memory I/O Compare disk I/O Much faster ).
Indexing and data caching
It mainly refers to innodb_buffer_pool_size Configuration item , You can see from the name , This configuration item is for InnoDB The storage engine works , This parameter defines InnoDB The maximum memory buffer size for storing the engine's table data and index data .
innodb_buffer_pool_size Is to cache data blocks and index blocks at the same time , The higher this value is set , The disks needed to access the data in the table I/O The less .
MySQL Thread cache
It mainly refers to... In the configuration file thread_cache_size Configuration item . I told you MySQL Server The network module adopts the classic I/O Reuse + Thread pool model , The reason why thread pool is introduced , Mainly for the purpose of business execution , Not because of temporary creation and destruction of threads , Cause system performance degradation , Because the creation and destruction of threads is very performance consuming , So thread pool is before business use , First create a fixed number of threads , Waiting for events to happen , When there is SQL Request arrival MySQL Server When , Take a thread from the thread pool to execute the process SQL Just ask , After execution , Don't destroy threads , Instead, return the thread to the thread pool , Wait for the processing of the next task (MySQL According to the number of connections , Automatically increase the number of thread pools ).( The number of threads in the thread pool increases with requests , It can be added dynamically )
Scalable thread pool ( Initialization is 1 Threads , Handle all business , If the business request cannot be processed , Thread requests to the thread pool always fail , At this point, the thread pool will create more threads to process more requests , Some time after processing , Maybe there are not so many requests , Idle threads will return to the thread pool , The thread pool will also reduce the number of threads in the thread pool according to the corresponding configuration , Return resources to the system )
3、MySQL Server Optimize
Configuration of various parameters
Turn off adaptive hash indexing , Maintaining an adaptive hash index takes a lot of performance , If you rarely use , Turn it off through parameter configuration .
Improve redo log performance , Can be reset InnoDB log buffer size (redo log Cache size ),Innodb_buffer_pool_size( Cache size ), To reduce disk I/O frequency , Because the cache is large , Working in the buffer for a long time , It's more efficient .
about MySQL Server End optimization , It mainly refers to MySQL Server Optimization of configuration item content of configuration file loaded at startup
边栏推荐
- 使用MySqlBulkLoader批量插入数据
- 429-二叉树(108. 将有序数组转换为二叉搜索树、538. 把二叉搜索树转换为累加树、 106.从中序与后序遍历序列构造二叉树、235. 二叉搜索树的最近公共祖先)
- 字典树(复习)
- Online text batch inversion by line tool
- Common shell script commands (4)
- UE4: explanation of build configuration and config
- 【云驻共创】 什么是信息化?什么是数字化?这两者有什么联系和区别?
- Accumulating power in the middle stage, UFIDA IUAP builds a new base for digital intelligence of social enterprises
- Hash table - Review
- 【精品必读】Linux系统Oracle数据库趣解子查询
猜你喜欢
嵌入式软件开发中必备软件工具
【bug】联想小新出现问题,你的PIN不可用。
Connection integration development theme month | drivers of enterprise master data governance
[login interface]
拥抱云原生:江苏移动订单中心实践
带你认识图数据库性能和场景测试利器LDBC SNB
muduo
308. 二维区域和检索 - 可变 线段树/哈希
[required reading for high-quality products] sub query of Oracle database in Linux system
【debug】平台工程接口调试
随机推荐
Linux系统ORACLE 19C OEM监控管理
redis集群系列二
Is it safe to buy stocks and open an account on the account opening link of the securities manager? Ask the great God for help
使用MySqlBulkLoader批量插入数据
数据库索引
Batch insert data using MySQL bulkloader
循环遍历及函数基础知识
指针和结构体
Linux system Oracle 19C OEM monitoring management
经纬度分析
数据库日志
拥抱云原生:江苏移动订单中心实践
数组练习 后续补充
[help] troubleshooting of JVM's high CPU resource consumption
Hash table - Review
linux系统笑着玩Oracle数据库多表查询-连接查询
Redis cluster Series III
Leetcode 989. 数组形式的整数加法(简单)
ABAP-CL_OBJECT_COLLECTION工具类
多伦多大学博士论文 | 深度学习中的训练效率和鲁棒性