ruby-on-rails – 大型机器上的Rails应用程序只能获得60个请求/秒的基准测试结果

我正在一台强大的机器上托管一个Rails应用程序 – 我认为 – 它应该能够处理比我给它更高的负载.以下是ApacheBench令人印象深刻的测试结果:

ab -kc 250 -n 1000 -H "Accept-Encoding: gzip,deflate" https://www.mysite.com/

Server Software:        nginx/1.0.15
Server Hostname:        www.mysite.com
Server Port:            443
SSL/TLS Protocol:       TLSv1/SSLv3,DHE-RSA-AES256-SHA,2048,256

Document Path:          /
Document Length:        4258 bytes

Concurrency Level:      250
Time taken for tests:   16.498 seconds
Complete requests:      1000
HTML transferred:       4258000 bytes
Requests per second:    60.61 [#/sec] (mean)
Time per request:       4124.432 [ms] (mean)
Time per request:       16.498 [ms] (mean, across all concurrent requests)
Transfer rate:          282.83 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:      302 1801 866.3   1623    3583
Processing:   183 1993 867.9   1873    7050
Waiting:      183 1880 864.2   1743    7036
Total:       1397 3794 1389.0   3558   10580

Percentage of the requests served within a certain time (ms)
  50%   3558
  66%   4012
  75%   4179
  80%   4712
  90%   4947
  95%   6411
  98%   8376
  99%   8380
 100%  10580 (longest request)

呸.也许我错了,但我觉得我应该能够获得远高于每秒60个请求的数量,并且每次请求的时间要低得多于4.1秒.

该应用程序位于c1.xlarge EC2实例(7 GB内存20 EC2计算单元,8个虚拟核心,每个2.5 EC2计算单元,1690 GB实例存储64位平台,I / O性能:高). ApacheBench基准测试运行的站点根目录正在进行操作缓存,甚至不会触及数据库.对它的单个请求如下所示:

Started GET "/" for ##.###.###.## at Thu Apr 19 13:05:50 +0000 2012
  Processing by OneOfMyControllers#index as HTML
  Read fragment views/www.mysite.com/index (1.1ms)
  Completed 200 OK in 2ms

该机器正在运行Ubuntu 11.04,我正在使用Rails 3.1,Ruby Enterprise Edition,Passenger和nginx.我的nginx配置看起来像这样:

worker_processes  8;
worker_rlimit_nofile 65535;

events {
    worker_connections 4096;
}

http {
    passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-3.0.8;
    passenger_ruby /usr/bin/ruby1.8;

    rails_spawn_method smart;
    rails_app_spawner_idle_time 0;
    rails_framework_spawner_idle_time 0;

    passenger_max_pool_size 60;
    passenger_pool_idle_time 1000;

    ssl_session_cache shared:SSL:3m;  # 3MB can hold about 12k SSL cache sessions
    ssl_session_timeout 5m; # average user spends 5 minutes on our site

    include       mime.types;
    default_type  application/octet-stream;

    sendfile       on;
    tcp_nopush     on; # useful with the sendfile option
    tcp_nodelay    off; 

    keepalive_timeout     10;
    send_timeout          10;
    client_body_timeout   10;
    client_header_timeout 10;

    gzip              on;
    gzip_static       on;
    gzip_disable      "MSIE [1-6]\.";
    gzip_comp_level   4;
    gzip_buffers      16 4k;
    gzip_min_length   1000;
    gzip_proxied      any;
    gzip_vary         on;
    gzip_types        text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_http_version 1.0; # Amazon CloudFront uses HTTP/1.0                                            

    include /opt/nginx/conf/sites-enabled/*;
}

在/opt/nginx/conf/sites-enabled/mysite.com里面,我得到了:

server {
    listen         80;
    server_name    mysite.com;

    rewrite ^/(.*) http://www.mysite.com/$1 permanent;
}
server {
    listen         443;
    ssl            on;
    server_name    mysite.com;

    ssl_certificate           /opt/mysite/ssl/wildcard_gandi_2012/combined-certification.crt;
    ssl_certificate_key       /opt/mysite/ssl/wildcard_gandi_2012/monserveur.key;
    ssl_protocols             SSLv3 TLSv1;
    ssl_ciphers               HIGH:!ADH:!MD5;
    ssl_prefer_server_ciphers on;

    rewrite ^/(.*) https://www.mysite.com/$1 permanent;
}
server {
    listen            80;
    server_name       *.mysite.com www.mysite.com;

    root /opt/mysite/public;

    passenger_enabled on;

    access_log  /opt/mysite/log/nginx_access.log;
    error_log   /opt/mysite/log/nginx_error.log;

    # Set the maximum file upload size to 25 MB.
    client_max_body_size 25M;
}
server {
    listen            443;
    ssl               on;
    server_name       *.mysite.com www.mysite.com;

    ssl_certificate           /opt/mysite/ssl/wildcard_gandi_2012/combined-certification.crt;
    ssl_certificate_key       /opt/mysite/ssl/wildcard_gandi_2012/monserveur.key;
    ssl_protocols             SSLv3 TLSv1;
    ssl_ciphers               HIGH:!ADH:!MD5;
    ssl_prefer_server_ciphers on;

    root /opt/mysite/public;

    passenger_enabled on;

    access_log  /opt/mysite/log/nginx_access.log;
    error_log   /opt/mysite/log/nginx_error.log;

    # Set the maximum file upload size to 25 MB.
    client_max_body_size 25M;

    # Asset caching
    location ~ ^/(assets)/  {
        root /opt/mysite/public;
        gzip_static on;
        access_log off;
        expires 1y;
        add_header Cache-Control public;
        add_header Last-Modified "";
        add_header ETag "";
        break;
    }
}

知道为什么我不能获得超过60个请求/秒?我有什么明显的东西可以忽略吗?

解决方法:

我怀疑你的一个重大问题是https.

我刚刚运行了一些比较基准测试,对我来说,他们在这样一个非常基本的页面上显示速度降低了2-4倍.如果您点击HTTP页面,您的指标会增加吗?

还要检查您的乘客状态(rvmsudo passenger-status)以检查是否已加载所有进程并均匀地在其中分配请求.

上一篇:1006 Sign In and Sign Out (25 分)


下一篇:使用layui框架导出table表为excel