Uwsgi starts multiple processes, and django website user session has been emptying.

1.django+uwsgi+nginx management platform, which used to work in a single thread. Later, a function was added to query and modify the password of the host in the ip list in batch. When updating, the site will not respond until the execution is finished because of a single thread.
2. The number of virtual machines and cores is 2. I have both set the process to 4 and the thread has not set
3 to 2. Nginx and uwsgi. Then came the problem of session emptying and jumping back to the login interface soon after the site was logged in. There is no error in the log, but it is found that the session recording the login status is empty, so it is thought that the login timeout has been skipped.

this is my uwsgi configuration
[uwsgi]
chdir=xx
module=xx
socket=xx
master=True
workers=4
pidfile=xx
vacuum=True
max-requests=5000
daemonize=xx
async=30
ugreen=""
http-timeout=300

the previous configuration only did not have a workers line, so it was a single process. After adding workers=4, log in to the website to execute the function for a long time, and there is a corresponding for others to visit the website, that is, session will always be cleared within one minute. Why
?

Mar.21,2021

this is not supposed to happen. For each request, the session information generated by the backend is saved in the django_session table, and then the session key is put into cookie and returned to the front end. When the front end requests again, take this session, to the database to query the corresponding information.
.. / python2.7/site-packages/django/contrib/sessions/middleware.py
you see


solves
because what is set in my django settings is to use cache to save session
different uWsgi processes cannot get the cache of other processes
set up django's session storage to use data base or cache + database

  • Who has encountered django+uwsgi+nginx users?

    uses django+uwsgi+nginx to develop a background management system, which is not used by many people, and there is no performance problem. But there has always been a problem, that is, occasionally encountered, with a sudden login user becomes another. W...

    Mar.04,2022
Menu