sanic-org/sanic

The AsyncIO Server should use Python's 3.7 BufferedProtocol when possible ?

Ouverte

#1 873 ouverte le 15 juin 2020

 (8 commentaires) (0 réaction) (0 personne assignée)Python (1 515 forks)batch import
feature requesthelp wantedidea discussionneeds investigation

Métriques du dépôt

Stars
 (17 623 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

Description

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

Guide contributeur