stevep 发表于 2013-1-16 00:43:04

咨询个rails性能方面的问题

想看看rails实际的性能

用rails写了一个简单的查询用户的action,controller中show方法如下:

def show    @user = User.find_by_id(params[:id])    respond_to do |format|      format.xml    endend

部署采用 ruby 1.8.7 rails 2.3.2 , lighttpd + fastcgi 和 nginx + mongrel 两种方式实验, 操作系统是debian 5.0,数据库是mysql 5.0.51a, 服务器硬件配置是 两个4核cpu, 2G内存, rails的实例数10-15之间

使用另外一台机器多次执行 ab -n 10000 -c 20 http:///users/1.xml 进行简单的性能测试,两种部署方式的压力测试结果比较接近,下面是其中某次测试的结果

Requests per second:    1124.64 [#/sec] (mean)
Time per request:       17.783 (mean)
Time per request:       0.889 (mean, across all concurrent requests)

从 production.log的日志上来看,大部分的请求的处理时长都在1-2ms, qps的值还算可以接受

但是比较奇怪的是,整个压力测试期间,所有cpu的资源占用 几乎都是接近100%,使用htop观察都是rails进程占用,内存占用几乎维持在585M以内,使用vmstat观察,没有swap in 和 out的操作, vmstat在性能测试期间的输出

procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
rb   swpd   free   buffcache   si   so    bi    bo   in   cs us sy id wa
00      0 949500 109752 413004    0    0   0   3   12   2500 1000
140      0 947656 109752 413184    0    0   0   0 4742 10677 626 320
140      0 948152 109752 413504    0    0   0   0 6198 13899 91900
160      0 947164 109752 413876    0    0   0   0 6106 13828 91900
150      0 947664 109752 414316    0    0   0   0 6035 14070 92800
150      0 947128 109752 414664    0    0   0   0 6338 14701 92800
150      0 946780 109752 415072    0    0   02016 5815 13463 91810
160      0 946740 109752 415420    0    0   0   0 6045 13756 90 1000
150      0 945656 109752 415900    0    0   0   0 6153 14314 90 1000

为什么cpu的资源占用会这么高呢?
页: [1]
查看完整版本: 咨询个rails性能方面的问题