http - CouchDB/MochiWeb : negative effect of persistent connections

标签 http tcp profiling couchdb congestion-control

我在我的 Mint/Debian 机器上非常简单地设置了 CouchDB。我的 Java webapp 在查询 CouchDB 时遇到了相当长的延迟,所以我开始寻找原因。

编辑:查询模式是很多小查询和小 JSON 对象(例如 300 字节向上/1Kbyte 向下)。

Wireshark 转储非常好,显示大部分请求-响应周转时间为 3-5 毫秒。 JVM 帧采样向我展示了套接字代码(对 Couch 的客户端查询)有点忙,但没什么特别的。然后我尝试使用 ApacheBench 和 oops 进行相同的分析:我目前看到 keep-alive 相对于非持久性设置引入了稳定的额外 39 毫秒延迟。

有人知道怎么解释吗?也许持久连接会增加 TCP 层上的拥塞窗口,然后由于 TCP_WAIT 和较小的请求/响应大小或类似原因而空闲? 是否应该为环回 tcp 连接打开此选项 (TCP_WAIT)?

w@mint ~ $ uname -a
Linux mint 2.6.39-2-486 #1 Tue Jul 5 02:52:23 UTC 2011 i686 GNU/Linux
w@mint ~ $ curl http://127.0.0.1:5984/
{"couchdb":"Welcome","version":"1.1.1"}

运行 keep alive,平均每个请求 40 毫秒

w@mint ~ $ ab -n 1024 -c 1 -k http://127.0.0.1:5984/
>>>snip
Server Software:        CouchDB/1.1.1
Server Hostname:        127.0.0.1
Server Port:            5984

Document Path:          /
Document Length:        40 bytes

Concurrency Level:      1
Time taken for tests:   41.001 seconds
Complete requests:      1024
Failed requests:        0
Write errors:           0
Keep-Alive requests:    1024
Total transferred:      261120 bytes
HTML transferred:       40960 bytes
Requests per second:    24.98 [#/sec] (mean)
Time per request:       40.040 [ms] (mean)
Time per request:       40.040 [ms] (mean, across all concurrent requests)
Transfer rate:          6.22 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1   40   1.4     40      48
Waiting:        0    1   0.7      1       8
Total:          1   40   1.3     40      48

Percentage of the requests served within a certain time (ms)
  50%     40
>>>snip
  95%     40
  98%     41
  99%     44
 100%     48 (longest request)

没有 keepalive,瞧 - 大多数情况下每个请求 1 毫秒。

w@mint ~ $ ab -n 1024 -c 1 http://127.0.0.1:5984/
>>>snip
Time taken for tests:   1.080 seconds
Complete requests:      1024
Failed requests:        0
Write errors:           0
Total transferred:      236544 bytes
HTML transferred:       40960 bytes
Requests per second:    948.15 [#/sec] (mean)
Time per request:       1.055 [ms] (mean)
Time per request:       1.055 [ms] (mean, across all concurrent requests)
Transfer rate:          213.89 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    1   1.0      1      11
Waiting:        1    1   0.9      1      11
Total:          1    1   1.0      1      11

Percentage of the requests served within a certain time (ms)
  50%      1
>>>snip
  80%      1
  90%      2
  95%      3
  98%      5
  99%      6
 100%     11 (longest request)

好的,现在启用了 keep-alive,但还要求通过 http header 关闭连接。每个请求也需要 1 毫秒左右。

w@mint ~ $ ab -n 1024 -c 1 -k -H 'Connection: close' http://127.0.0.1:5984/
>>>snip
Time taken for tests:   1.131 seconds
Complete requests:      1024
Failed requests:        0
Write errors:           0
Keep-Alive requests:    0
Total transferred:      236544 bytes
HTML transferred:       40960 bytes
Requests per second:    905.03 [#/sec] (mean)
Time per request:       1.105 [ms] (mean)
Time per request:       1.105 [ms] (mean, across all concurrent requests)
Transfer rate:          204.16 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    1   1.2      1      14
Waiting:        0    1   1.1      1      13
Total:          1    1   1.2      1      14

Percentage of the requests served within a certain time (ms)
  50%      1
>>>snip
  80%      1
  90%      2
  95%      3
  98%      6
  99%      7
 100%     14 (longest request)

最佳答案

是的,这与 tcp 套接字设置选项有关。此配置现在使所有三种情况均以每个请求 1 毫秒的速度趋于平稳。

[httpd]
socket_options = [{nodelay, true}]

详情请看这里: http://wiki.apache.org/couchdb/Performance#Network

关于http - CouchDB/MochiWeb : negative effect of persistent connections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8992122/

相关文章:

javascript - 为什么浏览器在这里低效地发出 2 个请求?

spring - 我的 tcp 客户端使用 spring 集成无法获得响应

java - 如何设置 block 超时?

c++ - VS2005 Debug模式和 Release模式之间的巨大性能影响

c# - 运行时代码覆盖工具

ios - 通过 JSON API Objective-C 发送 POST 请求

php - http_post_fields() 无法解析主机名

javascript - 通过http传输大量json

c# tcp 端口扫描器资源

shell - 测试远程 TCP 端口是否从 shell 脚本打开