Connection Pooling
This article is part of a series that I have started working on. In this series, I’ll be briefly discussing engineering concepts.
1/n
What
Connection pooling is re-using a bunch of connections instead of creating a new connection for every request.
Why
- TCP connections are costly → Creating a TCP connection requires a 3-way handshake. It takes time and resources to create one.
- TLS → With HTTPS there is an overhead of TLS handshake.
Demo
Let’s see what happens when we use the same connection for multiple requests.
These requests need to be to the same domain
Run the following command
curl https://github.com/404 https://github.com/404 -o /dev/null -w '\nEstablish Connection time %{time_connect} total time %{time_total}\n'
As you can see the 1st request involves TLS termination but the 2nd request completely skips it since it is using the same connection.
Also, the time take to establish a connection is very less for the 2nd request as compared to the 1st one.