Hello,
I am using sanic to build API microservices and also to build a website. The website returns jinja2-rendered templates as text(...). In both cases, a significant part of the runtime is calling upstream microservices via the aiohttp client.
For the API microservices, the users will primarily use HTTP/1.1 and I'm using nghttpx as a reverse proxy.
For the website, users will use both HTTP/1.1 and HTTP/2, and I'm also using nghttpx as a reverse proxy.
My questions are:
a) Do you think the wrapping around hyper-h2 is ready for production?
b) Do you see a significant speed difference between the parser in hyper-h2 and http-parser?
b) Would you present sanic to nghttpx as HTTP/1.1 and HTTP/2?
Thank you,
Adam
p.s. switching from falcon to sanic and requests to aiohttp reduced the CPU load on our backend servers from 62% to 25%! Most of this saving is likely iowait.
a) Do you think the wrapping around hyper-h2 is ready for production?
It hasn't even been merged yet, so it might make sense to wait for a few minor versions after it's been merged to try running it in prod. That way we can fix any potential bugs that come up.
b) Do you see a significant speed difference between the parser in hyper-h2 and http-parser?
Channelcat observed the http2 implementation being about 35% slower. However that was just a single page, and I'm not sure how it was tested. If it wasn't tested with the browser, the browser may do some smarter stuff that would make it worthwhile.
b) Would you present sanic to nghttpx as HTTP/1.1 and HTTP/2?
Good question, I'm not sure. Would nghttpx expose sanic over http2 even if you were using the version of sanic that only supports http1.1? To me it looks like it would, based on the project info:
nghttpx(1) is a proxy translating protocols between HTTP/2 and other protocols (e.g., HTTP/1, SPDY)
If that is the case then it probably reinforces the suggestion to use HTTP1.1 for now, since you'll still get HTTP2 support via nghttpx. However ultimately I would recommend doing some benchmarks and tests of your own to see how resilient and efficient the different configuration options are, as there's nothing quite like real data (i.e. the above is largely opinion and speculation).
Thank you Raphael, that aligns with my thinking too.
Closing this, feel free to reopen to continue the discussion if needed.
is there any updates about http/2 and Sanic?
It is not planned for the upcoming 18.12 LTS, but I suspect it will work it's way into master this winter and hopefully be included in 19.3 release.
in the interim, are there recommendations to run Sanic (+gunicorn?) behind for instance a Caddyserver?
@djoek I am not familiar with caddyserver. But, while you can use gunicorn see the docs, I would say my recommended way is with the built in server using something like Kubernetes to manage one or more instances for horizontal scaling.
Cool, thanks @ahopkins ! caddyserver is just a http2 server, so the question was more of a "what are the http2 best practices" but i can roll with this
@djoek We are working on an implementation to add asgi support to Sanic. Right now we are aiming for the March 2019 release. This will allow use of things like uvicorn, hypercorn, and daphne to run Sanic, thus allowing for HTTP/2 support.
@ahopkins This is great! Any news?
Yes. We hope to have it workable for the 19.6 release.
Most helpful comment
@djoek We are working on an implementation to add
asgisupport to Sanic. Right now we are aiming for the March 2019 release. This will allow use of things likeuvicorn,hypercorn, anddaphneto run Sanic, thus allowing for HTTP/2 support.