From e7922c1b547d58e605cf5a877ace8214c992d987 Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Tue, 3 Jan 2017 18:35:11 -0800 Subject: [PATCH 1/2] add configurable backlog #263 --- sanic/sanic.py | 6 ++++-- sanic/server.py | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/sanic/sanic.py b/sanic/sanic.py index 22ed234e..d0674360 100644 --- a/sanic/sanic.py +++ b/sanic/sanic.py @@ -20,7 +20,7 @@ from .exceptions import ServerError class Sanic: def __init__(self, name=None, router=None, - error_handler=None, logger=None): + error_handler=None, logger=None, backlog=100): if logger is None: logging.basicConfig( level=logging.INFO, @@ -29,6 +29,7 @@ class Sanic: if name is None: frame_records = stack()[1] name = getmodulename(frame_records[1]) + self.backlog = backlog self.name = name self.router = router or Router() self.error_handler = error_handler or Handler(self) @@ -278,7 +279,8 @@ class Sanic: 'error_handler': self.error_handler, 'request_timeout': self.config.REQUEST_TIMEOUT, 'request_max_size': self.config.REQUEST_MAX_SIZE, - 'loop': loop + 'loop': loop, + 'backlog': self.backlog } # -------------------------------------------- # diff --git a/sanic/server.py b/sanic/server.py index e789f173..ec207d26 100644 --- a/sanic/server.py +++ b/sanic/server.py @@ -226,7 +226,7 @@ def trigger_events(events, loop): def serve(host, port, request_handler, error_handler, before_start=None, after_start=None, before_stop=None, after_stop=None, debug=False, request_timeout=60, sock=None, request_max_size=None, - reuse_port=False, loop=None, protocol=HttpProtocol): + reuse_port=False, loop=None, protocol=HttpProtocol, backlog=100): """ Starts asynchronous HTTP Server on an individual process. :param host: Address to host on @@ -276,7 +276,8 @@ def serve(host, port, request_handler, error_handler, before_start=None, host, port, reuse_port=reuse_port, - sock=sock + sock=sock, + backlog=backlog ) # Instead of pulling time at the end of every request, From 616e20d4674de93f89b3f0b509e206c31ae9a2bc Mon Sep 17 00:00:00 2001 From: Raphael Deem Date: Wed, 4 Jan 2017 09:31:06 -0800 Subject: [PATCH 2/2] move backlog to run() --- sanic/sanic.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sanic/sanic.py b/sanic/sanic.py index d0674360..a3f49197 100644 --- a/sanic/sanic.py +++ b/sanic/sanic.py @@ -20,7 +20,7 @@ from .exceptions import ServerError class Sanic: def __init__(self, name=None, router=None, - error_handler=None, logger=None, backlog=100): + error_handler=None, logger=None): if logger is None: logging.basicConfig( level=logging.INFO, @@ -29,7 +29,6 @@ class Sanic: if name is None: frame_records = stack()[1] name = getmodulename(frame_records[1]) - self.backlog = backlog self.name = name self.router = router or Router() self.error_handler = error_handler or Handler(self) @@ -243,7 +242,7 @@ class Sanic: def run(self, host="127.0.0.1", port=8000, debug=False, before_start=None, after_start=None, before_stop=None, after_stop=None, sock=None, - workers=1, loop=None, protocol=HttpProtocol): + workers=1, loop=None, protocol=HttpProtocol, backlog=100): """ Runs the HTTP Server and listens until keyboard interrupt or term signal. On termination, drains connections before closing. @@ -280,7 +279,7 @@ class Sanic: 'request_timeout': self.config.REQUEST_TIMEOUT, 'request_max_size': self.config.REQUEST_MAX_SIZE, 'loop': loop, - 'backlog': self.backlog + 'backlog': backlog } # -------------------------------------------- #