当前位置: 首页 > 知识库问答 >
问题:

Apache Http客户端比浏览器慢

张永嘉
2023-03-14

免责声明:我知道这个问题有重复(一、二、三),但是:

    null

我的代码:

RequestConfig requestConfig = RequestConfig.custom()
        .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
        .setSocketTimeout(60000)
        .setConnectTimeout(5000)
        .setConnectionRequestTimeout(5000)
        .build();
SocketConfig socketConfig = SocketConfig.custom()
        .setSoKeepAlive(false) //true - no differences in request time
        .setTcpNoDelay(true)
        .build();
PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager();
connManager.setMaxTotal(50);
connManager.setDefaultMaxPerRoute(2);

CloseableHttpClient httpClient = HttpClients.custom()
        .setDefaultSocketConfig(socketConfig)
        .setConnectionManager(connManager)
        .setDefaultRequestConfig(requestConfig)
        .setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36")
        .build();

//1
long t11 = System.currentTimeMillis();
try(CloseableHttpResponse response1 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
    code1 = response1.getStatusLine().getStatusCode();
}
long t12 = System.currentTimeMillis();
long reqTime1 = t12 - t11;
//2
long t21 = System.currentTimeMillis();
try(CloseableHttpResponse response2 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
    code2 = response2.getStatusLine().getStatusCode();
}
long t22 = System.currentTimeMillis();
long reqTime2 = t22 - t21;
//3
long t31 = System.currentTimeMillis();
try(CloseableHttpResponse response3 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
    code3 = response3.getStatusLine().getStatusCode();
}
long t32 = System.currentTimeMillis();
long reqTime3 = t32 - t31;

log.trace("reqTime1: {}", reqTime1);
log.trace("reqTime2: {}", reqTime2);
log.trace("reqTime3: {}", reqTime3);

这将打印:

reqTime1: 198 
reqTime2: 168 
reqTime3: 160

(所有3个请求返回200个http代码)

我有JVM选项:

-Djavax.net.ssl.keyStore=/path/to/my/keyStore.jks
-Djavax.net.ssl.keyStorePassword=my_password
-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog
-Dorg.apache.commons.logging.simplelog.showdatetime=true
-Dorg.apache.commons.logging.simplelog.log.org.apache.http=DEBUG
-Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=ERROR

(在我的keystore.jks中添加了vk.com证书)

下面是http-client的内部日志

