Skip to content

Commit 05767d6

Browse files
refactor(protocol): extract _READ_CHUNK_SIZE constant
Replace the bare literal 4096 in DqliteProtocol._read_chunk with a named module-level constant and explain the tradeoff (syscall overhead vs. small-message latency). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 527d7b1 commit 05767d6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/dqliteclient/protocol.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
)
2828
from dqlitewire.messages.base import Message
2929

30+
# Socket read buffer size. 4 KiB balances syscall overhead for typical
31+
# request/response payloads against latency for small wire messages.
32+
_READ_CHUNK_SIZE = 4096
33+
3034

3135
class DqliteProtocol:
3236
"""Low-level protocol handler for a single dqlite connection."""
@@ -292,7 +296,7 @@ async def _read_data(self, deadline: float | None = None) -> bytes:
292296
else:
293297
timeout = self._timeout
294298
try:
295-
data = await asyncio.wait_for(self._reader.read(4096), timeout=timeout)
299+
data = await asyncio.wait_for(self._reader.read(_READ_CHUNK_SIZE), timeout=timeout)
296300
except TimeoutError:
297301
raise DqliteConnectionError(f"Server read timed out after {timeout:.1f}s") from None
298302
except (ConnectionError, OSError, RuntimeError) as e:

0 commit comments

Comments
 (0)