- 浏览: 1523465 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (532)
- 软件设计师 (7)
- PSP (5)
- NET MD (9)
- Hibernate (8)
- DIY (51)
- Work (43)
- GAME (24)
- 未分类 (44)
- iPod (6)
- MySQL (39)
- JSP (7)
- 日语能力考试 (36)
- 小说 (4)
- 豆包网 (23)
- 家用电脑 (7)
- DB2 (36)
- C/C++ (18)
- baby (9)
- Linux (13)
- thinkpad (23)
- OA (1)
- UML (6)
- oracle (24)
- 系统集成 (27)
- 脑梗塞 (6)
- 车 (8)
- MainFrame (8)
- Windows 7 (13)
- 手机 (8)
- git (12)
- AHK (2)
- COBOL (2)
- Java (9)
最新评论
-
安静听歌:
... ...
UUID做主键,好还是不好?这是个问题。 -
lehehe:
http://www.haoservice.com/docs/ ...
天气预报 -
lehehe:
[url http://www.haoservice.com/ ...
天气预报 -
liubang201010:
监控TUXEDO 的软件推荐用这个,专业,权威.并能提供报警和 ...
(转载)Tuxedo中间件简介 -
tinkame:
Next[j] =-1 当j=0时;=Max{k|0<k ...
KMP字符串模式匹配详解
对拥有一个几十万行表的 MySQL 性能优化的简单办法 | |
数据库的优化大概是在系统管理中最具有挑战性的了,因为其对人员的素质要求几乎是全方面的,好的 DBA 需要各种综合素质。在排除了操作系统,应用等引起的性能问题以外,优化数据库最核心的实际上就是配置参数的调整。本文通过一个简单的参数调整,实现了对拥有一个几十万行表的 group by 优化的例子。通过这个简单的调整,数据库性能有了突飞猛进的提升。
本例子是针对 MySQL 调整的,不像其他商业数据库,MySQL 没有视图,特别是 Oracle 可以利用固化视图来提升查询性能,没有存储过程,因此性能的调整几乎只能通过配置合适的参数来实现。
调整的具体步骤(例子针对 pLog 0.3x 的博客系统):
发现最多的 slow log 是:
SELECT category_id, COUNT(*) AS 'count' FROM plog_articles WHERE blog_id = 2 AND status = 'PUBLISHED' group by category_id;
一般在 20s 以上,甚至 30s 。
而当 blog_id=1 或者其他时,都能很快的选出结果。
于是怀疑索引有问题,重新建立索引,但无济于事。 EXPLAIN 结果如下:
mysql> EXPLAIN SELECT category_id, COUNT(*) AS 'count' FROM plog_articles WHERE blog_id = 2 AND status = 'PUBLISHED' group by category_id;
+---------------+------+------------------+------------------+---------+-------------+------+----------------------------------------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+---------------+------+------------------+------------------+---------+-------------+------+----------------------------------------------+
| plog_articles | ref | idx_article_blog | idx_article_blog | 5 | const,const | 4064 | Using where; Using temporary; Using filesort |
+---------------+------+------------------+------------------+---------+-------------+------+----------------------------------------------+
1 row in set (0.00 sec)
于是想到每次查看 blog_id = 2 的博客时,系统负载就提高,有较高的 swap 。于是查看 temporary table 有关的资料,果然有这样的说法:
If you create a lot of disk-based temporary tables, increase the size of tmp_table_size if you can do so safely. Keep in mind that setting the value too high may result in excessive swapping or MySQL running out of memory if too many threads attempt to allocate in-memory temporary tables at the same time. Otherwise, make sure that tmpdir points to a very fast disk that's not already doing lots of I/O.
Another problem that doesn't show up in the slow query log is an excessive use of disk-based temporary tables. In the output of EXPLAIN, you'll often see Using temporary. It indicates that MySQL must create a temporary table to complete the query. However, it doesn't tell you whether that temporary table will be in memory or on disk. That's controlled by the size of the table and MySQL's tmp_table_size variable.
If the space required to build the temporary table is less than or equal to tmp_table_size, MySQL keeps it in memory rather than incur the overhead and time required to write the data to disk and read it again. However, if the space required exceeds tmp_table_size, MySQL creates a disk-based table in its tmpdir directory (often /tmp on Unix systems.) The default tmp_table_size size is 32 MB.
To find out how often that happens, compare the relative sizes of the Created_tmp_tables and Created_tmp_disk_tables counters:
调整 tmp_table_size为 80M 左右后,以上语句 14s 即可解决。
这个参数是 DBA 很容易忽视的。
其实,不单单是数据库,就是操作系统,也是受 tmp 的影响巨大,例如安装软件到 d: 盘,如果 TMP 环境变量指向 c: 盘,而 c: 空间不够,照样可能导致安装失败。
因此让 TMP 有足够的空间可以说是计算机系统里一个普遍适用的原则(写程序也是一样)。
发表评论
-
MySQL配置文件my.cnf 例子最详细翻译
2009-07-20 11:58 1717http://www.blogjava.net/hunte ... -
MySQL :: @@Rowcount in MySQL
2009-03-02 15:39 2152@@Rowcount in MySQL? Posted ... -
MYSQL中删除重复记录的方法
2009-02-26 12:23 0MYSQL中删除重复记录的方法 2008 ... -
使用 MYSQLBINLOG 来恢复数据。
2009-02-26 12:21 0使用 MYSQLBINLOG 来恢复数据。 20 ... -
13.2.3. InnoDB Startup Options and System Variable
2009-02-20 13:37 1241http://dev.my ... -
mysql innodb 配置详解
2009-02-20 11:01 3547加为好友发送私信在线聊天 -
20.3.9 关于死锁 深入浅出MySQL——数据库开发、优化与管理维护
2009-02-20 10:50 3125深入浅出MySQL——数据库开发、优化与管理维护 回 ... -
mysql的临时表不支持自连接
2009-02-18 13:32 2324TEMPORARY TABLE ProblemsThe fol ... -
windows 下安装两个MySQL收藏
2009-02-03 16:28 2359由于两个MySQL进程需要不同的配置文件,以下所有操作均是在W ... -
1.4.1. What's New in MySQL 5.1
2009-02-03 16:25 11481.4.1. What's New in My ... -
查看mysql版本的四种方法
2009-02-02 10:57 9391:在终端下:mysql -V。 以下 ... -
Server SQL Modes
2009-02-01 11:06 13975.1.7. Server SQL Modes ... -
MySQL中的各种JOIN(CROSS JOIN, INNER JOIN, LEFT [OUTER]
2009-01-13 14:50 6183MySQL中的各种JOIN(CROSS JOIN, I ... -
[转]SQL Server 2000执行计划成本(5/5)
2009-01-09 15:26 1169[转]SQL Server 2000执行计划成本(5/5) ... -
SQL Server 2000执行计划成本(4/5)
2009-01-09 15:25 1077[转]SQL Server 2000执行计划成本(4/5) ... -
[转]SQL Server 2000执行计划成本(3/5)
2009-01-09 15:23 1501[转]SQL Server 2000执行计划成本(3/5) ... -
SQL Server 2000执行计划成本(1/5)
2009-01-09 14:52 1615[转]SQL Server 2000执行计划成本(1/5) ... -
浅谈MySQL数据库优化
2009-01-09 14:46 1305浅谈MySQL数据库优化 [收藏此页] [打印] ... -
sql server支持create table as ...建表么
2009-01-09 11:52 8978sql server支持create table as .. ... -
SQL Server如何识别自动创建的索引
2009-01-08 15:57 1276SQL Server如何识别自动创建的索引 http://w ...
相关推荐
经过对MySQL innodb的一些性能测试,发现一些可以提高insert效率的方法,供大家参考参考。 1. 一条SQL语句插入多条数据。 常用的插入语句如: INSERT INTO `insert_table` (`datetime`, `uid`, `...
笔者最近工作中遇见一个性能瓶颈问题,MySQL表,每天大概新增776万条记录,存储周期为7天,超过7天的数据需要在新增记录前老化。连续运行9天以后,删除一天的数据大概需要3个半小时(环境:128G, 32核,4T硬盘),而...
有个几千万条记录的表 on MySQL 5.0.x,现在要读出其中几十万万条左右的记录。常用方法,依次循环: select * from mytable where index_col = xxx limit offset, limit; 经验:如果没有blob/text字段,单行记录...
在这一版本中,SQL 执行引擎引入新的内部数据表示方式 --- `Chunk`,一个结构中保存一批数据而不仅是一行数据,同一列的数据在内存中连续存放,使得内存使用更紧凑,这样带来了几点好处:1. 显著减小了内存消耗; 2....
9. 系统性能优化,大大提高运行速度,能轻松支持十万级文章数的内容管理,如:网博资讯网、周游旅游网、Newsfeed Online 等 四、增加功能 1. 增加 FCKEditor 编辑器 五、模版调整 1. 增加 Mambo4.5.2.3 黄金...
Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多的网络程序,这是最基础的部分。 递归遍历矩阵 1个目标文件,简单! 多人聊天室 3...
Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多的网络程序,这是最基础的部分。 递归遍历矩阵 1个目标文件,简单! 多人聊天室 3...
9. 系统性能优化,大大提高运行速度,能轻松支持十万级文章数的内容管理,如:网博资讯网、周游旅游网、Newsfeed Online 等 四、增加功能 1. 增加 FCKEditor 编辑器 五、模版调整 1. 增加 Mambo4.5....
全新的内核,数据上几十万也没问题 05. 能链接RayFile网络硬盘的歌曲,节省服务器费用,空间就能运行 06. 采集DJ音乐到本地 07. 自定义生成目录路径 08. 远程FTP/本地扫描的歌曲数据,自动加入...