Skip to content

Commit eec7837

Browse files
zsandCommanderKeynes
authored andcommitted
Add TCP_NODELAY option to improve performance for large response queries (#749)
This commit adds the TCP_NODELAY option to the socket configuration in `configure_socket` function. Without this option, we observed significant performance issues when executing SELECT queries with large responses. Before the fix: postgres=> SELECT repeat('a', 1); SELECT repeat('a', 8153); Time: 1.368 ms Time: 41.364 ms After the fix: postgres=> SELECT repeat('a', 1); SELECT repeat('a', 8153); Time: 1.332 ms Time: 1.528 ms By setting TCP_NODELAY, we eliminate the Nagle's algorithm delay, which results in a substantial improvement in response times for large queries. This problem was discussed in #616.
1 parent de87f07 commit eec7837

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/messages.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ pub fn configure_socket(stream: &TcpStream) {
747747
}
748748
Err(err) => error!("Could not configure socket: {}", err),
749749
}
750+
match sock_ref.set_nodelay(true) {
751+
Ok(_) => (),
752+
Err(err) => error!("Could not configure TCP_NODELAY for socket: {}", err),
753+
}
750754
}
751755

752756
pub trait BytesMutReader {

0 commit comments

Comments
 (0)