How does django handle multiple users

非 Y 不嫁゛ 提交于 2021-01-27 02:27:26

问题


How does Django handle multiple users? I know that Apache creates a new thread and expressjs uses asynchronous methods. But I do not understand Django because it is working synchronously would'nt this slow down the process if there are more than say 2-3 users ?

Thanks


回答1:


Django is a WSGI application, which is a fundamental difference from a (WSGI) server such as Apache. Node.js/Express.js contains its own webserver to replace Apache. Django has to be served by a webserver of your choice.

Django's only job is to be thread-safe. All other aspects of concurrent requests are handled by your webserver.




回答2:


Assuming that your worry concerns multiple connections/requests in general and not users in particular, I would have to say the following about Django and threads.

Django is certainly thread-safe. It is a design consideration that has occupied several people in the past, as someone that follows Django development can observe.

For that reason, Django can be deployed in a multi-threaded container such as the default threaded mod_wsgi that works with the Apache server, and as such it has been evaluated by many deployments.

There are concerns however on how thread-safe is any particular application that is based on Django, and this is up to the individual developers and maintainers discretion to use best practices.

In Django documentation there are particular sections devoted into the safety of threads. For instance, the class-based views documentation specifically mentions that every class-based view has independent state. Also, one very common concern is custom template tags, as address in this section. I am sure there are other references to the subject too that currently I miss, so I would advise to keep documentation handy if your thread-safety concerns are too big.




回答3:


Django doesn't do anything to handle this at all. It's entirely the job of whatever server is serving Django, be it Apache, gunicorn, uwsgi, or whatever. Those servers are responsible for managing the threads or processes to serve multiple requests.



来源:https://stackoverflow.com/questions/30506282/how-does-django-handle-multiple-users

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!