[err] 2016/11/11 14:54:35:411 MSK [DEBUG] RequestAddCookies - CookieSpec selected: ignoreCookies
[err] 2016/11/11 14:54:35:412 MSK [DEBUG] RequestAuthCache - Auth cache not set in the context
[err] 2016/11/11 14:54:35:413 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:413 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 6][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 50]
[err] 2016/11/11 14:54:35:413 MSK [DEBUG] MainClientExec - Opening connection {s}->https://api.vk.com:443
[err] 2016/11/11 14:54:35:414 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connecting to api.vk.com/87.240.165.75:443
[err] 2016/11/11 14:54:35:414 MSK [DEBUG] SSLConnectionSocketFactory - Connecting socket to api.vk.com/87.240.165.75:443 with timeout 5000
[err] 2016/11/11 14:54:35:494 MSK [DEBUG] SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
[err] 2016/11/11 14:54:35:495 MSK [DEBUG] SSLConnectionSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
[err] 2016/11/11 14:54:35:495 MSK [DEBUG] SSLConnectionSocketFactory - Starting handshake
[err] 2016/11/11 14:54:35:641 MSK [DEBUG] SSLConnectionSocketFactory - Secure session established
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory -  negotiated protocol: TLSv1.2
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory -  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory -  peer principal: CN=*.vk.com, OU=Domain Control Validated
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory -  peer alternative names: [*.vk.com, vk.com]
[err] 2016/11/11 14:54:35:642 MSK [DEBUG] SSLConnectionSocketFactory -  issuer principal: CN=Go Daddy Secure Certificate Authority - G2, OU=http://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connection established 172.20.10.2:55317<->87.240.165.75:443
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-6: set socket timeout to 60000
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] MainClientExec - Executing request GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:643 MSK [DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] headers - http-outgoing-6 >> GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] headers - http-outgoing-6 >> Host: api.vk.com
[err] 2016/11/11 14:54:35:644 MSK [DEBUG] headers - http-outgoing-6 >> Connection: Keep-Alive
[err] 2016/11/11 14:54:35:645 MSK [DEBUG] headers - http-outgoing-6 >> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
[err] 2016/11/11 14:54:35:645 MSK [DEBUG] headers - http-outgoing-6 >> Accept-Encoding: gzip,deflate
[err] 2016/11/11 14:54:35:725 MSK [DEBUG] headers - http-outgoing-6 << HTTP/1.1 200 OK
[err] 2016/11/11 14:54:35:725 MSK [DEBUG] headers - http-outgoing-6 << Server: Apache
[err] 2016/11/11 14:54:35:726 MSK [DEBUG] headers - http-outgoing-6 << Date: Fri, 11 Nov 2016 11:54:35 GMT
[err] 2016/11/11 14:54:35:726 MSK [DEBUG] headers - http-outgoing-6 << Content-Type: application/json; charset=utf-8
[err] 2016/11/11 14:54:35:726 MSK [DEBUG] headers - http-outgoing-6 << Content-Length: 286
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << Connection: keep-alive
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << X-Powered-By: PHP/3.7212
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << Set-Cookie: remixlang=0; expires=Sun, 05 Nov 2017 18:31:29 GMT; path=/; domain=.vk.com
[err] 2016/11/11 14:54:35:727 MSK [DEBUG] headers - http-outgoing-6 << Pragma: no-cache
[err] 2016/11/11 14:54:35:728 MSK [DEBUG] headers - http-outgoing-6 << Cache-control: no-store
[err] 2016/11/11 14:54:35:728 MSK [DEBUG] headers - http-outgoing-6 << Content-Encoding: gzip
[err] 2016/11/11 14:54:35:728 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:35:729 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-6: Close connection
[err] 2016/11/11 14:54:35:730 MSK [DEBUG] MainClientExec - Connection discarded
[err] 2016/11/11 14:54:35:730 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 6][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:730 MSK [DEBUG] RequestAddCookies - CookieSpec selected: ignoreCookies
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] RequestAuthCache - Auth cache not set in the context
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 7][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 50]
[err] 2016/11/11 14:54:35:731 MSK [DEBUG] MainClientExec - Opening connection {s}->https://api.vk.com:443
[err] 2016/11/11 14:54:35:732 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connecting to api.vk.com/87.240.165.75:443
[err] 2016/11/11 14:54:35:732 MSK [DEBUG] SSLConnectionSocketFactory - Connecting socket to api.vk.com/87.240.165.75:443 with timeout 5000
[err] 2016/11/11 14:54:35:786 MSK [DEBUG] SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
[err] 2016/11/11 14:54:35:787 MSK [DEBUG] SSLConnectionSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
[err] 2016/11/11 14:54:35:787 MSK [DEBUG] SSLConnectionSocketFactory - Starting handshake
[err] 2016/11/11 14:54:35:909 MSK [DEBUG] SSLConnectionSocketFactory - Secure session established
[err] 2016/11/11 14:54:35:910 MSK [DEBUG] SSLConnectionSocketFactory -  negotiated protocol: TLSv1.2
[err] 2016/11/11 14:54:35:910 MSK [DEBUG] SSLConnectionSocketFactory -  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
[err] 2016/11/11 14:54:35:910 MSK [DEBUG] SSLConnectionSocketFactory -  peer principal: CN=*.vk.com, OU=Domain Control Validated
[err] 2016/11/11 14:54:35:911 MSK [DEBUG] SSLConnectionSocketFactory -  peer alternative names: [*.vk.com, vk.com]
[err] 2016/11/11 14:54:35:911 MSK [DEBUG] SSLConnectionSocketFactory -  issuer principal: CN=Go Daddy Secure Certificate Authority - G2, OU=http://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US
[err] 2016/11/11 14:54:35:911 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connection established 172.20.10.2:55318<->87.240.165.75:443
[err] 2016/11/11 14:54:35:912 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-7: set socket timeout to 60000
[err] 2016/11/11 14:54:35:912 MSK [DEBUG] MainClientExec - Executing request GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:912 MSK [DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] headers - http-outgoing-7 >> GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] headers - http-outgoing-7 >> Host: api.vk.com
[err] 2016/11/11 14:54:35:913 MSK [DEBUG] headers - http-outgoing-7 >> Connection: Keep-Alive
[err] 2016/11/11 14:54:35:914 MSK [DEBUG] headers - http-outgoing-7 >> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
[err] 2016/11/11 14:54:35:914 MSK [DEBUG] headers - http-outgoing-7 >> Accept-Encoding: gzip,deflate
[err] 2016/11/11 14:54:35:989 MSK [DEBUG] headers - http-outgoing-7 << HTTP/1.1 200 OK
[err] 2016/11/11 14:54:35:989 MSK [DEBUG] headers - http-outgoing-7 << Server: Apache
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Date: Fri, 11 Nov 2016 11:54:35 GMT
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Content-Type: application/json; charset=utf-8
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Content-Length: 286
[err] 2016/11/11 14:54:35:990 MSK [DEBUG] headers - http-outgoing-7 << Connection: keep-alive
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << X-Powered-By: PHP/3.7212
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << Set-Cookie: remixlang=0; expires=Wed, 08 Nov 2017 21:16:16 GMT; path=/; domain=.vk.com
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << Pragma: no-cache
[err] 2016/11/11 14:54:35:991 MSK [DEBUG] headers - http-outgoing-7 << Cache-control: no-store
[err] 2016/11/11 14:54:35:992 MSK [DEBUG] headers - http-outgoing-7 << Content-Encoding: gzip
[err] 2016/11/11 14:54:35:992 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:35:992 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-7: Close connection
[err] 2016/11/11 14:54:35:993 MSK [DEBUG] MainClientExec - Connection discarded
[err] 2016/11/11 14:54:35:993 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 7][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:994 MSK [DEBUG] RequestAddCookies - CookieSpec selected: ignoreCookies
[err] 2016/11/11 14:54:35:994 MSK [DEBUG] RequestAuthCache - Auth cache not set in the context
[err] 2016/11/11 14:54:35:994 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection request: [route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[err] 2016/11/11 14:54:35:995 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection leased: [id: 8][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 50]
[err] 2016/11/11 14:54:35:995 MSK [DEBUG] MainClientExec - Opening connection {s}->https://api.vk.com:443
[err] 2016/11/11 14:54:35:996 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connecting to api.vk.com/87.240.165.75:443
[err] 2016/11/11 14:54:35:996 MSK [DEBUG] SSLConnectionSocketFactory - Connecting socket to api.vk.com/87.240.165.75:443 with timeout 5000
[err] 2016/11/11 14:54:36:050 MSK [DEBUG] SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
[err] 2016/11/11 14:54:36:050 MSK [DEBUG] SSLConnectionSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]
[err] 2016/11/11 14:54:36:050 MSK [DEBUG] SSLConnectionSocketFactory - Starting handshake
[err] 2016/11/11 14:54:36:117 MSK [DEBUG] SSLConnectionSocketFactory - Secure session established
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory -  negotiated protocol: TLSv1.2
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory -  negotiated cipher suite: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory -  peer principal: CN=*.vk.com, OU=Domain Control Validated
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory -  peer alternative names: [*.vk.com, vk.com]
[err] 2016/11/11 14:54:36:118 MSK [DEBUG] SSLConnectionSocketFactory -  issuer principal: CN=Go Daddy Secure Certificate Authority - G2, OU=http://certs.godaddy.com/repository/, O="GoDaddy.com, Inc.", L=Scottsdale, ST=Arizona, C=US
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] DefaultHttpClientConnectionOperator - Connection established 172.20.10.2:55331<->87.240.165.75:443
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-8: set socket timeout to 60000
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] MainClientExec - Executing request GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] MainClientExec - Target auth state: UNCHALLENGED
[err] 2016/11/11 14:54:36:119 MSK [DEBUG] MainClientExec - Proxy auth state: UNCHALLENGED
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> GET /method/database.getCountries HTTP/1.1
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> Host: api.vk.com
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> Connection: Keep-Alive
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36
[err] 2016/11/11 14:54:36:120 MSK [DEBUG] headers - http-outgoing-8 >> Accept-Encoding: gzip,deflate
[err] 2016/11/11 14:54:36:188 MSK [DEBUG] headers - http-outgoing-8 << HTTP/1.1 200 OK
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Server: Apache
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Date: Fri, 11 Nov 2016 11:54:36 GMT
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Content-Type: application/json; charset=utf-8
[err] 2016/11/11 14:54:36:189 MSK [DEBUG] headers - http-outgoing-8 << Content-Length: 286
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Connection: keep-alive
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << X-Powered-By: PHP/3.7212
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Set-Cookie: remixlang=0; expires=Thu, 16 Nov 2017 00:20:15 GMT; path=/; domain=.vk.com
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Pragma: no-cache
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Cache-control: no-store
[err] 2016/11/11 14:54:36:190 MSK [DEBUG] headers - http-outgoing-8 << Content-Encoding: gzip
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-8: Close connection
[err] 2016/11/11 14:54:36:192 MSK [DEBUG] MainClientExec - Connection discarded
[err] 2016/11/11 14:54:36:192 MSK [DEBUG] PoolingHttpClientConnectionManager - Connection released: [id: 8][route: {s}->https://api.vk.com:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 50]
[14:54:36.193] TRACE [proliker.utils.TestService.hc(TestService.java:300)]: reqTime1:    319 
[14:54:36.193] TRACE [proliker.utils.TestService.hc(TestService.java:301)]: reqTime2:    264 
[14:54:36.194] TRACE [proliker.utils.TestService.hc(TestService.java:302)]: reqTime3:    198 

当然,上面的测试是在关闭内部日志记录的情况下执行的,因为它会给每个请求增加大约50毫秒的额外时间。

我已经读了三遍所有的apache http-client站点文档,我不知道该去哪里看,哪里有错误。我非常希望一些极客能帮助我提高请求速度。

共有1个答案

柳昊焱
2023-03-14
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] MainClientExec - Connection can be kept alive indefinitely
[err] 2016/11/11 14:54:36:191 MSK [DEBUG] DefaultManagedHttpClientConnection - http-outgoing-8: Close connection
[err] 2016/11/11 14:54:36:192 MSK [DEBUG] MainClientExec - Connection discarded

