Skip to content
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

Comparison with httptools #9

Closed
kespindler opened this issue Aug 2, 2016 · 1 comment
Closed

Comparison with httptools #9

kespindler opened this issue Aug 2, 2016 · 1 comment

Comments

@kespindler
Copy link

In your readme you say you attempted a cython wrapper around http-parser, which appears to have been done now: https://github.com/MagicStack/httptools

Do you have any points of reference on performance, ease of use, or other points between the two libraries?

@njsmith
Copy link
Member

njsmith commented Aug 27, 2016

It's not really an apples-to-apples comparison. httptools is substantially lower-level -- it just provides a parser, while h11 implements a complete model of the HTTP request/response cycle. Potentially h11 could be adapted to use httptools internally for parsing, but I don't think it would be very useful. Currently h11 is pure Python, but httptools requires a C compiler, which adds operational complexity. Normally this is offset by C code being faster, but in my benchmarks, h11's parser isn't the bottleneck anyway, so optimizing it wouldn't get you much.

httptools is definitely faster -- but AFAICT that's mostly because it does less. There are a lot of fiddly bits required to correctly implement HTTP, and those have a cost, which h11 pays. If you don't care about handling the edge cases correctly (which is a totally valid situation to be in!) and need Ultimate Speed, then implementing something on top of httptools is probably a better starting point than h11; if you don't want to read RFCs then h11 handles a lot of picky junk for you, and is probably "fast enough".

(For reference, on my laptop, h11 handles the protocol parts of doing a request/response cycle in ~0.2 milliseconds on CPython, and ~0.04 milliseconds on PyPy. So if you're implementing an HTTP server and need, say, 10 ms to actually generate your response -- doing database calls, filling in templates, etc. -- then h11's overhead is very small in relative terms.)

CC: @1st1 in case he has a different perspective he'd like to bring in :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants