读书人

linux 性能优化札记。 (1 G内存服务器

发布时间: 2012-09-17 12:06:51 作者: rapoo

linux 性能优化笔记。。。 (1 G内存服务器)
近期服务器性能极不稳定,打开首页速度时快时慢(目前只有一个用户,属于企业内部应用,重点是数据量非常大, 1K~ 100K 之间)

下面是从我的邮件摘录出一部分内容:

1. 访问速度不稳定。时快时慢。

868 19:12:13 INFO: Completed 200 OK in 39137ms (Views: 5839.8ms | ActiveRecord: 4412.1ms)
869 Started GET "/babble_portal/device_groups" for 172.21.100.1 at Thu May 24 19:12:25 +0000 2012
870 19:13:45 INFO: Completed 200 OK in 93696ms (Views: 38701.7ms | ActiveRecord: 40828.7ms)
871 Started GET "/babble_portal/device_groups" for 172.21.100.1 at Thu May 24 19:14:42 +0000 2012
872 21:57:41 INFO: Completed 200 OK in 9704339ms (Views: 1176.9ms | ActiveRecord: 76436.0ms)
873 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 21:57:43 +0000 2012
874 21:58:20 INFO: Completed 200 OK in 9954427ms (Views: 174.3ms | ActiveRecord: 68178.3ms)
875 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 21:58:21 +0000 2012
876 21:58:21 INFO: Completed 200 OK in 38122ms (Views: 1435.4ms | ActiveRecord: 35950.5ms)
877 21:58:45 INFO: Completed 200 OK in 23981ms (Views: 2407.9ms | ActiveRecord: 20904.1ms)


而对于 打开首页的速度,我也做了一个分析:( 见附件: landing_page_log, 使用的命令是: cat log_from_configfun/manually_2012-05-24.log | grep -E 'Completed|GET.*portal\/"' | grep GET -A 1 > landing_page_log ) 可以看出,绿色的部分表示程序运行正常,而红色的部分表示程序运行极慢。。。

49 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 18:46:38 +0000 2012
50 18:46:39 INFO: Completed 200 OK in 975ms (Views: 677.1ms | ActiveRecord: 105.7ms)
51 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 18:47:04 +0000 2012
52 18:47:05 INFO: Completed 200 OK in 981ms (Views: 685.0ms | ActiveRecord: 98.0ms)
53 --
54 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 18:48:45 +0000 2012
55 18:48:47 INFO: Completed 200 OK in 1109ms (Views: 670.0ms | ActiveRecord: 89.7ms)
56 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 18:48:51 +0000 2012
57 18:48:51 INFO: Completed 200 OK in 944ms (Views: 656.4ms | ActiveRecord: 99.7ms)
58 --
59 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 18:54:40 +0000 2012
60 18:54:42 INFO: Completed 200 OK in 1847ms (Views: 1647.4ms | ActiveRecord: 116.9ms)
61 --
62 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 18:55:10 +0000 2012
63 18:55:12 INFO: Completed 200 OK in 1330ms (Views: 1142.7ms | ActiveRecord: 102.4ms)
64 --
65 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 18:56:34 +0000 2012
66 18:56:35 INFO: Completed 200 OK in 1095ms (Views: 779.4ms | ActiveRecord: 100.7ms)
67 --
68 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 19:11:54 +0000 2012
69 19:12:13 INFO: Completed 200 OK in 39137ms (Views: 5839.8ms | ActiveRecord: 4412.1ms)
70 --
71 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 21:57:43 +0000 2012
72 21:58:20 INFO: Completed 200 OK in 9954427ms (Views: 174.3ms | ActiveRecord: 68178.3ms)
73 Started GET "/babble_portal/" for 172.21.100.1 at Thu May 24 21:58:21 +0000 2012
74 21:58:21 INFO: Completed 200 OK in 38122ms (Views: 1435.4ms | ActiveRecord: 35950.5ms)



所以我现在考虑的方向是,是不是configfun 服务器当时 ( 21:58分, 19:12分)正在忙于运行其他程序?

2. 仔细看了服务器的日志,没有发现任何出错的问题

top - 02:42:44 up 40 days, 10:17, 3 users, load average: 0.00, 0.00, 0.00Tasks: 111 total, 2 running, 109 sleeping, 0 stopped, 0 zombieCpu(s): 0.0%us, 0.1%sy, 0.0%ni, 99.9%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%stMem: 1048576k total, 366628k used, 681948k free, 12708k buffersSwap: 1052248k total, 57936k used, 994312k free, 129896k cached

看看 ps 的结果:

引用[kcv478@configfun ~]$ ps aux --sort -rss,-vsz
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
kcv478 19037 0.2 9.5 186196 100076 ? S 02:23 0:03 Rails: /rails_apps/babble_portal/releases/manuall
root 10287 0.0 0.8 38064 8900 ? S May27 0:00 Passenger spawn server
ntp 1705 0.0 0.5 19620 5316 ? SLs Apr17 3:36 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root 1924 0.0 0.4 256936 4708 ? SN Apr17 0:28 /usr/bin/python -tt /usr/sbin/yum-updatesd
root 14197 0.0 0.3 88596 3236 ? Ss 01:06 0:00 sshd: kcv478 [priv]
root 14862 0.0 0.3 88596 3236 ? Ss 01:18 0:00 sshd: kcv478 [priv]
root 16184 0.0 0.3 88596 3236 ? Ss 01:39 0:00 sshd: kcv478 [priv]
apache 10297 0.0 0.2 210820 3100 ? S May27 0:00 /usr/sbin/httpd
apache 19039 0.0 0.2 210820 2684 ? S 02:23 0:00 /usr/sbin/httpd
apache 10301 0.0 0.2 210820 2620 ? S May27 0:00 /usr/sbin/httpd
apache 10302 0.0 0.2 210820 2600 ? S May27 0:00 /usr/sbin/httpd
apache 10304 0.0 0.2 210820 2576 ? S May27 0:00 /usr/sbin/httpd
apache 10298 0.0 0.2 210820 2568 ? S May27 0:00 /usr/sbin/httpd
mysql 1768 0.0 0.2 306612 2140 ? Sl Apr17 12:16 /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/m
apache 10300 0.0 0.2 210820 2140 ? S May27 0:00 /usr/sbin/httpd
apache 10299 0.0 0.2 210820 2100 ? S May27 0:00 /usr/sbin/httpd
apache 10303 0.0 0.1 210820 2092 ? S May27 0:00 /usr/sbin/httpd
kcv478 14260 0.0 0.1 88736 1712 ? S 01:07 0:00 sshd: kcv478@pts/0
kcv478 16195 0.0 0.1 88736 1692 ? S 01:39 0:00 sshd: kcv478@pts/2
kcv478 14864 0.0 0.1 88736 1688 ? S 01:18 0:00 sshd: kcv478@pts/1
root 30621 0.0 0.1 210688 1624 ? Ss May11 5:49 /usr/sbin/httpd
root 10285 0.0 0.1 92196 1588 ? Sl May27 0:01 PassengerHelperAgent
kcv478 14261 0.0 0.1 64316 1588 pts/0 Ss+ 01:07 0:00 -bash
kcv478 16197 0.0 0.1 64316 1588 pts/2 Ss 01:39 0:00 -bash
kcv478 14865 0.0 0.1 64316 1584 pts/1 Ss+ 01:18 0:00 -bash
nobody 10290 0.0 0.1 49844 1240 ? Sl May27 0:00 PassengerLoggingAgent


很好,现在运行的进程, RSS基本都在 10MB以下。 先这样吧 :)

总结:
本以为会是一个很麻烦的过程(卸载不必要的程序啊,调试啊,等等)现在看起来,原因就在于没有及时的把原来跑着的delayed_job停止。 把它们删掉之后就问题解决了。。:-)。如此简单。

读书人网 >UNIXLINUX

热点推荐