Mysql如何使用内存
每个session使用的内存:
Each thread that is used to manage client connections uses some thread-specific space. The following list indicates these and which variables control their size:
A stack (default 192KB, variable thread_stack)
A connection buffer (variable net_buffer_length)
A result buffer (variable net_buffer_length)
The connection buffer and result buffer both begin with a size given by net_buffer_length but are dynamically enlarged up to max_allowed_packet bytes as needed. The result buffer shrinks to net_buffer_length after each SQL statement. While a statement is running, a copy of the current statement string is also allocated.
每个session都有自己独占的内存空间,存储特定的信息,内存分配采用malloc(),free(),内存管理采用FIFO,应该也是增强版的先进先出,没什么区别。
key_buffer_size:
索引缓冲区的大小,只用来缓存Myisam的索引,Myisam表的数据是不会放到这个缓存里面。
我们可以通过Key_read_requests和Key_read的比例来判断设置是否合理,key_read/Key_read_requests比例要小越好,至少是在1:1000以上。
对表进行顺序扫描的请求将分配一个缓存区(变量read_buffer_size)。
当按任意顺序读取行时(例如,按照排序顺序),将分配一个随机读 缓存区(变量read_rnd_buffer_size)以避免硬盘搜索。
Myisam表文件是每个session都会打开,多个session就是打开多次,而索引只需要打开一次。
For each MyISAM table that is opened, the index file is opened once; the data file is opened once for each concurrently running thread. For each concurrent thread, a table structure, column structures for each column, and a buffer of size 3 × N are allocated (where N is the maximum row length, not counting BLOB columns). A BLOB column requires five to eight bytes plus the length of the BLOB data. The MyISAM storage engine maintains one extra row buffer for internal use.
tmp_table_size
If an internal heap table exceeds the size of tmp_table_size, MySQL handles this automatically by changing the in-memory heap table to a disk-based MyISAM table as necessary.--这个说的内部表和内存表(memory)是不一样的,内存表是不会转化的,文档中说得太模糊,基本上我已经晕了。
看看这位老兄的描述,清楚多了。
The lower value from tmp_table_size and use max_heap_table_size was used to define when temporary table was converted from memory to disk.
Also tmp_table_size was used to limit the size of the temporary table - no matter whether it’s in memory or on disk.
And max_heap_table_size was also used to limit the size of explicitly created HEAP tables.
This variable determines the maximum size for a temporary table in memory. If the table becomes too large, a MYISAM table is created on disk. Try to avoid temporary tables by optimizing the queries where possible, but where this is not possible, try to ensure temporary tables are always stored in memory. Watching the processlist for queries with temporary tables that take too long to resolve can give you an early warning that tmp_table_size needs to be upped. Be aware that memory is also allocated per-thread. An example where upping this worked for more was a server where I upped this from 32MB (the default) to 64MB with immediate effect. The quicker resolution of queries resulted in less threads being active at any one time, with all-round benefits for the server, and available memory
具体的看链接,很值得一看
http://dev.mysql.com/doc/refman/5.1/en/memory-use.html
http://dev.mysql.com/doc/refman/5.1/en/temporary-files.html
http://www.mysqlperformanceblog.com/2007/01/19/tmp_table_size-and-max_heap_table_size/
建议继续学习:
- Linux内存点滴 用户进程内存空间 (阅读:11598)
- ps - 按进程消耗内存多少排序 (阅读:11356)
- Linux Used内存到底哪里去了? (阅读:10021)
- Linux操作系统的内存使用方法详细解析 (阅读:8921)
- linux内核研究笔记(一)内存管理 – page介绍 (阅读:8766)
- 几个内存相关面试题(c/c++) (阅读:8073)
- 内存越界的概念和调试方法 (阅读:6343)
- Innodb分表太多或者表分区太多,会导致内存耗尽而宕机 (阅读:6203)
- 必看!linux系统如何查看内存使用情况 (阅读:6204)
- 如何查看Linux 硬件配置信息 (阅读:5925)
扫一扫订阅我的微信号:IT技术博客大学习
- 作者:Incessant 来源: Incessant
- 标签: 内存
- 发布时间:2009-10-11 22:33:18
- [69] Twitter/微博客的学习摘要
- [67] IOS安全–浅谈关于IOS加固的几种方法
- [65] 如何拿下简短的域名
- [65] android 开发入门
- [63] find命令的一点注意事项
- [62] Go Reflect 性能
- [61] 流程管理与用户研究
- [60] Oracle MTS模式下 进程地址与会话信
- [59] 图书馆的世界纪录
- [57] 读书笔记-壹百度:百度十年千倍的29条法则