httpClient发送数据的速度很慢

时间:2018-04-16 04:03:03

标签: tcp httpclient tcpdump

我使用java HttpClient 4.3.5发送文件,我使用此配置创建HttpClient     

SocketConfig soConfig = SocketConfig.custom()
            .setTcpNoDelay(true)
            .build();
    int socketSendBufferSizeHint = config.getSocketSendBufferSizeHint();
    int socketReceiveBufferSizeHint = config.getSocketReceiveBufferSizeHint();
    int buffersize = 0;
    if (socketSendBufferSizeHint > 0 || socketReceiveBufferSizeHint > 0) {
        buffersize = Math.max(socketSendBufferSizeHint, socketReceiveBufferSizeHint);
    }
    ConnectionConfig coConfig = ConnectionConfig.custom()
            .setBufferSize(buffersize)
            .build();
    RequestConfig reConfig = RequestConfig.custom()
            .setConnectTimeout(config.getConnectionTimeOut())
            .setSocketTimeout(config.getSocketTimeOut())
            .setStaleConnectionCheckEnabled(true)
            .build();       

并使用PoolingHttpClientConnectionManager连接管理器, 当我使用response = client.execute(httpRequest);发送http请求时。但客户端发送数据1MB数据可能需要每个请求720毫秒。在正常情况下,只需要75ms,我使用tcpdump获取下面的数据。我不明白为什么java http客户端发送数据比python慢​​。任何帮助,谢谢。

```

22:20:13.800409 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [.], seq 2566415:2575079, ack 733, win 1452, length 8664
22:20:13.800427 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [.], seq 2575079:2582299, ack 733, win 1452, length 7220
22:20:13.800673 IP 198.18.96.40.https > tj1-smart-camera-mt00.kscn.24759: Flags [.], ack 2569303, win 6137, length 0
22:20:13.800678 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [P.], seq 2582299:2582828, ack 733, win 1452, length 529
22:20:13.800797 IP 198.18.96.40.https > tj1-smart-camera-mt00.kscn.24759: Flags [.], ack 2582299, win 6123, length 0
22:20:13.809401 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [.], seq 2582828:2590048, ack 733, win 1452, length 7220
22:20:13.809411 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [.], seq 2590048:2597268, ack 733, win 1452, length 7220
22:20:13.809665 IP 198.18.96.40.https > tj1-smart-camera-mt00.kscn.24759: Flags [.], ack 2585716, win 6137, length 0
22:20:13.809673 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [P.], seq 2597268:2599241, ack 733, win 1452, length 1973
22:20:13.809790 IP 198.18.96.40.https > tj1-smart-camera-mt00.kscn.24759: Flags [.], ack 2597268, win 6137, length 0
22:20:13.809920 IP 198.18.96.40.https > tj1-smart-camera-mt00.kscn.24759: Flags [.], ack 2599241, win 6137, length 0
22:20:13.818367 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [.], seq 2599241:2606461, ack 733, win 1452, length 7220
22:20:13.818376 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [.], seq 2606461:2613681, ack 733, win 1452, length 7220
22:20:13.818385 IP tj1-smart-camera-mt00.kscn.24759 > 198.18.96.40.https: Flags [P.], seq 2613681:2615654, ack 733, win 1452, length 1973
22:20:13.818639 IP 198.18.96.40.https > tj1-smart-camera-mt00.kscn.24759: Flags [.], ack 2602129, win 6137, length 0
22:20:13.822745 IP 198.18.96.40.https > tj1-smart-camera-mt00.kscn.24759: Flags [.], ack 2615654, win 6137, length 0

```

0 个答案:

没有答案