expose request_buffer_queue_size to be configurable and update documentation

fix StreamBuffer buffer_size
This commit is contained in:
Yun Xu 2018-12-04 20:12:04 -08:00
parent b5287184e9
commit 1bfbc67c62
5 changed files with 11 additions and 7 deletions

View File

@ -88,6 +88,7 @@ Out of the box there are just a few predefined values which can be overwritten w
| Variable | Default | Description | | Variable | Default | Description |
| ------------------------- | --------- | ------------------------------------------------------ | | ------------------------- | --------- | ------------------------------------------------------ |
| REQUEST_MAX_SIZE | 100000000 | How big a request may be (bytes) | | 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) | | REQUEST_TIMEOUT | 60 | How long a request can take to arrive (sec) |
| RESPONSE_TIMEOUT | 60 | How long a response can take to process (sec) | | RESPONSE_TIMEOUT | 60 | How long a response can take to process (sec) |
| KEEP_ALIVE | True | Disables keep-alive when False | | KEEP_ALIVE | True | Disables keep-alive when False |

View File

@ -1071,6 +1071,7 @@ class Sanic:
"response_timeout": self.config.RESPONSE_TIMEOUT, "response_timeout": self.config.RESPONSE_TIMEOUT,
"keep_alive_timeout": self.config.KEEP_ALIVE_TIMEOUT, "keep_alive_timeout": self.config.KEEP_ALIVE_TIMEOUT,
"request_max_size": self.config.REQUEST_MAX_SIZE, "request_max_size": self.config.REQUEST_MAX_SIZE,
"request_buffer_queue_size": self.config.REQUEST_BUFFER_QUEUE_SIZE,
"keep_alive": self.config.KEEP_ALIVE, "keep_alive": self.config.KEEP_ALIVE,
"loop": loop, "loop": loop,
"register_sys_signals": register_sys_signals, "register_sys_signals": register_sys_signals,

View File

@ -32,6 +32,7 @@ class Config(dict):
""" """
self.REQUEST_MAX_SIZE = 100000000 # 100 megabytes self.REQUEST_MAX_SIZE = 100000000 # 100 megabytes
self.REQUEST_BUFFER_QUEUE_SIZE = 100
self.REQUEST_TIMEOUT = 60 # 60 seconds self.REQUEST_TIMEOUT = 60 # 60 seconds
self.RESPONSE_TIMEOUT = 60 # 60 seconds self.RESPONSE_TIMEOUT = 60 # 60 seconds
self.KEEP_ALIVE = keep_alive self.KEEP_ALIVE = keep_alive

View File

@ -49,9 +49,8 @@ class RequestParameters(dict):
class StreamBuffer: class StreamBuffer:
def __init__(self, buffer_size=None): def __init__(self, buffer_size=100):
self._buffer_size = buffer_size or 100 self._queue = asyncio.Queue(buffer_size)
self._queue = asyncio.Queue()
async def read(self): async def read(self):
""" Stop reading when gets None """ """ Stop reading when gets None """

View File

@ -59,7 +59,7 @@ class HttpProtocol(asyncio.Protocol):
"response_timeout", "response_timeout",
"keep_alive_timeout", "keep_alive_timeout",
"request_max_size", "request_max_size",
"request_body_buffer_queue_size", "request_buffer_queue_size",
"request_class", "request_class",
"is_request_stream", "is_request_stream",
"router", "router",
@ -85,10 +85,10 @@ class HttpProtocol(asyncio.Protocol):
signal=Signal(), signal=Signal(),
connections=None, connections=None,
request_timeout=60, request_timeout=60,
request_body_buffer_queue_size=100,
response_timeout=60, response_timeout=60,
keep_alive_timeout=5, keep_alive_timeout=5,
request_max_size=None, request_max_size=None,
request_buffer_queue_size=100,
request_class=None, request_class=None,
access_log=True, access_log=True,
keep_alive=True, keep_alive=True,
@ -111,7 +111,7 @@ class HttpProtocol(asyncio.Protocol):
self.request_handler = request_handler self.request_handler = request_handler
self.error_handler = error_handler self.error_handler = error_handler
self.request_timeout = request_timeout 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.response_timeout = response_timeout
self.keep_alive_timeout = keep_alive_timeout self.keep_alive_timeout = keep_alive_timeout
self.request_max_size = request_max_size self.request_max_size = request_max_size
@ -295,7 +295,7 @@ class HttpProtocol(asyncio.Protocol):
) )
if self._is_stream_handler: if self._is_stream_handler:
self.request.stream = StreamBuffer( self.request.stream = StreamBuffer(
self.request_body_buffer_queue_size self.request_buffer_queue_size
) )
self.execute_request_handler() self.execute_request_handler()
@ -581,6 +581,7 @@ def serve(
ssl=None, ssl=None,
sock=None, sock=None,
request_max_size=None, request_max_size=None,
request_buffer_queue_size=100,
reuse_port=False, reuse_port=False,
loop=None, loop=None,
protocol=HttpProtocol, protocol=HttpProtocol,
@ -641,6 +642,7 @@ def serve(
outgoing bytes, the low-water limit is a outgoing bytes, the low-water limit is a
quarter of the high-water limit. quarter of the high-water limit.
:param is_request_stream: disable/enable Request.stream :param is_request_stream: disable/enable Request.stream
:param request_buffer_queue_size: streaming request buffer queue size
:param router: Router object :param router: Router object
:param graceful_shutdown_timeout: How long take to Force close non-idle :param graceful_shutdown_timeout: How long take to Force close non-idle
connection connection