免费注册 查看新帖 |

Chinaunix

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

我的MYSQL服务器占用CPU达到100%? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-02-26 20:37 |只看该作者 |倒序浏览
如题,用PS 查看MYSQL进程启动了五十多个线程.用TOP查看有时MYSQL占用CPU达到100%,不知道是什么原因.数据库有三十多M,不太大吧.主要是针对一个数据库进行查询和插入操作.还请高手帮忙分析一下原因.谢谢.

论坛徽章:
62
2016科比退役纪念章
日期:2016-06-28 17:45:06奥兰多魔术
日期:2015-05-04 22:47:40菠菜神灯
日期:2015-05-04 22:35:07菠菜神灯
日期:2015-05-04 22:35:02NBA季后赛大富翁
日期:2015-05-04 22:33:34NBA常规赛纪念章
日期:2015-05-04 22:32:032015年亚洲杯纪念徽章
日期:2015-04-14 16:54:452015年亚洲杯之朝鲜
日期:2015-03-19 23:03:16明尼苏达森林狼
日期:2015-03-16 21:51:152015小元宵徽章
日期:2015-03-06 15:57:202015年迎新春徽章
日期:2015-03-04 09:55:282015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2006-02-26 20:41 |只看该作者
为吗 MYSQL进程启动了五十多个线程 ?

程序没关闭?

论坛徽章:
0
3 [报告]
发表于 2006-02-26 22:44 |只看该作者
下面是用ps查看得到的结果:
root      1871  0.0  0.1  5696 1228 ?        S    13:25   0:00 /bin/sh /usr/local/mysql-4.0.22/bin/mysqld_safe --datadir=/usr/local/
mysql     1909  0.0  4.6 644260 47952 ?      S    13:25   0:01  \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/local/mysql
mysql     1910  0.0  4.6 644260 47952 ?      S    13:25   0:00      \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/local/m
mysql     1911  0.0  4.6 644260 47952 ?      S    13:25   0:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     1912  0.0  4.6 644260 47952 ?      S    13:25   0:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     1913  0.0  4.6 644260 47952 ?      S    13:25   0:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     1914  0.0  4.6 644260 47952 ?      S    13:25   0:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     1917  0.0  4.6 644260 47952 ?      S    13:25   0:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     1918  0.0  4.6 644260 47952 ?      S    13:25   0:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     1919  0.0  4.6 644260 47952 ?      S    13:25   0:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     1920  0.0  4.6 644260 47952 ?      S    13:25   0:03          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2257  3.7  4.6 644260 47952 ?      S    13:25  20:25          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2258  3.6  4.6 644260 47952 ?      S    13:25  20:05          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2259  4.0  4.6 644260 47952 ?      S    13:25  22:02          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2260  3.6  4.6 644260 47952 ?      S    13:26  19:55          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2261  3.3  4.6 644260 47952 ?      S    13:27  18:16          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2262  3.7  4.6 644260 47952 ?      S    13:28  20:02          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2369  3.5  4.6 644260 47952 ?      S    13:33  18:50          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     2900  2.9  4.6 644260 47952 ?      S    13:58  15:01          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3274  2.4  4.6 644260 47952 ?      S    14:39  11:24          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3275  2.4  4.6 644260 47952 ?      S    14:39  11:18          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3276  2.4  4.6 644260 47952 ?      S    14:39  11:35          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3542  2.1  4.6 644260 47952 ?      S    14:55   9:35          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3543  2.2  4.6 644260 47952 ?      S    14:55  10:07          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3544  2.1  4.6 644260 47952 ?      S    14:56   9:54          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3545  2.0  4.6 644260 47952 ?      S    14:56   9:18          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3546  2.1  4.6 644260 47952 ?      S    14:56   9:47          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3547  2.1  4.6 644260 47952 ?      S    14:56   9:41          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3548  2.2  4.6 644260 47952 ?      S    14:56  10:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3549  2.2  4.6 644260 47952 ?      S    14:56   9:59          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3550  2.1  4.6 644260 47952 ?      S    14:56   9:44          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3551  2.2  4.6 644260 47952 ?      S    14:56  10:04          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3552  2.1  4.6 644260 47952 ?      S    14:57   9:49          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3553  2.1  4.6 644260 47952 ?      S    14:57   9:39          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3554  2.1  4.6 644260 47952 ?      S    14:57   9:36          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3608  2.1  4.6 644260 47952 ?      S    14:58   9:42          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3609  2.1  4.6 644260 47952 ?      S    14:58   9:31          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3610  2.1  4.6 644260 47952 ?      S    15:00   9:49          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3664  2.1  4.6 644260 47952 ?      S    15:00   9:29          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3665  2.1  4.6 644260 47952 ?      S    15:00   9:34          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3666  2.0  4.6 644260 47952 ?      S    15:00   9:18          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3667  2.0  4.6 644260 47952 ?      R    15:00   9:24          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3668  2.2  4.6 644260 47952 ?      S    15:00  10:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3669  2.1  4.6 644260 47952 ?      S    15:00   9:27          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3672  2.1  4.6 644260 47952 ?      R    15:01   9:26          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3673  2.0  4.6 644260 47952 ?      R    15:01   9:06          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3833  2.2  4.6 644260 47952 ?      S    15:02  10:00          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3834  2.2  4.6 644260 47952 ?      S    15:02   9:52          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3835  2.1  4.6 644260 47952 ?      S    15:02   9:47          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3836  2.1  4.6 644260 47952 ?      S    15:02   9:23          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3837  2.2  4.6 644260 47952 ?      S    15:02   9:52          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3838  2.1  4.6 644260 47952 ?      S    15:02   9:25          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc
mysql     3839  2.1  4.6 644260 47952 ?      S    15:02   9:38          \_ /usr/local/mysql-4.0.22/libexec/mysqld --basedir=/usr/loc


