From 859b92ab755062262282bb4f489d1f87d0a725c0 Mon Sep 17 00:00:00 2001 From: Albert Tugushev Date: Thu, 23 Jul 2020 22:03:24 +0700 Subject: [PATCH] Increase chunk size for messages reader from IO stream Low value (previously 52) caused preformance issues. --- ansq/tcp/connection.py | 3 ++- ansq/tcp/consts.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ansq/tcp/connection.py b/ansq/tcp/connection.py index 4b15813..5a533a3 100644 --- a/ansq/tcp/connection.py +++ b/ansq/tcp/connection.py @@ -6,6 +6,7 @@ from time import time from typing import Optional, Callable, Any, Union, Generator +from ansq.tcp import consts from ansq.tcp.exceptions import ProtocolError, get_exception, NSQUnauthorized from ansq.tcp.types import ( TCPConnection as NSQConnectionBase, ConnectionStatus, NSQMessage, @@ -218,7 +219,7 @@ async def _read_data_task(self): """Response reader task.""" while not self._reader.at_eof(): try: - data = await self._reader.read(52) + data = await self._reader.read(consts.MAX_CHUNK_SIZE) except asyncio.CancelledError: # useful during update to TLS, task canceled but connection # should not be closed diff --git a/ansq/tcp/consts.py b/ansq/tcp/consts.py index a316040..fa6bbfb 100644 --- a/ansq/tcp/consts.py +++ b/ansq/tcp/consts.py @@ -7,3 +7,4 @@ ATTEMPTS_SIZE = 2 MSG_ID_SIZE = 16 MSG_HEADER = TIMESTAMP_SIZE + ATTEMPTS_SIZE + MSG_ID_SIZE +MAX_CHUNK_SIZE = 4096