3

I have a django application in which i am using python Thread module to do multi threading, it works fine while using django development server through manage.py. But when i deploy on apache - mod_wsgi, its not working .join is failing and threading not working. Can anyone help for exact apache configuration ?

i tried keeping some multithread and multiprocess configuration like follows. But still not working. My configuration - Listen 8000

Alias /static/ /usr/td/static/
<Directory /usr/td/static/>
    Require all granted
</Directory>

<Directory /usr/td>
    <Files wsgi.py>
     Require all granted
    </Files>
</Directory>
    WSGIDaemonProcess td display-name=myproject processes=10 threads=255 python-path=/usr/td/:/usr/lib/python2.7/site-packages
    WSGIProcessGroup td
WSGIScriptAlias / /usr/td/td/wsgi.py

1 Answer 1

2

There is nothing in mod_wsgi that stops you from using threading, although running background tasks in a web application process is often a bad idea. Depending on what you are doing, you should use a separate task queuing system such as Celery.

One thing that stands out as indicating you are going off in the wrong direction is that you have set threads=255. This is the number of concurrent threads for accepting requests. It is nearly always a very bad idea to set such a high number.

Right now you have set up a request thread pool size across all mod_wsgi daemon processes of 2550 threads, which is way more than Apache itself can even proxy. So it is just a waste of memory as would never be used.

Even 25 threads would be regarded as being high and you definitely don't want to use a large number of threads if the process is doing high CPU tasks as the threading model and GIL of Python don't make it practical.

Why are you using such a high number of threads? That number is nothing to do with any background threads you may create yourself to do stuff, it is only indicating number of web request handler threads.

Suggest you actually show a bit about the actual threading code you are trying to run. The Apache/mod_wsgi configuration has really got nothing to do with it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Graham for the answer. I do not need to keep threads in wsgi - apache configuration here. I though keeping this config will allow for threading in python.. i just wanted to run threads in the backend. so does the celery will help me in the backend ? can you please share some links having example? i have gone though the celery docs , but it looked complected to me.. i am using Thread module to do some parallel work in the backend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.