免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2537 | 回复: 7
打印 上一主题 下一主题

求助-Mysql服务器消耗CPU的问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-22 12:05 |只看该作者 |倒序浏览
机器配置:1CPU 2.4GHZ 1GMEM
Mysql:4.0.26
Apache:2.0.59 worker
PHP:4.4.4

这几天因为测试系统的性能,所以用ab和loadrunner测试了一下连接的压力,结果发现
Mysql的CPU总是很高,基本都在80%以上,只要前台开两个并发甚至用ab -n 1000 -c 1 http://×××/index_new.php
然后sar -u 1 5就发现idle基本为0,cpu全被消耗了,而内存消耗很少,
index_new.php里面就是有不到10个SQL查询,PHP也是用的connect连接的Mysql
期间查看Mysql show full processlist,连接数很少,只是id刷新变化很频繁而已
我还试了一下jboss的页面(页面不到5个sql),现象一样,换了 一台机器,现象也是一样
只有一台web 另外一台单独做mysql server的时候稍微好点,但cpu也高达50%以上,此时并发不过20用户,
这些页面的SQL我都单独优化了,都是毫秒级的执行

My.cnf如下:
[mysqld]
back_log=200
max_allowed_packet=8M
max_connections=200
max_user_connections=195
query_cache_type=1
log_slow_queries=/db/mysql/mysql-slow-qry.log
long_query_time=1
skip-locking
key_buffer = 128M
table_cache = 512
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
join_buffer_size = 4M
myisam_sort_buffer_size = 64M
skip-name-resolve
thread_cache_size = 64
thread_stack = 256k
query_cache_size = 64M
wait_timeout=7200
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 2
# Uncomment the following if you are using InnoDB tables
#innodb_data_home_dir = /var/lib/mysql/
#innodb_data_file_path = ibdata1:200M;ibdata2:50M:autoextend
#innodb_log_group_home_dir = /var/lib/mysql/
#innodb_log_arch_dir = /var/lib/mysql/
# You can set .._buffer_pool_size up to 50 - 80 %
# of RAM but beware of setting memory usage too high
innodb_buffer_pool_size = 128M
#innodb_additional_mem_pool_size = 20M
# Set .._log_file_size to 25 % of buffer pool size
#innodb_log_file_size = 64M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
default-character-set=gb2312
#log-update = /db/mysql/update
innodb_table_locks = 0
#innodb_thread_concurrency = 6
tmp_table_size = 192M

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash

[myisamchk]
key_buffer = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout

后台mysql-slow-qry.sql也没发现该页面存在速度慢的sql,现在着实无从下手,高人帮忙分析一下

论坛徽章:
0
2 [报告]
发表于 2007-05-22 12:35 |只看该作者
加大buffer和cache的数量试试看

论坛徽章:
0
3 [报告]
发表于 2007-05-23 10:18 |只看该作者
加大了,可还是没有明显的改善,现在怀疑不是参数的问题,可能是php里面的query语句有问题
但是当初写完sql以后专门在sqlylg里面执行看过 都是百毫秒的
select b.fid, b.name, count(a.pid) hj  
   from cdb_posts a, cdb_forums b
where a.fid = b.fid   
    and b.fup = 85  
group by b.fid
order by hj desc
   limit 0, 10
简单的表关联,实在看不出还有什么需要优化的了

论坛徽章:
0
4 [报告]
发表于 2007-05-23 17:08 |只看该作者
sort_buffer 加大这个和 thread_cache_size这个看下呢?

论坛徽章:
0
5 [报告]
发表于 2007-05-23 19:16 |只看该作者
explain select b.fid, b.name, count(a.pid) hj  
   from cdb_posts a, cdb_forums b
where a.fid = b.fid   
    and b.fup = 85  
group by b.fid
order by hj desc
   limit 0, 10

贴下这个结果

论坛徽章:
0
6 [报告]
发表于 2007-05-23 19:54 |只看该作者
估计会报错,呵呵

论坛徽章:
0
7 [报告]
发表于 2007-05-24 08:40 |只看该作者
explain以后
"b","ref","PRIMARY\,fup","fup",2,"const",22,"Using where; Using temporary; Using filesort"
"a","ref","fid","fid",2,"b.fid",513,""

sort_buffer_size 4M
thread_cache_size 128
好多了 现在一般在20%以下了 现在压力变到apache上了
谢谢大家了 一个url包括太多环节了 想摘清楚真不容易

论坛徽章:
0
8 [报告]
发表于 2007-05-24 13:53 |只看该作者
按你的机器 key_buffer 加大一点儿 再试试呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP