diff --git a/docs/sanic/config.md b/docs/sanic/config.md index c16e2397..5f87348a 100644 --- a/docs/sanic/config.md +++ b/docs/sanic/config.md @@ -88,6 +88,7 @@ Out of the box there are just a few predefined values which can be overwritten w | Variable | Default | Description | | ------------------------- | --------- | ------------------------------------------------------ | | REQUEST_MAX_SIZE | 100000000 | How big a request may be (bytes) | + | REQUEST_BUFFER_QUEUE_SIZE | 100 | Request streaming buffer queue size | | REQUEST_TIMEOUT | 60 | How long a request can take to arrive (sec) | | RESPONSE_TIMEOUT | 60 | How long a response can take to process (sec) | | KEEP_ALIVE | True | Disables keep-alive when False | diff --git a/sanic/app.py b/sanic/app.py index c2a24464..7a4af641 100644 --- a/sanic/app.py +++ b/sanic/app.py @@ -1071,6 +1071,7 @@ class Sanic: "response_timeout": self.config.RESPONSE_TIMEOUT, "keep_alive_timeout": self.config.KEEP_ALIVE_TIMEOUT, "request_max_size": self.config.REQUEST_MAX_SIZE, + "request_buffer_queue_size": self.config.REQUEST_BUFFER_QUEUE_SIZE, "keep_alive": self.config.KEEP_ALIVE, "loop": loop, "register_sys_signals": register_sys_signals, diff --git a/sanic/config.py b/sanic/config.py index 0a53a607..15341829 100644 --- a/sanic/config.py +++ b/sanic/config.py @@ -32,6 +32,7 @@ class Config(dict): ▀▀▄▄▀ """ self.REQUEST_MAX_SIZE = 100000000 # 100 megabytes + self.REQUEST_BUFFER_QUEUE_SIZE = 100 self.REQUEST_TIMEOUT = 60 # 60 seconds self.RESPONSE_TIMEOUT = 60 # 60 seconds self.KEEP_ALIVE = keep_alive diff --git a/sanic/request.py b/sanic/request.py index faa63137..fc392c11 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -49,9 +49,8 @@ class RequestParameters(dict): class StreamBuffer: - def __init__(self, buffer_size=None): - self._buffer_size = buffer_size or 100 - self._queue = asyncio.Queue() + def __init__(self, buffer_size=100): + self._queue = asyncio.Queue(buffer_size) async def read(self): """ Stop reading when gets None """ diff --git a/sanic/server.py b/sanic/server.py index ff87198e..af253775 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -59,7 +59,7 @@ class HttpProtocol(asyncio.Protocol): "response_timeout", "keep_alive_timeout", "request_max_size", - "request_body_buffer_queue_size", + "request_buffer_queue_size", "request_class", "is_request_stream", "router", @@ -85,10 +85,10 @@ class HttpProtocol(asyncio.Protocol): signal=Signal(), connections=None, request_timeout=60, - request_body_buffer_queue_size=100, response_timeout=60, keep_alive_timeout=5, request_max_size=None, + request_buffer_queue_size=100, request_class=None, access_log=True, keep_alive=True, @@ -111,7 +111,7 @@ class HttpProtocol(asyncio.Protocol): self.request_handler = request_handler self.error_handler = error_handler self.request_timeout = request_timeout - self.request_body_buffer_queue_size = request_body_buffer_queue_size + self.request_buffer_queue_size = request_buffer_queue_size self.response_timeout = response_timeout self.keep_alive_timeout = keep_alive_timeout self.request_max_size = request_max_size @@ -295,7 +295,7 @@ class HttpProtocol(asyncio.Protocol): ) if self._is_stream_handler: self.request.stream = StreamBuffer( - self.request_body_buffer_queue_size + self.request_buffer_queue_size ) self.execute_request_handler() @@ -581,6 +581,7 @@ def serve( ssl=None, sock=None, request_max_size=None, + request_buffer_queue_size=100, reuse_port=False, loop=None, protocol=HttpProtocol, @@ -641,6 +642,7 @@ def serve( outgoing bytes, the low-water limit is a quarter of the high-water limit. :param is_request_stream: disable/enable Request.stream + :param request_buffer_queue_size: streaming request buffer queue size :param router: Router object :param graceful_shutdown_timeout: How long take to Force close non-idle connection