下面是top的结果.有时CPU的id显示为0.0%
Tasks: 118 total,   5 running, 113 sleeping,   0 stopped,   0 zombie
Cpu(s): 63.8% us, 10.4% sy,  0.0% ni, 25.8% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:   1034032k total,   281420k used,   752612k free,    38148k buffers
Swap:  2031608k total,        0k used,  2031608k free,   141252k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                
2258 mysql     16   0  629m  46m 4724 S 85.6  4.6  20:21.38 mysqld                                 
3275 mysql     16   0  629m  46m 4724 S 63.7  4.6  11:38.52 mysqld                                 
3665 mysql     25   0  629m  46m 4724 S 51.1  4.6   9:48.15 mysqld                                 
3545 mysql     25   0  629m  46m 4724 R 44.5  4.6   9:31.83 mysqld                                 
2900 mysql     25   0  629m  46m 4724 R 30.2  4.6  15:10.31 mysqld                                 
3838 mysql     21   0  629m  46m 4724 R 16.3  4.6   9:32.44 mysqld                                 
    2 root      RT   0     0    0    0 S  5.0  0.0   1:40.85 migration/0                           
15353 root      16   0  1992  968 1664 R  0.7  0.1   0:00.27 top                                    
    1 root      16   0  1756  564 1408 S  0.0  0.1   0:01.29 init                                   
    3 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/0                           
    4 root      RT   0     0    0    0 S  0.0  0.0   0:00.11 migration/1                           
    5 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/1                           
    6 root      RT   0     0    0    0 S  0.0  0.0   0:00.25 migration/2                           
    7 root      34  19     0    0    0 S  0.0  0.0   0:00.00 ksoftirqd/2      

楼上的大哥.不知以上的情况可正常. 这种情况已有好多天了,郁闷.跟程序有关,还是MYSQL本身的问题啊

论坛徽章:
0
4 [报告]
发表于 2006-02-27 09:08 |只看该作者
我一前也遇到过这样得情况
TOP里好像是虚假的信息

重新安装较为新的版本的mysql吧

论坛徽章:
62
2016科比退役纪念章
日期:2016-06-28 17:45:06奥兰多魔术
日期:2015-05-04 22:47:40菠菜神灯
日期:2015-05-04 22:35:07菠菜神灯
日期:2015-05-04 22:35:02NBA季后赛大富翁
日期:2015-05-04 22:33:34NBA常规赛纪念章
日期:2015-05-04 22:32:032015年亚洲杯纪念徽章
日期:2015-04-14 16:54:452015年亚洲杯之朝鲜
日期:2015-03-19 23:03:16明尼苏达森林狼
日期:2015-03-16 21:51:152015小元宵徽章
日期:2015-03-06 15:57:202015年迎新春徽章
日期:2015-03-04 09:55:282015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 2006-02-27 09:10 |只看该作者
问你自己啊, 为吗 MYSQL启动了五十多个线程 ? 你有那么多连接吗?

进程号靠的很近啊

mysql本身没这个问题。

论坛徽章:
0
6 [报告]
发表于 2006-02-27 09:15 |只看该作者
先执行 show processlist; 看看都有什么在运行,然后再对症下药

论坛徽章:
0
7 [报告]
发表于 2006-02-27 09:46 |只看该作者
能不能说具体一点啊.这个线程是MYSQL自己启动的啊.数据库在UPDATE的时候速度很慢,还有另外一台服务器在远程调用这台数据库,速度也是很慢.一直查不出原因.我的my.cnf里面的配置是这样的
socket          = /tmp/mysql.sock
skip-locking
#skip-innodb
skip-name-resolve
max_allowed_packet = 4M
table_cache = 512
sort_buffer_size = 32M
net_buffer_length = 8K
myisam_sort_buffer_size = 64M
max_connections=1024
wait_timeout=120
thread_concurrency = 4
thread_cache_size=100
tmp_table_size=80M
key_buffer_size = 400M
query_cache_size=128M
query_cache_limit=1M
query_cache_type=1
read_buffer_size=8M
read_rnd_buffer_size=768K
back_log=500
interactive_timeout=120
max_connect_error=30000
long_query_time=5
innodb_flush_log_at_trx_commit=0
两颗CPU,2G的内存.

