0

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.

Below the Radar
  • 7,321
  • 11
  • 63
  • 142
  • How did you deploy your web service? Usually, the browser requests multiple tiles at once. If you have more than one worker, tiles should already be created in parallel. – sk1p Dec 18 '13 at 09:29
  • this web service is still running on django development server in local, but I am working on future deployment on WebFaction. I have read that I have to change my server to eventlet.wsgi to make it works in parallel. Is there a way to verify if the tiles are actually created in parallel? – Below the Radar Dec 18 '13 at 13:14
  • 1
    Any serious deployment method allows parallel requests, from gunicorn, mod_wsgi, uwsgi to fastcgi. Since Django 1.4, even the development server is threaded. I don't know about WebFaction, but if you have shell access, you can verify this by running `top` or `htop` and check the utilization of the available cores while firing test requests at your server. – sk1p Dec 18 '13 at 13:37

1 Answers1

2

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)

temoto
  • 5,394
  • 3
  • 34
  • 50