We should discuss disabling the access log by default since it:
1) causes significant slowdown
2) would be potentially provided by something like nginx.
For those who immediately want to restore Sanic's performance, by sacrificing the access log, you'll need to disable it: app = Sanic(log_config=None).
See https://github.com/channelcat/sanic/issues/770, https://github.com/channelcat/sanic/issues/835, and https://github.com/channelcat/sanic/pull/839 for further context.
Beyond that, we should consider updating and re-adding the benchmark table. However, in #839 the creator of aiohttp criticized that we left the access log enabled with aiohttp and not sanic -- for the record, our original log configuration was not logging every request, so we didn't need to disable it. Anyway, next time we should state as a disclaimer that we haven't taken all of the steps to optimize each framework and are simply using their default configuration.
As for the benchmark table,
otherwise, it's not very meaningful.
Also aiohttp doesn't enforce uvloop by default but uses pre-installed loop policy.
It makes result numbers very different.
Here is a benchmark for python web frameworks. it includes three types of benchmark tests.
http://klen.github.io/py-frameworks-bench/ for reference.
Maybe we should take the approach from 12 factor and not write this to the disk by default?
Treat logs as event streamsTwelve-factor apps write logs as an ordered event stream to stout. Applications should not attempt to manage the storage of their own log files. The collection and archival of log output for an application should instead be handled by the execution environment.
yeah, that may help, and Python3 has sth similar builtin.
https://docs.python.org/3/library/logging.handlers.html#queuehandler
https://docs.python.org/3/library/logging.handlers.html#queuelistener
But i am not too concerning about the logging, it's a pain point for all frameworks. logging/logging infra may be vary from one user to another. I'd prefer not to do too much for the user, leave the choice to the user. like, one can also use zmq for logging, just send messages for a log-broker.
The log_config=None argument doesn't even work anymore, all requests are still logged. What a shame!
I extend the Sanic class and write the _helper method to set access_log = False as default setting.
This method is called when sanic create/run the server
from sanic import Sanic
from sanic.server import serve, serve_multiple, HttpProtocol, Signal
class MySanic(Sanic):
def __init__(self, name=None, router=None, error_handler=None,
load_env=True, request_class=None):
super().__init__(name=name, router=router, error_handler=error_handler,
load_env=load_env, request_class=request_class)
# Custom attributes
self.mongo_db = None
self.pg_db = None
self.redis_db = None
self.user_cache = {} # Cache mongo_db user + password hash for quick login, sync every 2min
self.connected_users = {} # Keep connected user id + live token
self.xiangqi_clients = {}
self.xiangqi_rooms = {}
self.poker_clients = {}
self.poker_rooms = {}
self.bacay_clients = {}
self.bacay_rooms = {}
self.connected_ws_set = set()
self.use_msgpack = False
def _helper(self, host=None, port=None, debug=False,
ssl=None, sock=None, workers=1, loop=None,
protocol=HttpProtocol, backlog=100, stop_event=None,
register_sys_signals=True, run_async=False, access_log=False):
return super()._helper(host=host, port=port, debug=debug,
ssl=ssl, sock=sock, workers=workers, loop=loop,
protocol=protocol, backlog=backlog, stop_event=stop_event,
register_sys_signals=register_sys_signals, run_async=run_async, access_log=access_log)
And it runs well
@r0fls was this resolved at all? I can't find a PR or anything, but it seems like a good idea that should be embraced to me.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is incorrect, please respond with an update. Thank you for your contributions.
Most helpful comment
Maybe we should take the approach from 12 factor and not write this to the disk by default?