my43_mysql内存相关概念

 

相关参数

read_buffer_size

https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_read_buffer_size

If you do many sequential scans, you might want to increase this value, which defaults to 131072.

The value of this variable should be a multiple of 4KB. If it is set to a value that is not a multiple of 4KB, its value will be rounded down to the nearest multiple of 4KB.

This option is also used in the following context for all storage engines:
For caching the indexes in a temporary file (not a temporary table), when sorting rows for ORDER BY.
For bulk insert into partitions.
For caching results of nested queries.
read_buffer_size is also used in one other storage engine-specific way:

to determine the memory block size for MEMORY tables.


For more information about memory use during different operations, see Section 8.12.3.1, “How MySQL Uses Memory”.

read_rnd_buffer_size

https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_read_rnd_buffer_size

This variable is used for reads from MyISAM tables, and, for any storage engine, for Multi-Range Read optimization.

When reading rows from a MyISAM table in sorted order following a key-sorting operation, the rows are read through this buffer to avoid disk seeks. See Section 8.2.1.16, “ORDER BY Optimization”. Setting the variable to a large value can improve ORDER BY performance by a lot. However, this is a buffer allocated for each client, so you should not set the global variable to a large value. Instead, change the session variable only from within those clients that need to run large queries.

Multi-Range Read:减少磁盘的随机访问,并且将随机访问转化为较为顺序的数据访问,详细说明请参见

https://www.cnblogs.com/olinux/p/5146868.html

sort_buffer_size

https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_sort_buffer_size

If you see many Sort_merge_passes per second in SHOW GLOBAL STATUS output, you can consider increasing the sort_buffer_size value to speed up ORDER BY or GROUP BY operations that cannot be improved with query optimization or improved indexing.

The optimizer tries to work out how much space is needed but can allocate more, up to the limit. Setting it larger than required globally will slow down most queries that sort. It is best to increase it as a session setting, and only for the sessions that need a larger size. On Linux, there are thresholds of 256KB and 2MB where larger values may significantly slow down memory allocation, so you should consider staying below one of those values. Experiment to find the best value for your workload. See Section B.4.3.5, “Where MySQL Stores Temporary Files”.

其他参考

https://www.cnblogs.com/wy123/p/7744171.html

配置示例

64G物理内存,sort_buffer_size=4M

| Sort_merge_passes                             | 11                                                 |
| Sort_range                                    | 55963361                                           |
| Sort_rows                                     | 1347711564                                         |
| Sort_scan                                     | 83848520  

mysql配置文件主要参数

https://www.jb51.net/article/48082.htm

binlog_cache_size

https://dev.mysql.com/doc/refman/8.0/en/replication-options-binary-log.html#sysvar_binlog_cache_size

写入binlog事务的缓冲区,线程级参数。

The size of the memory buffer to hold changes to the binary log during a transaction. When binary logging is enabled on the server (with the log_bin system variable set to ON), a binary log cache is allocated for each client if the server supports any transactional storage engines. If the data for the transaction exceeds the space in the memory buffer, the excess data is stored in a temporary file. When binary log encryption is active on the server, the memory buffer is not encrypted, but (from MySQL 8.0.17) any temporary file used to hold the binary log cache is encrypted. After each transaction is committed, the binary log cache is reset by clearing the memory buffer and truncating the temporary file if used.


If you often use large transactions, you can increase this cache size to get better performance by reducing or eliminating the need to write to temporary files. The Binlog_cache_use and Binlog_cache_disk_use status variables can be useful for tuning the size of this variable. See Section 5.4.4, “The Binary Log”.

配置示例一:

binlog_cache_size 32K,物理内存64G

mysql> show global status like 'Binlog_cache%';
+-----------------------+-----------+
| Variable_name         | Value     |
+-----------------------+-----------+
| Binlog_cache_disk_use | 5169527   |
| Binlog_cache_use      | 897476315 |
+-----------------------+-----------+
2 rows in set (0.00 sec)

mysql> show global status like 'Binlog_cache%';
+-----------------------+-----------+
| Variable_name         | Value     |
+-----------------------+-----------+
| Binlog_cache_disk_use | 5169534   |
| Binlog_cache_use      | 897476897 |
+-----------------------+-----------+
2 rows in set (0.00 sec)

mysql> show global status like 'Binlog_cache%';
+-----------------------+-----------+
| Variable_name         | Value     |
+-----------------------+-----------+
| Binlog_cache_disk_use | 5169536   |
| Binlog_cache_use      | 897477059 |
+-----------------------+-----------+
mysql> show global status like 'Sort%';
+-------------------+-------------+
| Variable_name     | Value       |
+-------------------+-------------+
| Sort_merge_passes | 6732        |
| Sort_range        | 521537793   |
| Sort_rows         | 11590846064 |
| Sort_scan         | 3845091301  |
+-------------------+-------------+
4 rows in set (0.00 sec)

mysql> 
mysql> show global status like 'Sort%';
+-------------------+-------------+
| Variable_name     | Value       |
+-------------------+-------------+
| Sort_merge_passes | 6732        |
| Sort_range        | 521537839   |
| Sort_rows         | 11590846115 |
| Sort_scan         | 3845091308  |
+-------------------+-------------+
4 rows in set (0.01 sec)

mysql> show global status like 'Sort%';
+-------------------+-------------+
| Variable_name     | Value       |
+-------------------+-------------+
| Sort_merge_passes | 6732        |
| Sort_range        | 521537992   |
| Sort_rows         | 11590846217 |
| Sort_scan         | 3845091328  |
+-------------------+-------------+
4 rows in set (0.01 sec)
原文地址:https://www.cnblogs.com/perfei/p/12251331.html