Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 997b5e0

Browse files
committed
Set TCP_NODELAY for tokio-postgres
1 parent a237a47 commit 997b5e0

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

tokio-postgres/src/proto/connect.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,16 +144,9 @@ impl PollConnect for Connect {
144144
fn poll_connecting_tcp<'a>(
145145
state: &'a mut RentToOwn<'a, ConnectingTcp>,
146146
) -> Poll<AfterConnectingTcp, Error> {
147-
loop {
147+
let socket = loop {
148148
let error = match state.future.poll() {
149-
Ok(Async::Ready(socket)) => {
150-
let state = state.take();
151-
transition!(PreparingSsl {
152-
socket: Socket::Tcp(socket),
153-
params: state.params,
154-
tls: state.tls,
155-
})
156-
}
149+
Ok(Async::Ready(socket)) => break socket,
157150
Ok(Async::NotReady) => match state.timeout {
158151
Some((_, ref mut delay)) => {
159152
try_ready!(
@@ -177,7 +170,19 @@ impl PollConnect for Connect {
177170
if let Some((timeout, ref mut delay)) = state.timeout {
178171
delay.reset(Instant::now() + timeout);
179172
}
180-
}
173+
};
174+
175+
// Our read/write patterns may trigger Nagle's algorithm since we're pipelining which
176+
// we don't want. Each individual write should be a full command we want the backend to
177+
// see immediately.
178+
socket.set_nodelay(true)?;
179+
180+
let state = state.take();
181+
transition!(PreparingSsl {
182+
socket: Socket::Tcp(socket),
183+
params: state.params,
184+
tls: state.tls,
185+
})
181186
}
182187

183188
#[cfg(unix)]

0 commit comments

Comments
 (0)