Apache HttpClient在高请求/秒下随机延迟 [英] Apache HttpClient random delays under high requests/second

查看:808
本文介绍了Apache HttpClient在高请求/秒下随机延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Apache HttpClient在localhost上查询HTTP / 1.0(不保留)服务器,每秒约有20个POST请求。我有一个TCP_NODELAY启用如下:

I'm using Apache HttpClient to query HTTP/1.0 (without keep alive) server on localhost with around 20 POST requests/second. I have a TCP_NODELAY enabled like this:


val httpParams = new BasicHttpParams()
HttpConnectionParams.setTcpNoDelay(httpParams, true)
val client = new DefaultHttpClient(connectionManager, httpParams)

尽管如此,我每分钟几次看到发送此类请求的随机延迟10-200毫秒(在服务器上显示测量,该延迟在发送中)。我检查过,这不是垃圾收集器暂停。可能是什么问题?

Despite that, several times per minute I see a random delay of 10-200 milliseconds for sending such request (measuring on the server shows, that delay is in sending). I checked, that it's not a garbage collector pause. What can be the problem?

我试图用相同的速率查询服务器与C ++客户端,并且它没有这样的随机延迟,所以我认为它是HttpClient问题。

I tried to query the server with C++ client with the same rate, and it doesn't have such random delays, so i think it's HttpClient problem.

更新:
我检查了jetty HttpClient实现,它有同样的问题。这可能是FreeBSD上JVM的一些问题吗?我应该在linux上测试一下,但我手头没有linux服务器。

Update: I checked jetty HttpClient implementation, and it has the same problem. Can this be some problem of JVM on FreeBSD? I should test this on linux, but I don't have a linux server at hand.

推荐答案

我在这里遇到同样的问题使用Windows。
就我而言,HttpClient引入了大约1秒的延迟,但只是在第一次尝试执行帖子时(我按顺序执行了几次)。我尝试了一种解决方法,即为本地主机创建一个假帖子并执行它(除了IOException)。通过这样做,我在调用实际服务时的延迟从大约1秒减少到大约100毫秒。
我还没有比这更好的改进。

I have the same problem here using windows. In my case, HttpClient was introducing around 1 second of delay but just at the first attempt to execute a post (I do several in sequence). I try a workaround that was to create a "fake" post to the local host and execute it (and except an IOException). By doing that, my delay when calling real services was reduce from around 1 second to around 100ms. I could not improve more than that yet.

这篇关于Apache HttpClient在高请求/秒下随机延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