gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 07:36:50 24 4
gpt4 key购买 nike

我正在一台强大的机器上托管一个 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 基准测试所针对的站点根目录是 Action 缓存的,甚至不涉及数据库。对它的单个请求如下所示:
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 企业版、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 ) 以检查所有进程是否已加载并在它们之间均匀分配请求。

关于ruby-on-rails - 大型机器上的 Rails 应用程序仅获得 60 个请求/秒的基准测试结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10229057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com