The HTTP Connection Pool Service allows a centralized way of managing and reusing http connections for outbound communication.

The connection pool service uses the concept of named pools. A named pool has a number of configuration options on it that describe how a connection from that pool should behave. Connections from a pool are reused to cut down on the overhead of connection negotiation when resources are frequently accessed. The id/name of the pool corresponds to the connection pool id found in other service’s and filter’s configurations, indicating that outbound connections from that component should use the matching pool.

Configuration

  • Default Configuration: http-connection-pool.cfg.xml

  • Released: v2.8.3

  • Schema

Full Configuration

http-connection-pool.cfg.xml
<http-connection-pools xmlns="http://docs.openrepose.org/repose/http-connection-pool/v1.0">
    <pool id="default" (1)
          default="true" (2)
          chunked-encoding="true" (3)
          http.conn-manager.max-total="400" (4)
          http.conn-manager.max-per-route="200" (5)
          http.socket.timeout="30000" (6)
          http.socket.buffer-size="8192" (7)
          http.connection.timeout="30000" (8)
          http.connection.max-line-length="8192" (9)
          http.connection.max-header-count="100" (10)
          http.connection.max-status-line-garbage="100" (11)
          http.tcp.nodelay="true" (12)
          keepalive.timeout="0" (13)
          keystore-filename="client.jks" (14)
          keystore-password="password" (15)
          key-password="password" (16)
          truststore-filename="servers.jks" (17)
          truststore-password="password"> (18)
        <headers> (19)
            <header name="foo" value="bar"/> (20)
        </headers>
    </pool>
    <pool id="banana"/> (21)
</http-connection-pools>
1 The id/name of this pool, it must be unique. Used to identify this pool for usage by other services/filters. The only required attribute for a pool.
2 Whether or not this pool is the default pool for the connection service. You must have exactly one pool marked as the default. This pool is the one that will be used to make connections to the origin service.
3 Determines whether or not this client should send chunked data when forwarding requests to the origin service. If set to true, chunked data will always be sent. If set to false, chunked data will never be sent. If set to auto, chunked data will only be sent if the original request to Repose was chunked. Note that the auto setting only has meaning for the default connection pool, as that is the only pool that will be used to make requests to the origin service.
WARNING: Setting this attribute to false may cause Repose to attempt to retrieve the actual content length through reading the ServletInputStream. This will cause some performance degradation as request body is no longer always streamed through.
It is recommended that users leave this value as true unless their service does not support chunked encoding.
Default: true
4 Maximum number of connections opened across all endpoints in this connection pool. If this is set too high, you may run out of memory.
Default: 400
5 Maximum number of connections opened per endpoint in this connection pool.
Default: 200
6 Defines the socket timeout in milliseconds, which is the timeout for waiting for data (or, put differently, a maximum period of inactivity between two consecutive data packets). A timeout value of zero is interpreted as an infinite timeout.
Default: 30000
7 Determines the size of the internal socket buffer used to buffer data while receiving / transmitting HTTP messages.
Default: 8192
8 Determines the timeout in milliseconds until a connection is established. A timeout value of zero is interpreted as an infinite timeout. Please note this parameter can only be applied to connections that are bound to a particular local address.
Default: 30000
9 Determines the maximum line length limit. If set to a positive value, any HTTP line exceeding this limit will cause an IOException. A negative or zero value will effectively disable the check.
Default: 8192
10 Determines the maximum HTTP header count allowed. If set to a positive value, the number of HTTP headers received from the data stream exceeding this limit will cause an IOException. A negative or zero value will effectively disable the check.
Default: 100
11 Maximum number of lines allotted for garbage.
Default: 100
12 Determines whether Nagle’s algorithm is to be used. The Nagle’s algorithm tries to conserve bandwidth by minimizing the number of segments that are sent. When applications wish to decrease network latency and increase performance, they can disable Nagle’s algorithm (that is enable http.tcp.nodelay). Data will be sent earlier, at the cost of an increase in bandwidth consumption.
Default: true
13 If a Keep-Alive header is not present in the response, the value of keepalive.timeout is evaluated. If this value is 0, the connection will be kept alive indefinitely. If the value is greater than 0, the connection will be kept alive for the number of milliseconds specified. Set to 1 to connect:close.
Default: 0
14 The keystore filename either fully qualified or relative to the Repose configuration directory. Used for SSL/TLS Client Authentication.
NOTE: The keystore-filename, keystore-password, and key-password are all mutually required. If one exists, then they all must exist and client authentication is assumed to be required.
15 The password to access the keystore.
NOTE: The keystore-filename, keystore-password, and key-password are all mutually required. If one exists, then they all must exist and client authentication is assumed to be required.
16 The password for the particular key within the keystore.
NOTE: The keystore-filename, keystore-password, and key-password are all mutually required. If one exists, then they all must exist and client authentication is assumed to be required.
17 The truststore filename either fully qualified or relative to the Repose configuration directory. Used when it is necessary to have the certificate of the requested resource’s server.
NOTE: The truststore-filename and truststore-password are mutually required. If one exists, then the other must exist.
18 The password to access the truststore.
NOTE: The truststore-filename and truststore-password are mutually required. If one exists, then the other must exist.
19 Indicates that the configured list of headers should be added to every outbound request on this connection pool. Use is optional.
20 A header to be added to every outbound request from this connection pool. At least on is required when using the optional headers element.
21 A second pool is defined here that uses all the defaults.

Common Use Cases/Problems

Origin Service doesn’t support chunked encoding (e.g., WSGI)

If the origin service doesn’t support chunked encoding, it can be turned off easily. Add or update the chunked-encoding attribute for your default pool to false.

partial http-connection-pool.cfg
<pool id="default"
      default="true" (1)
      ... (2)
      chunked-encoding="false"/> (3)
</pool>
1 Be sure it’s the default pool being updated.
2 Here are the rest of the pool attributes.
3 Add chunked-encoding if not already present and set it to false.

This can be done for any other pool as well, if it’s known that it will be used to communicate to a service that doesn’t support chunked encoding.

Need higher concurrency

If the connection pool is filling up, but more resources are available on the machine Repose is running on, the pool can be expanded to allow more concurrent connections. This is most useful if wait times are high or requests are timing out. The size of the pools can be increased by raising http.conn-manager.max-total and http.conn-manager.max-per-route.

partial http-connection-pool.cfg
<pool id="default"
      ... (1)
      http.conn-manager.max-total="800" (2)
      http.conn-manager.max-per-route="300"/> (3)
</pool>
1 The existing pool attributes.
2 The new overall pool size. This is the maximum number of connections this pool will have open at once.
3 The new max number of connections to a single endpoint. If a pool is only ever used for a single endpoint (e.g., foo.com), then this number and http.conn-manager.max-total should be the same. If they aren’t then the max pool size will never be reached.

Requested endpoint requires a static header

Some services require a static header be present just for the purposes of identification; this can easily be done by adding the headers element to the pool configuration.

http-connection-pool.cfg.xml
<http-connection-pools xmlns="http://docs.openrepose.org/repose/http-connection-pool/v1.0">
    <pool id="default">
        <headers> (1)
            <header name="foo" value="bar"/> (2)
        </headers>
    </pool>
</http-connection-pools>
1 The element to add to the pool configuration to trigger this behavior.
2 The header name and value to add to the outbound request. Multiple header elements can be specified if more than one is desired.

SSL/TLS Client Authentication

Further Information

For more information about the http.* attributes or the underlying connection pool see Apache Connection Management.