执行show processlist;没有固定的进程在运行.多次执行显示的查询是不一样的啊.有SELECT,UPDATE的

下面是我的mysql_slow.log一部分日志.long_query_time=5
# Time: 060227  9:34:54
# User@Host: root[root] @ localhost []
# Query_time: 7  Lock_time: 1  Rows_sent: 0  Rows_examined: 0
update cdb_pay set pstate='2',outtime='2006-2-27',mempsw='******' where pcode='**********' and serv
erID='1001';
# Time: 060227  9:36:10
# User@Host: root[root] @ localhost []
# Query_time: 8  Lock_time: 1  Rows_sent: 0  Rows_examined: 0
update cdb_pay set pstate='2',outtime='2006-2-27',mempsw='******' where pcode=***********and serv
erID='1002';
# Time: 060227  9:37:05
# User@Host: root[root] @ localhost []
# Query_time: 8  Lock_time: 1  Rows_sent: 0  Rows_examined: 0
update cdb_pay set pstate='2',outtime='2006-2-27',mempsw='******' where pcode='***********' and serv
erID='1001';
# Time: 060227  9:38:58
# User@Host: root[root] @ localhost []
# Query_time: 7  Lock_time: 1  Rows_sent: 0  Rows_examined: 0
update  cdb_pay set pdate='1141004330',mempsw='******',vartime='2006-2-27',unid='227',pstate='1' whe
re pcode='**********' and serverID='1001' limit 1;
# Time: 060227  9:39:12
# User@Host: root[root] @ localhost []
# Query_time: 7  Lock_time: 0  Rows_sent: 0  Rows_examined: 0
update  cdb_pay set pdate='1141004344',mempsw='******',vartime='2006-2-27',unid='227',pstate='1' whe
re pcode='***********' and serverID='1001' limit 1;
# Time: 060227  9:39:20
# User@Host: root[root] @ localhost []
# Query_time: 6  Lock_time: 0  Rows_sent: 0  Rows_examined: 0
update cdb_pay set pstate='2',outtime='2006-2-27',mempsw='*****' where pcode='***********' and serv
erID='1001';

论坛徽章:
62
2016科比退役纪念章
日期:2016-06-28 17:45:06奥兰多魔术
日期:2015-05-04 22:47:40菠菜神灯
日期:2015-05-04 22:35:07菠菜神灯
日期:2015-05-04 22:35:02NBA季后赛大富翁
日期:2015-05-04 22:33:34NBA常规赛纪念章
日期:2015-05-04 22:32:032015年亚洲杯纪念徽章
日期:2015-04-14 16:54:452015年亚洲杯之朝鲜
日期:2015-03-19 23:03:16明尼苏达森林狼
日期:2015-03-16 21:51:152015小元宵徽章
日期:2015-03-06 15:57:202015年迎新春徽章
日期:2015-03-04 09:55:282015年辞旧岁徽章
日期:2015-03-03 16:54:15
8 [报告]
发表于 2006-02-27 09:56 |只看该作者
mysql没这个本事,只有你的应用程序才有本事启动这么多。

论坛徽章:
0
9 [报告]
发表于 2006-02-27 10:12 |只看该作者
那是不是因为启动线程太多而影响了数据库的速度啊?跟MYSQL的版本有没有关系啊,
那应用程序对MYSQL应该怎么操作啊,我对程序不是很熟悉.程序语言是PHP.谢谢楼上大哥的指点.

论坛徽章:
62
2016科比退役纪念章
日期:2016-06-28 17:45:06奥兰多魔术
日期:2015-05-04 22:47:40菠菜神灯
日期:2015-05-04 22:35:07菠菜神灯
日期:2015-05-04 22:35:02NBA季后赛大富翁
日期:2015-05-04 22:33:34NBA常规赛纪念章
日期:2015-05-04 22:32:032015年亚洲杯纪念徽章
日期:2015-04-14 16:54:452015年亚洲杯之朝鲜
日期:2015-03-19 23:03:16明尼苏达森林狼
日期:2015-03-16 21:51:152015小元宵徽章
日期:2015-03-06 15:57:202015年迎新春徽章
日期:2015-03-04 09:55:282015年辞旧岁徽章
日期:2015-03-03 16:54:15
10 [报告]
发表于 2006-02-27 10:28 |只看该作者
原帖由 jason0127 于 2006-2-27 10:12 发表
那是不是因为启动线程太多而影响了数据库的速度啊?跟MYSQL的版本有没有关系啊,
那应用程序对MYSQL应该怎么操作啊,我对程序不是很熟悉.程序语言是PHP.谢谢楼上大哥的指点.




什么叫启动线程太多? 谁启动的?mysql自己不会这么做的。

怀疑系统问题,其实很无聊,应该彻底打消这个念头。系统不是完美的,只是我们普通的工作根本不可能测试出bug。

还是那几个show processlist结构看看
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP