2

I've installed Nginx + uWSGI + Django on a VDS with 3 CPU cores. uWSGI is configured for 6 processes and 5 threads per process. Now I want to tell uWSGI to use processes for load balancing until all processes are busy, and then to use threads if needed. It seems uWSGI prefer threads, and I have not found any config option to change this behaviour. First process takes over 100% CPU time, second one takes about 20%, and another processes are mostly not used.

Our site receives 40 r/s. Actually even having 3 processes without threads is anough to handle all requests usually. But request processing hangs from time to time for various reasons like locked shared resources, etc. In such cases we have -1 process. Users don't like to wait and click the link again and again. As a result all processes hangs and all users have to wait.

I'd add even more threads to make the server more robust. But the problem is probably python GIL. Threads wan't use all CPU cores. So multiple processes work much better for load balancing. But threads may help a lot in case of locked shared resources and i/o wait delays. A process may do much work while one of it's thread is locked.

I don't want to decrease time limits until there is no another solution. It is possible to solve this problem with threads in theory, and I don't want to show error messages to user or to make him waiting on every request until there is no another choice.

raacer
  • 228
  • 1
  • 2
  • 12
  • 1
    If you're not getting any performance benefits from running your application in a threaded mode because of GIL issues, why not just disable multithreading and run however many single-threaded processes you need? – jgoldschrafe Oct 07 '13 at 20:48
  • 1
    Because processes eat memory :) – raacer Oct 07 '13 at 22:44
  • Theoretically speaking that is not always true with respect to threads, though in this case it likely is. – Falcon Momot Oct 08 '13 at 04:03

0 Answers0