Updated Twistedweb with django

I have a Django app that needs to be deployed in a WSGI container. I can either choose an event driven application server like TwistedWeb or a process driven server like uWSGI. I fully understand the difference between event driven and server process driven and I know the Django framework is nature blocking.

I came across TwistedWeb which allows us to launch a WSGI application in an easy way.

My questions are:

1) I could have gotten anything by running Twisted instead of uWSGI since Django locks nature. Is TwistedWeb different from the standard twisted library? I know people run Twisted with Django when they need async support as well as to quickly communicate with common functionality, and they still only want one application. I don't have such a use case, and for me it's just a site.

2) Will performance be worse on TwistedWeb as a single process, and my request will block since Django is synchronous in nature? Or does TwistedWeb launch something like uWSGI, which spawns multiple processes before serving and distributes roundrobin requests among them? If so, is TwistedWeb better than uWSGI?

3) Is there any other protocol other than WSGI that can integrate Twisted with Django and still give me asynchronous behavior (trying luck here :))

+3


source to share


2 answers


You could ask each of them as a separate question; anytime you feel the need to list a list, you probably should. But here goes:



  • Yes, you would have won. By placing your Django app in Twisted, you will have access to Twisted mainloop and therefore all the Twisted APIs that you can easily access with Crochet . You also eliminate the overhead of having a separate web server, since Twisted can serve as both an external web server and an application container.
  • Performance is probably the bottleneck in your database and your Django code. Twisted will probably be a little slower than something like nginx

    , for example, to serve your static content directly, but you can make this difference pretty minimal by running your twisted server running PyPy. It sounds like you're asking about concurrency, though - something like, "Will the Twisted WSGI container only run one Django request at a time?" - to which the answer is "no". The Twisted WSGI container is multithreaded and will run Django code more or less as it is waiting to be executed.
  • It is not clear what you are asking here, so perhaps ask more about that.
+2


source


No, unless you change the django db adapters and some core component a lot, you won't get any benefit. There is some tool for a simple assignment, but you will be at the edge of the bloodstream trying to adapt something built with the blocking paradigm from the start to something completely different.

On the other hand, the performance shouldn't be the worst, as 99.9% of the time your application is the bottleneck and not your WSGI infrastructure.



As for asynchronous django, a lot of people have had good luck with gevent, but you need to carefully analyze your application to make sure all components are gevent-friendly (and it can't be an easy task, especially for db adapters).

Remember that even if your application doesn't block 99.9999999%, you still block.

+2


source







All Articles