sanic-org/sanic
The AsyncIO Server should use Python's 3.7 BufferedProtocol when possible ?
Aperta
#1873 aperta il 15 giu 2020
feature requesthelp wantedidea discussionneeds investigation
Metriche repository
- Star
- (17.623 stelle)
- Metriche merge PR
- (Nessuna PR mergiata in 30 g)
Descrizione
Not sure how much performance it can add, but might be worth exploring: https://bugs.python.org/issue32251
It can be done in a backward compatible way with Python 3.6 like this: https://github.com/huge-success/sanic/blob/bedf68a9b2025618a94cb8044f495a0abd87a134/sanic/server.py#L47
Instead of inheriting asyncio.Protocol, it can be done:
try:
from asyncio import BufferedProtocol as BaseProtocol
# Python 3.6 support
except ImportError:
from asyncio import Protocol as BaseProtocol
And inside the implementation, it can be written for both Python 3.6 and 3.7+ by defining the 3 methods (where the first 2 use a preallocated buffer):
class HttpProtocol(BaseProtocol):
def get_buffer(self, sizehint):
def buffer_updated(self, nbytes):
# Python 3.6 support
def data_received(self, data):