-
Notifications
You must be signed in to change notification settings - Fork 0
fix(proxy): reduce SSL connection overhead by setting TCP_NODELAY #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,7 @@ def _create_pg_connection(self, address, context): | |
| redirect_config = self.instance_config.redirect | ||
|
|
||
| pg_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| pg_sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) | ||
| pg_sock.connect((redirect_config.host, redirect_config.port)) | ||
| pg_sock.setblocking(False) | ||
|
|
||
|
|
@@ -130,6 +131,7 @@ def accept_wrapper(self, sock: socket.socket): | |
|
|
||
| # Accept the raw connection | ||
| clientsocket, address = sock.accept() | ||
| clientsocket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Would there be a point to enable only for ssl?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. Nagle's delay applies to any small-packet exchange, not just SSL. SSL makes the improvement more obvious because of the extra SSLRequest round trip, but auth and ready-for-query messages are small on every connection. |
||
| # On macOS, accepted sockets inherit O_NONBLOCK from the listening socket. | ||
| # SSL negotiation uses blocking recv, so we must set blocking explicitly here. | ||
| clientsocket.setblocking(True) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you measured the impact on larger queries? Will we lose significant performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran a small benchmark with TCP_NODELAY=1 vs Nagle across payload sizes from 1B to 10MB:
(mean end-to-end latency for a single SELECT query)
No meaningful difference for larger queries.
The benchmark did surface a pre-existing bug where large payloads could cause connection hangs. I will open a follow-up PR for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR for the large payload hang #16