Http persistent connections

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Http persistent connections

Jimmie Houchin-5

Hello,

I am writing an app which accesses a REST api. The documentation says this.

Connection Limits

To provide equal resources to all clients, we recommend limiting both the number of new connections per second, and the number of requests per second made on a persistent connection (see above/below).

For new connections, we recommend you limit this to twice per second (2/s). Establishing a new TCP and SSL connection is expensive for both client and server. To allow a better experience, using a persistent connection will allow more requests to be performed on an established connection.

For an established connection, we recommend limiting this to one hundred per second (100/s). Please see following section on persistent connections to learn how to maintain a connection once it is established.

HTTP Persistent Connection

This keeps the underlying TCP connection active for multiple requests/responses. Subsequent requests will result in reduced latency as the TCP handshaking process is no longer required.

If you are using an HTTP 1.0 client, ensure it supports the keep-alive directive and submit the header Connection: Keep-Alive with your request.

Keep-Alive is part of the protocol in HTTP 1.1 and enabled by default on compliant clients. However, you will have to ensure your implementation does not set the connection header to other values.


I do not know how to reuse a connection.

I see in ZnClient #canReuseConnection and #connectionReuseTimeout.

Is the timeout from connection time or last request or access time?

Does that handle everything automatically for me?

I will be accessing this api multiple times a minute, sometimes multiple times a second for almost all the time.

How long can I keep a persistent connection open?

What are best practices?

Any help and wisdom greatly appreciated.

Thanks.

Jimmie




Reply | Threaded
Open this post in threaded view
|

Re: Http persistent connections

Sven Van Caekenberghe-2
Hi Jimmie,

> On 31 Oct 2018, at 14:01, Jimmie Houchin <[hidden email]> wrote:
>
> Hello,
>
> I am writing an app which accesses a REST api. The documentation says this.
>
> Connection Limits
>
> To provide equal resources to all clients, we recommend limiting both the number of new connections per second, and the number of requests per second made on a persistent connection (see above/below).
>
> For new connections, we recommend you limit this to twice per second (2/s). Establishing a new TCP and SSL connection is expensive for both client and server. To allow a better experience, using a persistent connection will allow more requests to be performed on an established connection.
>
> For an established connection, we recommend limiting this to one hundred per second (100/s). Please see following section on       persistent connections to learn how to maintain a connection once it is established.
>
> HTTP Persistent Connection
>
> This keeps the underlying TCP connection active for multiple requests/responses. Subsequent requests will result in reduced latency as the TCP handshaking process is no longer required.
>
> If you are using an HTTP 1.0 client, ensure it supports the keep-alive directive and submit the header Connection: Keep-Alive with your request.
>
> Keep-Alive is part of the protocol in HTTP 1.1 and enabled by default on compliant clients. However, you will have to ensure       your implementation does not set the connection header to other values.
>
>
>
> I do not know how to reuse a connection.
>
> I see in ZnClient #canReuseConnection and #connectionReuseTimeout.
>
> Is the timeout from connection time or last request or access time?
>
> Does that handle everything automatically for me?
>
> I will be accessing this api multiple times a minute, sometimes multiple times a second for almost all the time.
>
> How long can I keep a persistent connection open?
>
> What are best practices?
>
> Any help and wisdom greatly appreciated.
>
> Thanks.
>
> Jimmie

Yes, Zn fully and automagically supports persistent connections.

In a first approach, just create one ZnClient instance, configure it with your host, etc, and then keep on reusing this instance for each (subsequent) request. Zn will keep client side connections open indefinitely. But a (busy) server will kill idle connections for sure. ZnClient will always try to connect again, before giving an error, so it effectively reconnects.

You can look at client side logging by inspecting

  ZnLogEvent announcer

to figure out what is happening.

One warning though: if your app is multi user / multi threaded, you will probably need an http client instance per session. It is possibly necessary to prevent mixing up authentication info as well.

HTH,

Sven
 


Reply | Threaded
Open this post in threaded view
|

Re: Http persistent connections

Jimmie Houchin-5
On 10/31/18 8:16 AM, Sven Van Caekenberghe wrote:

> Hi Jimmie,
>
>> On 31 Oct 2018, at 14:01, Jimmie Houchin <[hidden email]> wrote:
>>
>> Hello,
>>
>> I am writing an app which accesses a REST api. The documentation says this.
>>
>> Connection Limits
>>
>> To provide equal resources to all clients, we recommend limiting both the number of new connections per second, and the number of requests per second made on a persistent connection (see above/below).
>>
>> For new connections, we recommend you limit this to twice per second (2/s). Establishing a new TCP and SSL connection is expensive for both client and server. To allow a better experience, using a persistent connection will allow more requests to be performed on an established connection.
>>
>> For an established connection, we recommend limiting this to one hundred per second (100/s). Please see following section on       persistent connections to learn how to maintain a connection once it is established.
>>
>> HTTP Persistent Connection
>>
>> This keeps the underlying TCP connection active for multiple requests/responses. Subsequent requests will result in reduced latency as the TCP handshaking process is no longer required.
>>
>> If you are using an HTTP 1.0 client, ensure it supports the keep-alive directive and submit the header Connection: Keep-Alive with your request.
>>
>> Keep-Alive is part of the protocol in HTTP 1.1 and enabled by default on compliant clients. However, you will have to ensure       your implementation does not set the connection header to other values.
>>
>>
>>
>> I do not know how to reuse a connection.
>>
>> I see in ZnClient #canReuseConnection and #connectionReuseTimeout.
>>
>> Is the timeout from connection time or last request or access time?
>>
>> Does that handle everything automatically for me?
>>
>> I will be accessing this api multiple times a minute, sometimes multiple times a second for almost all the time.
>>
>> How long can I keep a persistent connection open?
>>
>> What are best practices?
>>
>> Any help and wisdom greatly appreciated.
>>
>> Thanks.
>>
>> Jimmie
> Yes, Zn fully and automagically supports persistent connections.
>
> In a first approach, just create one ZnClient instance, configure it with your host, etc, and then keep on reusing this instance for each (subsequent) request. Zn will keep client side connections open indefinitely. But a (busy) server will kill idle connections for sure. ZnClient will always try to connect again, before giving an error, so it effectively reconnects.
>
> You can look at client side logging by inspecting
>
>    ZnLogEvent announcer
>
> to figure out what is happening.
>
> One warning though: if your app is multi user / multi threaded, you will probably need an http client instance per session. It is possibly necessary to prevent mixing up authentication info as well.
>
> HTH,
>
> Sven

Thanks Sven. I thought that would be how it worked.

You write beautiful software. I love to try to learn from what you write.

Thanks for the pointer.

Jimmie