All locations active · 99.99% uptime
Protocols

Keep-Alive and Connection Pooling in Proxies

The single most effective change you can make to improve proxy performance is not buying a faster proxy; it is reusing the existing connection. A client that opens a new connection for every request pays the connection setup cost over and over, and that cost compounds when it goes through a proxy.

The Real Cost of Establishing a Connection

FIGUREThe stages of the first connection through a proxy
SETUP01DNSresolution~20 msProxy addressfor02TCP handshake~35 msClient ↔ proxy03Proxy authentication~35 ms407 → resendthe request04CONNECTtunnel~35 msTunnel opening05TLS handshake~70 msClient ↔ target06First requestvariableThe actual datatotal fixed cost ~200 ms

These 200 ms are paid again on every new connection. If you send 1,000 requests and open a new connection each time, you spend 200 seconds on setup alone.

How Does Keep-Alive Work?

In HTTP/1.1 connections are persistent by default: the connection is not closed once the response arrives, and the next request is sent over the same socket. Three things break this behaviour:

  • The server sends Connection: close back — the connection is closed.
  • The client creates a new session object for every request — the pool never works.
  • The idle timeout is exceeded — the proxy or the server drops the connection.
The most common mistake

Creating a new Session, Client or Agent object for every request in the code. This completely disables connection reuse, whatever your pool configuration may be.

The Correct Configuration

FIGUREReusing the connection
Pool configuration by language01# Python requests — the Session is created once02import requests03session = requests.Session()04session.proxies = {"https": "http://username:password@proxy.example.com:8080"}05adapter = requests.adapters.HTTPAdapter(pool_connections=16, pool_maxsize=16)06session.mount("https://", adapter)07for url in urls:08 r = session.get(url, timeout=25) # the same connection is reused0910# Python httpx — set the limits explicitly11import httpx12limits = httpx.Limits(max_connections=16, max_keepalive_connections=16,13 keepalive_expiry=60.0)14client = httpx.Client(limits=limits, proxy=PROXY, timeout=25.0)1516# Node.js undici17import { Agent, setGlobalDispatcher } from "undici";18setGlobalDispatcher(new Agent({ connections: 16, keepAliveTimeout: 60_000 }));

Keep the pool size just below your provider's concurrency limit. If you exceed it, extra connections are opened and immediately closed.

How Much Do You Gain?

FIGURETotal time for 1,000 requests
MEASUREMENT061122183244Without a pool (new connection)With a pool (keep-alive)1002505007501000

In the example measurement, using a pool cuts the total time to roughly one third. The gain grows as the latency to the proxy increases.

TLS Session Reuse

Alongside the connection pool there is a second source of gains: the TLS session ticket. When reconnecting to the same target, an abbreviated handshake can be performed instead of a full one. Most modern clients do this automatically; what matters is reusing the client object.

FIGUREFull and abbreviated TLS handshakes
TLSFull handshakeSession reuseRound trips2 RTT1 RTTCertificate transferYesNoneKey computationFullAbbreviatedTypical duration70–140 ms30–60 msConditionFirst connectionSame client object

If you recreate the client object on every request, the session ticket is lost and a full handshake is performed every time.

Balancing the Idle Timeout

Keeping a connection open for too long can cause problems too: the proxy or the target server may silently drop the connection and your client only notices this on the next request. This leads to the "first request fails, second one succeeds" pattern.

SettingRecommendedWhy
keepalive_expiry30–60 sMust be shorter than the server timeout
Pool sizeBelow the concurrency limitAnything more is a wasted handshake
RetryOnceCompensates for a dropped connection
Connection lifetime limit5–10 minLong-lived connections go stale
Practical recommendation

Keep the idle timeout shorter than the server's timeout. That way you are the one closing the connection and the "the server closed it but I do not know" situation never arises.

The Conflict with Rotation

Connection reuse and IP rotation naturally conflict: using the same connection means staying on the same exit IP. This is not a problem but a matter of preference:

FIGUREPool or rotation?
DECISIONIs staying on the same IP a problem?No, a session is requiredYESSet the pool to the maximu…NOSee belowHighest speed gainPartly — it can be the same IP for a whileYESPool + periodic refre…NOSee belowThe balance pointYes, a different IP on every request is essentialYESSwitch the pool offNOAccept the speed cost…

In most scenarios the second option is the right one: reuse the connection for a while (for example 30 requests or 5 minutes), then refresh it.

For rotation strategies, see our article on rotation settings .

Summary

Keep-alive and connection pooling are the single biggest lever in proxy performance. Create the client object once and reuse it, keep the pool size below your provider's limit, set the idle timeout shorter than the server's timeout and add a single retry. If you need rotation, prefer periodic refreshing over switching the pool off. For measurement, ping test and proxy checker tools.

Frequently Asked Questions

01Does keep-alive work over a proxy?

Yes. Once the CONNECT tunnel is established you can send multiple requests through the same tunnel. Persistent connections are supported on plain HTTP proxies as well.

02How should I choose the pool size?

Keep it just below your provider's concurrency limit. If you exceed it, extra connections are opened and immediately closed and the handshake cost goes to waste.

03The first request fails but the following ones work — why?

The connection in the pool may have been silently closed by the server. Keep the idle time shorter than the server's timeout and add a single retry.

04Does a connection pool prevent IP rotation?

Yes, the same connection stays on the same exit IP. If you need rotation, refresh the connection after a certain number of requests or after a certain time instead of switching the pool off entirely.

05What does TLS session reuse gain you?

An abbreviated handshake is performed instead of a full one; it typically saves one round trip and 40–80 ms. All you need to do is reuse the client object.

Related Articles and Pages

NEXT STEP

Strengthen your proxy setup today.

Get started in minutes with a paid plan, or try our free proxy list first.

FREEPROXY.TR

Looking for a free proxy? You're in the right place

A complete proxy platform where you can browse up-to-date free proxy addresses, compare HTTP and SOCKS proxy types, and check your proxy connections with free tools.