如果这不是有意的,那么使HttpClient更快的最简单方法是重用连接(尤其是在使用SSL/TLS传输安全性时)。

始终确保响应内容已被完全使用(通过从内容流读取直到流结束或关闭流)。

try(CloseableHttpResponse response1 = httpClient.execute(new HttpGet("https://api.vk.com/method/database.getCountries"))) {
    int code1 = response1.getStatusLine().getStatusCode();
    EntityUtils.consume(response1.getEntity());
}
 类似资料:
  • 一面-2023年5月6日 ios客户端,大前端、object-c 自我介绍。有点背稿的感觉。 聊一个项目。说了OSG的项目。提到内存管理。 开始八股。内存:只能指针。 多态,静态、动态。模板、虚函数。静态的除了模板还有啥。析构函数为什么要添加虚函数。 空类size的大小。 struct/class的区别。 堆/栈/BSS几个内存类别 TCP四次挥手。 ipv4地址空间这么小怎么够用,NAT。用同一

  • 二面-2023年5月8日 第一次迟到了面试.. 自我介绍。刚开始没准备各种结巴,语言不顺。整体还是讲完了。 项目。疯狂问项目、但是又不是挖,就是让自己讲。讲了好几个项目。看起来不是特别满意。一个是我自己准备项目拿普通横向项目准备的亮点肯定不够不到位,另外岗位是客户端,没有什么相关的。 岗位匹配度上,问了好几遍和原技术栈不匹配,自己的个人想法。(一开始也是你捞的我,我有啥想法 手撕算法。快排。这两面

  • 问题内容: 是否有从客户端浏览器获取时区的可靠方法?我看到了以下链接,但我想要一个更强大的解决方案。 使用JavaScript自动检测时区 JavaScript中的时区检测 问题答案: 查看此存储库pageloom很有帮助 下载jstz.min.js并将功能添加到您的html页面 然后从您的显示代码调用此函数

  • 我有一个在生产中工作的密钥斗篷,我需要我的用户登录到一个使用react native开发的移动应用程序,使用该密钥斗篷。到目前为止,我使用的正常登录流程通过应用内浏览器作为AppAtuh,但现在我收到了一个用户的请求,说在应用程序,同时登录。 > 我使移动登录的Keycloak主题对移动应用程序UI进行了如此多的加密,以至于可以将其作为普通屏幕使用react WebView打开。 其次,这种思想适

  • 4.7 30min中午收到的下午面试很离谱 面试官上来自我介绍,主要是QQ浏览器的pc和mac开发,说主要拷打计算机基础,当时就感觉寄,感觉铁定不问cpp,然后果然没问,一顿八股之后,写个算法题,下来秒挂,虽然我八股确实很垃圾 tcp和udp的区别 tcp如何实现可靠传输的 http的断点传输  寄 虚拟内存的定义 虚拟内存的作用 除了扩大逻辑内存,进程隔离还有什么作用 寄 进程和线程的区别 进程

  • 我读了很多文章来寻找java应用程序的最佳Rest客户机,最后我发现将Jersey与ApacheHTTP客户机4.5结合使用非常好,但在很多文章中,我发现现在改型是最好的(我没有提到Volley,因为在我的例子中,我不需要API支持缓存)。 对于java客户机应用程序,改型是否更好。还是对Android来说更好?为什么我以前没有找到这个比较。。它们无法比较? 我可以比较一下它们的性能、连接池、它们