http - 服务器每秒处理 70 个请求,每个请求的响应时间小于 50 毫秒

标签 http tcp amazon-ec2 reusability time-wait

我从附近服务器的有限数量的 IP (< 4) 收到大量 http GET 请求。任务是为每个请求保持 <= 50 毫秒的响应时间。

我通过将 tcp_tw_reuse 设置为 1 启用了 TCP 连接重用。ip_local_port_range 设置为 1024 到 65535。

tcp_fin_timeout 设置为 60(默认值)。

在我的网络服务器配置文件 (nginx) 中,我将 keepalive_timeout 设置为 5(这是否与 tcp 的 TIME_WAIT 相关?)。

现在,我每秒收到 5 个请求,响应时间约为 200 毫秒。

我需要帮助来显着改善我的响应时间(本地计算时间可以忽略不计)。

最佳答案

我要出去猜这些是静态文件,你没有通过 cgi 传递它们。

根据我在分析和谷歌分析方面的经验,这一切都是为了找到瓶颈,或者优化最耗时的区域,而不是花费你所有的努力来加快占用你 5% 时间的过程。

我想详细了解您的设置。 一个文件的响应时间是多少? ping 的回程时间是多少? 文件有多大?

例如,如果 ping 需要 150 毫秒,则您的问题出在您的网络上,而不是您的 nginx conf。 如果文件以兆字节为单位,则不是 nginx。

如果响应时间在每秒 1 到 30 个请求之间不同,我会假设一些比更精细的 nginx 调整更强烈的东西。

你能进一步说明情况吗?

-- 更新-- 我对开箱即用的 nginx 服务器进行了基准测试,得到了一个典型的 index.php 页面。

当从服务器内部进行基准测试时:

roderick@anon-webserver:~$ ab -r -n 1000 -c 100 http://anon.com/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking anon.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/0.8.54
Server Hostname:        anon.com
Server Port:            80

Document Path:          /index.php
Document Length:        185 bytes

Concurrency Level:      100
Time taken for tests:   0.923 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      380000 bytes
HTML transferred:       185000 bytes
Requests per second:    1083.19 [#/sec] (mean)
Time per request:       92.320 [ms] (mean)
Time per request:       0.923 [ms] (mean, across all concurrent requests)
Transfer rate:          401.96 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        2    4   1.6      4       9
Processing:     1   43 147.6      4     833
Waiting:        1   41 144.4      3     833
Total:          4   47 148.4      8     842

Percentage of the requests served within a certain time (ms)
  50%      8
  66%      8
  75%      9
  80%      9
  90%     13
  95%    443
  98%    653
  99%    654
 100%    842 (longest request)

从我的家用桌面进行基准测试时:

roderick@Rod-Dev:~$ ab -r -n 1000 -c 100 http://anon.com/index.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking anon.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests


Server Software:        nginx/0.8.54
Server Hostname:        anon.com
Server Port:            80

Document Path:          /index.php
Document Length:        185 bytes

Concurrency Level:      100
Time taken for tests:   6.391 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Non-2xx responses:      1000
Total transferred:      380000 bytes
HTML transferred:       185000 bytes
Requests per second:    156.48 [#/sec] (mean)
Time per request:       639.063 [ms] (mean)
Time per request:       6.391 [ms] (mean, across all concurrent requests)
Transfer rate:          58.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:       40  260 606.9    137    3175
Processing:    81  214 221.7    140    3028
Waiting:       81  214 221.6    140    3028
Total:        120  474 688.5    277    6171

Percentage of the requests served within a certain time (ms)
  50%    277
  66%    308
  75%    316
  80%    322
  90%    753
  95%    867
  98%   3327
  99%   3729
 100%   6171 (longest request)

我的操作系统是 linux,我的 cpu 使用了 3 年(那是一台 500 美元的服务器)。

我绝对没有对配置文件做任何事情。

这告诉我什么? nginx 不是问题。

您的服务器网络中断或 AWS 正在限制您的 CPU。我可能会猜到两者。

如果修复有那么重要,我会得到一个专用服务器。但这只是我的知识范围。

关于http - 服务器每秒处理 70 个请求,每个请求的响应时间小于 50 毫秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9259869/

相关文章:

http - 可以使用Grails将 header 添加到重定向中

Android: fragment 中的Http请求

linux - Haproxy 中大量的 TIME_WAIT

amazon-web-services - 公有子网中的 AWS NLB,私有(private)子网中的 EC2

ubuntu - 我应该为 Ubuntu 10.04 或 11.04 使用哪个 AWS AMI,并运行 node.js?

c# - Amazon EC2 上的实时 TCP/IP 套接字服务器

http ://mysite. com 与 http ://www. mysite.com 的 JavaScript 问题

java - 在另一个类中运行网络操作时出现网络策略违规

java - 压缩类错误 - 线程异常 "main"java.lang.StringIndexOutOfBoundsException : String index out of range: -1

tcp - 哪个超时值决定了多长时间空闲的TCP连接会被关闭?