- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章mysql Key_buffer_size参数的优化设置由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
先来看看document对这个参数的解释
缓存myisam表的索引块大小,可以被所有进程所共享。当设置key_buffer_size,操作系统不会马上分配key_buffer_size设置的值,而是在需要的时候,再分配的。可以设置多个key_buffer,当设置不是默认key_buffer为0时,mysql会把缓存的索引块移到默认的key_buffer中去并删除不再使用的索引块。Myisam表中只能cache索引块,不能cache数据块.
原本描述:
Index blocks for MyISAM tables are buffered and are shared by all threads. key_buffer_size is the size of the buffer used for index blocks. The key buffer is also known as the key cache. 。
The maximum allowable setting for key_buffer_size is 4GB on 32-bit platforms. As of MySQL 5.0.52, values larger than 4GB are allowed for 64-bit platforms (except 64-bit Windows, for which large values are truncated to 4GB with a warning). The effective maximum size might be less, depending on your available physical RAM and per-process RAM limits imposed by your operating system or hardware platform. The value of this variable indicates the amount of memory requested. Internally, the server allocates as much memory as possible up to this amount, but the actual allocation might be less. 。
Increase the value to get better index handling (for all reads and multiple writes) to as much as you can afford. Using a value that is 25% of total memory on a machine that mainly runs MySQL is quite common. However, if you make the value too large (for example, more than 50% of your total memory) your system might start to page and become extremely slow. MySQL relies on the operating system to perform file system caching for data reads, so you must leave some room for the file system cache. Consider also the memory requirements of other storage engines. 。
1、建立缓存索引 :
mysql> set global key_buffer_1.key_buffer_size=8384512; Query OK, 0 rows affected (0.01 sec) mysql> set global key_buffer_2.key_buffer_size=8384512; Query OK, 0 rows affected (0.01 sec) 。
2、把指定表放到key buffer中 。
mysql> cache index t1,t2 in key_buffer_1; +————+——————–+———-+———-+ | Table | Op | Msg_type | Msg_text | +————+——————–+———-+———-+ | luoxuan.t1 | assign_to_keycache | status | OK | | luoxuan.t2 | assign_to_keycache | status | OK | +————+——————–+———-+———-+ 2 rows in set (0.00 sec) 。
3、预先装载表的索引块 。
mysql> load index into cache t1,t2; +————+————–+———-+———-+ | Table | Op | Msg_type | Msg_text | +————+————–+———-+———-+ | luoxuan.t1 | preload_keys | status | OK | | luoxuan.t2 | preload_keys | status | OK | +————+————–+———-+———-+ 2 rows in set (0.00 sec) 。
下面我们来看一下,如果计算命中率及key buffer的使用率 。
Cache命中率: 100 – ( (Key_reads * 100) / Key_read_requests ) 。
Key buffer的使用率 100 – ( (Key_blocks_unused * key_cache_block_size) * 100 / key_buffer_size )在mysql数据库中,mysql key_buffer_size是对MyISAM表性能影响最大的一个参数,下面就将对mysql Key_buffer_size参数的设置进行详细介绍,供您参考.
下面一台以MyISAM为主要存储引擎服务器的配置:
mysql> show variables like 'key_buffer_size'; +-----------------+------------+ | Variable_name | Value | +-----------------+------------+ | key_buffer_size | 536870912 | +-----------------+------------+ 。
分配了512MB内存给mysql key_buffer_size,我们再看一下key_buffer_size的使用情况: mysql> show global status like 'key_read%',
+------------------------+-------------+ | Variable_name | Value | +------------------------+-------------+ | Key_read_requests | 27813678764 | | Key_reads | 6798830 | +------------------------+-------------+ 。
一共有27813678764个索引读取请求,有6798830个请求在内存中没有找到直接从硬盘读取索引,计算索引未命中缓存的概率:
key_cache_miss_rate = Key_reads / Key_read_requests * 100% 。
比如上面的数据,key_cache_miss_rate为0.0244%,4000个索引读取请求才有一个直接读硬盘,已经很BT了,key_cache_miss_rate在0.1%以下都很好(每1000个请求有一个直接读硬盘),如果key_cache_miss_rate在0.01%以下的话,key_buffer_size分配的过多,可以适当减少。 MySQL服务器还提供了key_blocks_*参数:
mysql> show global status like 'key_blocks_u%'; +------------------------+-------------+ | Variable_name | Value | +------------------------+-------------+ | Key_blocks_unused | 0 | | Key_blocks_used | 413543 | +------------------------+-------------+ 。
Key_blocks_unused表示未使用的缓存簇(blocks)数,Key_blocks_used表示曾经用到的最大的blocks数,比如这台服务器,所有的缓存都用到了,要么增加key_buffer_size,要么就是过渡索引了,把缓存占满了。比较理想的设置:
Key_blocks_used / (Key_blocks_unused + Key_blocks_used) * 100% ≈ 80% 。
key_buffer_size设置注意事项 1.单个key_buffer的大小不能超过4G,如果设置超过4G,就有可能遇到下面3个bug
http://bugs.mysql.com/bug.php?id=29446 。
http://bugs.mysql.com/bug.php?id=29419 。
http://bugs.mysql.com/bug.php?id=5731 。
2.建议key_buffer设置为物理内存的1/4(针对MyISAM引擎),甚至是物理内存的30%~40%,如果key_buffer_size设置太大,系统就会频繁的换页,降低系统性能。因为MySQL使用操作系统的缓存来缓存数据,所以我们得为系统留够足够的内存;在很多情况下数据要比索引大得多.
3.如果机器性能优越,可以设置多个key_buffer,分别让不同的key_buffer来缓存专门的索引 。
上面只是对"新手"来说的,我们还可以更深入地优化key_buffer_size,使用"show status"来查看"Key_read_requests, Key_reads, Key_write_requests 以及Key_writes ",以调整到更适合你的应用的大小,Key_reads/Key_read_requests的大小正常情况下得小于0.01 。
参考资料:
http://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_key_buffer_size 。
。
优化mysql之key_buffer_size 。
key_buffer_size key_buffer_size指定索引缓冲区的大小,它决定索引处理的速度,尤其是索引读的速度。通过检查状态值Key_read_requests和Key_reads,可以知道key_buffer_size设置是否合理。比例key_reads /key_read_requests应该尽可能的低,至少是1:100,1:1000更好(上述状态值可以使用SHOW STATUS LIKE ‘key_read%'获得)。 key_buffer_size只对MyISAM表起作用。即使你不使用MyISAM表,但是内部的临时磁盘表是MyISAM表,也要使用该值。可以使用检查状态值created_tmp_disk_tables得知详情。 对于1G内存的机器,如果不使用MyISAM表,推荐值是16M(8-64M) 。
提升性能的建议: 1.如果opened_tables太大,应该把my.cnf中的table_cache变大 2.如果Key_reads太大,则应该把my.cnf中key_buffer_size变大.可以用Key_reads/Key_read_requests计算出cache失败率 3.如果Handler_read_rnd太大,则你写的SQL语句里很多查询都是要扫描整个表,而没有发挥键的作用 4.如果Threads_created太大,就要增加my.cnf中thread_cache_size的值.可以用Threads_created/Connections计算cache命中率 5.如果Created_tmp_disk_tables太大,就要增加my.cnf中tmp_table_size的值,用基于内存的临时表代替基于磁盘的 。
MySQL优化小案例:key_buffer_size key_buffer_size是对MyISAM表性能影响最大的一个参数,下面一台以MyISAM为主要存储引擎服务器的配置:
mysql> SHOW VARIABLES LIKE '%key_buffer_size%'; 下面查看key_buffer_size的使用情况:
mysql> SHOW GLOBAL STATUS LIKE '%key_read%'; +-------------------+-----------------+ | Variable_name | Value | +-------------------+-----------------+ | Key_read_requests | 2454354135490 | | Key_reads | 23490 | +-------------------+-----------------+ 2 rows in set (0.00 sec) 一共有Key_read_requests个索引请求,一共发生了Key_reads次物理IO 。
Key_reads/Key_read_requests ≈ 0.1%以下比较好.
经过对比,针对我的内存是64G的,所以我把Key_buffer_size设置为2048M,感觉好多了,么有了内存溢出情况。解决了问题。后续有什么情况我小编继续补充.
最后此篇关于mysql Key_buffer_size参数的优化设置的文章就讲到这里了,如果你想了解更多关于mysql Key_buffer_size参数的优化设置的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
比较代码: const char x = 'a'; std::cout > (0C310B0h) 00C3100B add esp,4 和 const i
您好,我正在使用 Matlab 优化求解器,但程序有问题。我收到此消息 fmincon 已停止,因为目标函数值小于目标函数限制的默认值,并且约束满足在约束容差的默认值范围内。我也收到以下消息。警告:矩
处理Visual Studio optimizations的问题为我节省了大量启动和使用它的时间 当我必须进行 J2EE 开发时,我很难回到 Eclipse。因此,我还想知道人们是否有任何提示或技巧可
情况如下:在我的 Excel 工作表中,有一列包含 1-name 形式的条目。考虑到数字也可以是两位数,我想删除这些数字。这本身不是问题,我让它工作了,只是性能太糟糕了。现在我的程序每个单元格输入大约
这样做有什么区别吗: $(".topHorzNavLink").click(function() { var theHoverContainer = $("#hoverContainer");
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: What is the cost of '$(this)'? 我经常在一些开发人员代码中看到$(this)引用同一个
我刚刚结束了一个大型开发项目。我们的时间紧迫,因此很多优化被“推迟”。既然我们已经达到了最后期限,我们将回去尝试优化事情。 我的问题是:优化 jQuery 网站时您要寻找的最重要的东西是什么。或者,我
所以我一直在用 JavaScript 编写游戏(不是网络游戏,而是使用 JavaScript 恰好是脚本语言的游戏引擎)。不幸的是,游戏引擎的 JavaScript 引擎是 SpiderMonkey
这是我在正在构建的页面中使用的 SQL 查询。它目前运行大约 8 秒并返回 12000 条记录,这是正确的,但我想知道您是否可以就如何使其更快提出可能的建议? SELECT DISTINCT Adve
如何优化这个? SELECT e.attr_id, e.sku, a.value FROM product_attr AS e, product_attr_text AS a WHERE e.attr
我正在使用这样的结构来测试是否按下了所需的键: def eventFilter(self, tableView, event): if event.type() == QtCore.QEven
我正在使用 JavaScript 从给定的球员列表中计算出羽毛球 double 比赛的所有组合。每个玩家都与其他人组队。 EG。如果我有以下球员a、b、c、d。它们的组合可以是: a & b V c
我似乎无法弄清楚如何让这个 JS 工作。 scroll function 起作用但不能隐藏。还有没有办法用更少的代码行来做到这一点?我希望 .down-arrow 在 50px 之后 fade out
我的问题是关于用于生产的高级优化级联样式表 (CSS) 文件。 多么最新和最完整(准备在实时元素中使用)的 css 优化器/最小化器,它们不仅提供删除空格和换行符,还提供高级功能,如删除过多的属性、合
我读过这个: 浏览器检索在 中请求的所有资源开始呈现 之前的 HTML 部分.如果您将请求放在 中section 而不是,那么页面呈现和下载资源可以并行发生。您应该从 移动尽可能多的资源请求。
我正在处理一些现有的 C++ 代码,这些代码看起来写得不好,而且调用频率很高。我想知道我是否应该花时间更改它,或者编译器是否已经在优化问题。 我正在使用 Visual Studio 2008。 这是一
我正在尝试使用 OpenGL 渲染 3 个四边形(1 个背景图,2 个 Sprite )。我有以下代码: void GLRenderer::onDrawObjects(long p_dt) {
我确实有以下声明: isEnabled = false; if(foo(arg) && isEnabled) { .... } public boolean foo(arg) { some re
(一)深入浅出理解索引结构 实际上,您可以把索引理解为一种特殊的目录。微软的SQL SERVER提供了两种索引:聚集索引(clustered index,也称聚类索引、簇集索引)和非聚集索引(no
一、写在前面 css的优化方案,之前没有提及,所以接下来进行总结一下。 二、具体优化方案 2.1、加载性能 1、css压缩:将写好的css进行打包,可以减少很多的体积。 2、css单一样式:在需要下边
我是一名优秀的程序员,十分优秀!