4

I am using Entity framework 4.0 in conjunction with REST web service. On the client side, during data/entities loading, client is making 40 sequential web requests.

When I set HttpWebRequest.KeepAlive to false (Fiddler shows Connection: Close headers in client-server communication), data loading is faster about 50% (requests are still sequential) - and I am wondering why.

From Wikipedia: HTTP persistent connection, also called HTTP keep-alive, or HTTP connection reuse, is the idea of using the same TCP connection to send and receive multiple HTTP requests/responses, as opposed to opening a new connection for every single request/response pair.

From MSDN: When the KeepAlive property is true, the application makes persistent connections to the servers that support them. When using HTTP/1.1, Keep-Alive is on/true by default.

What´s wrong? How can I speed up persistent requests?

1

1 Answer 1

1

Maybe on the client the limit for no. of concurrent connections per IP is higher for non-persistent connections than for persistent. So when using keep-alive, client may have allowed you to have 10 conns in parallel, but when not using keep-alive, you can have for example 15 parallel connections.

But this will be faster only on local network where establishing connection is really fast. On internet (RTT of 5-200 ms) you would need 3x RTT time (SYN, SYN+ACK, ACK) only to begin new connection. So especially if you have many small requests (for example images under 1kB), the speed of keep-alive can be 4x faster - because you setup the connection only once and then send 1 packet as request and receive 1 packet as response. But without keepalive, you need 3 packets to begin, then send request, then receive response and then 2 packets to close the connection.

Sign up to request clarification or add additional context in comments.

1 Comment

The triple handshake takes three single trips (A->B, B->A, A->B). A could already send an HTTP request along with the third step, so the request can start after one RTT.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.