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

Async #8

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Async #8

wants to merge 13 commits into from

Conversation

yohanboniface
Copy link
Member

Attempt at going async.

I've made the choice of a very low level approach to pull in as little as possible code and make it easier to optimize. Utilery does only one thing after all: take a (simple) URL and return a response. No form handling nor request body parsing, no cookie, no need to be generic…

Basically, async does not prove to be faster, but the code simplification and the use of httptools and asyncpg may worth it.

Bench: https://gist.github.com/yohanboniface/d168050ee7db382341c8724cbd941cac

We can see a very small boost (on my laptop).

Async or not, at the end, the real way to scale the tile server is:

  • add more CPUs
  • add better indices in the database

Async makes it easier to server more requests on a single process, but this can be achieved by Gunicorn/uwsgi + nginx much better in any cases. And this is the cons of this PR: it's harder to deploy with Nginx and uwsgi. This is why I've made a Gunicorn worker.
I'll look at serving with uwsgi in the future (needs a custom uwsgi compilation for now).

How to run:

Debug:

python utilery/server.py

Bench production:

gunicorn utilery.views:application -b 0.0.0.0:3579 -k utilery.worker.Worker -w 5

Tests are passing, but coverage have decreased due to replacing Werkzeug by httptools and asyncio.create_server, which needs dedicated tests. I'll add them.
Also I'll do more benchs for code optimization (having persistent views for example).

cc @Shongololo @magopian

cf #5

@songololo
Copy link

@yohanboniface what are your thoughts on dockerised deployment. I've been using nginx reverse proxy to load-balance to multiple dockerised containers (aiovectortiler in my case). nginx is also handy for setting backend and client side caching (but I haven't explored this much.)

@yohanboniface
Copy link
Member Author

Not a Docker fanboy myself, I think Nginx + gunicorn and multiple workers should scale well.
What are you trying to solve with Docker that you cannot solve without?

@songololo
Copy link

It is mainly handy for easing deployment without needing to reproduce a python environment & packages.

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

Successfully merging this pull request may close these issues.

2 participants