From 34eddf9983fbed31337aa8e5d7538c84d24f48aa Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Mon, 5 Jun 2023 20:14:02 -0500 Subject: [PATCH] Increase slowWriteTimer to 15ms and document why --- pgconn/pgconn.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pgconn/pgconn.go b/pgconn/pgconn.go index 8fa33289..ceaed8ff 100644 --- a/pgconn/pgconn.go +++ b/pgconn/pgconn.go @@ -1712,7 +1712,13 @@ func (pgConn *PgConn) makeCommandTag(buf []byte) CommandTag { // enterPotentialWriteReadDeadlock must be called before a write that could deadlock if the server is simultaneously // blocked writing to us. func (pgConn *PgConn) enterPotentialWriteReadDeadlock() { - pgConn.slowWriteTimer.Reset(10 * time.Millisecond) + // The time to wait is somewhat arbitrary. A Write should only take as long as the syscall and memcpy to the OS + // outbound network buffer unless the buffer is full (which potentially is a block). It needs to be long enough for + // the normal case, but short enough not to kill performance if a block occurs. + // + // In addition, on Windows the default timer resolution is 15.6ms. So setting the timer to less than that is + // ineffective. + pgConn.slowWriteTimer.Reset(15 * time.Millisecond) } // exitPotentialWriteReadDeadlock must be called after a call to enterPotentialWriteReadDeadlock.