Configuration of timeout in httpClient

Recently, some situations have occurred when using solrCloud. When querying, the response of the entire request is very slow due to the slow response speed of some nodes. Our solution is to set a timeout, that is, if some shards have If the response is too slow, simply ignore his response. This involves configuring multiple timeouts of httpClient, so I re-learned the three configurations of HttpClient, got the explanation from the source code, and then made an example to verify the explanation of the source code (the version of httppClient I used is 4.5.2) .

The three timeouts of httpClient are: connectionRequestTimeout, connectionTimeout, socketTimeout. Let’s look at the explanation in the source code first:

1、connectionRequestTimeout

/**
     * Returns the timeout in milliseconds used when requesting a connection
     * from the connection manager. A timeout value of zero is interpreted
     * as an infinite timeout.
     * <p>
     * A timeout value of zero is interpreted as an infinite timeout.
     * A negative value is interpreted as undefined (system default).
     * </p>
     * <p>
     * Default: {@code -1}
     * </p>
     */
    public int getConnectionRequestTimeout() {
        return connectionRequestTimeout;
    }

This means the timeout time of getting a connection from the connection manager, that is, the maximum time to get a connection from the connection pool (the principle of the connection pool has not been studied yet), 0 means there is no limit, if it is -1 means dependency on the platform.

 

2、connectionTimeout

/**
     * Determines the timeout in milliseconds until a connection is established.
     * A timeout value of zero is interpreted as an infinite timeout.
     * <p>
     * A timeout value of zero is interpreted as an infinite timeout.
     * A negative value is interpreted as undefined (system default).
     * </p>
     * <p>
     * Default: {@code -1}
     * </p>
     */
    public int getConnectTimeout() {
        return connectTimeout;
    }

This indicates the maximum time to establish a connection. This is a bit unclear. Didn't the previous connectionRequestTimeout already say that the connection was obtained? Why does it say the time to establish a connection here?

 

3、socketTimeout

    /**
     * Defines the socket timeout ({@code SO_TIMEOUT}) in milliseconds,
     * which is the timeout for waiting for data  or, put differently,
     * a maximum period inactivity between two consecutive data packets).
     * <p>
     * A timeout value of zero is interpreted as an infinite timeout.
     * A negative value is interpreted as undefined (system default).
     * </p>
     * <p>
     * Default: {@code -1}
     * </p>
     */
    public int getSocketTimeout() {
        return socketTimeout;
    }

The maximum time to wait for a packet, this is very simple. 

 

 

 

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326595908&siteId=291194637