-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http parser implementation based on http-parser #1626
Conversation
aiohttp/_parser.pyx
Outdated
self._upgraded = True | ||
|
||
encoding = None | ||
enc = headers.get(hdrs.CONTENT_ENCODING) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any need to have two variables to reference on content encoding?
return HttpVersion10 | ||
elif parser.http_minor == 1: | ||
return HttpVersion11 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we crash if version will be something weird?
messages = self._messages | ||
self._messages = [] | ||
else: | ||
messages = () |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self._messages
are list, but here messages becomes a tuple.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not want to convert messages into tuple. doesnt really matter
size_t max_field_size=8190): | ||
self._init(cparser.HTTP_REQUEST, protocol, loop, | ||
max_line_size, max_headers, max_field_size) | ||
#self._proto_on_url = getattr(protocol, 'on_url', None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be drop this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i've not decided on url, http-parser provides url parsing, should give some more performance, but it requires yarl integration
aiohttp/_parser.pyx
Outdated
const char *at, size_t length) except -1: | ||
cdef HttpParser pyparser = <HttpParser>parser.data | ||
try: | ||
#pyparser.url = _parse_url(at[:length], length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as previous
aiohttp/_parser.pyx
Outdated
cdef int cb_on_chunk_complete(cparser.http_parser* parser) except -1: | ||
cdef HttpParser pyparser = <HttpParser>parser.data | ||
try: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something TBD here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
aiohttp/_parser.pyx
Outdated
cdef class URL: | ||
cdef readonly str schema | ||
cdef readonly str host | ||
cdef readonly object port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why port is an object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i have no idea :)
url handling needs some more work
aiohttp/server.py
Outdated
loop=self._loop)) | ||
return | ||
except Exception as exc: | ||
print('exc') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug print.
aiohttp/server.py
Outdated
|
||
# feed payload | ||
else: | ||
if data: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif data
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
@@ -267,9 +275,9 @@ def request(pid): | |||
yield from sess.close() | |||
|
|||
|
|||
@pytest.mark.xfail | |||
# @pytest.mark.xfail |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be remove all these # pytest.mark.xfail
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i do not understand those tests, i need andrew help
Codecov Report
@@ Coverage Diff @@
## master #1626 +/- ##
=========================================
Coverage ? 94.61%
=========================================
Files ? 31
Lines ? 7395
Branches ? 1281
=========================================
Hits ? 6997
Misses ? 264
Partials ? 134
Continue to review full report at Codecov.
|
added http-parser's url parsing functionality. on my mac i get ~14.3k rps, ~7k was on 1.3 |
1.2 is slightly faster than 1.3, ~7.3k rps |
with all latest changes i could get ~16.2rps interestingly, |
cool, i didn't know about |
@samuelcolvin added |
great! |
aiohttp/test_utils.py
Outdated
"""Teardown and cleanup an event_loop created | ||
by setup_test_loop. | ||
|
||
""" | ||
if fast is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be
fast |= TESTS_FAST
that way if you're testing with pytest and have AIOHTTP_TESTS_FAST=True
but don't supply the --fast
argument you get fast tests.
With current setup AIOHTTP_TESTS_FAST
has no effect with pytest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think AIOHTTP_TESTS_FAST
is not needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fine by me.
i modified gunicorn worker to disable access log if access log is not configured on my mac i got ~60k rps t_srv.py: async def intro(request):
resp = Response(status=200)
return resp
def init():
app = Application()
app.router.add_get('/', intro)
return app
app = init() gunicorn command:
and wrk command:
|
ba056e3
to
ea68872
Compare
1f2d965
to
a92549e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🖌
merged to master @kxepal if you want to modify cython code, just modify on master |
added c-based http parser, cython code is based on https://github.com/MagicStack/httptools
it gives ~15-25% increase