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 |
| ------------------------- | --------- | ------------------------------------------------------ |
| 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 |

View File

@ -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,

View File

@ -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

View File

@ -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 """

View File

@ -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