eventlet - green threads on a django based web service

1.3k views Asked by At

I have a web service that creates images from geographic features and return it to a map using django framework. This is a tiling map service (TMS)

The web sercive is called through an url such: http://host.com/TMS/map_id/x/y/z.png where map_id, x, y and z are variables used to generate the images.

This url call a python function which return the images in a map client (OpenLayers). When moving in the map the user call a bunch of requests on this webservice like http://host.com/tiling/1/0/1/1.png, http://host.com/tiling/1/1/0/1.png, etc

I would like to use eventlet to thread the function of this webservice in order to generate images in parallel instead of one by a time.

Can someone help me doing this by providing cue about how to listen to a specific url (TMS url) and how to start threads on the function. Thanks a lot.

1

There are 1 answers

0
temoto On BEST ANSWER

Copy of same thread on Eventlet mailing list:

The easiest way is to change your backend server to gunicorn or spawning or eventlet.wsgi.

All of them (and probably, some others) are able to serve each connection or request in a separate green thread.

Please note, that if request processing is CPU bound, green threads will not help.

How to run Django under eventlet.wsgi server?

Django is no special, it's a regular WSGI application since 1.4. https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/

What is needed now to do to green thread the function of my webservice? I am running process monitor tool for windows and I see that actually the function is running on a single thread.

You are done. Every request is served in a separate green thread. Green threads, by definition 1, are not visible outside of process. (this implies that process monitor tool can not see green threads either)