一个简单的管理命令,可以从大型会话表中删除过期的会话,而不会杀死网站。
项目描述
一个简单的管理命令,可以从大型会话表中删除过期的会话,而不会杀死网站。
主要用例是如果您有一个有数百万过时会话的实时应用程序。运行常规的python manage.py cleanup可能会锁定您的数据库数小时,从而杀死您的网站。
使用django-graceful-session-cleanup,您可以逐步删除所有会话。
为了实现这一点,它将始终每次查询只删除一小部分过期的会话,然后暂停几秒钟。有一些命令行选项可以控制间隔、暂停时间和每次间隔要删除的会话数量。
安装
安装包
pip install django-graceful-session-cleanup
将其添加到INSTALLED_APPS
INSTALLED_APPS = [ .... 'graceful_session_cleanup', ]
运行管理命令
python manage.py graceful_session_cleanup
有一些选项您可以使用
python manage.py graceful_session_cleanup --sleep-seconds 9 --delete-count 1000 --iteration-count 200
这将删除1000个过期的会话条目,等待5秒钟以便其他进程可以使用数据库,然后重复200次。根据数据库负载(假设删除需要1秒),这将需要(9s + 1s) * 200 = 2000s。
命令行上有帮助
$ python manage.py help graceful_session_cleanup Usage: django graceful_session_cleanup [options] Can be run as a cronjob or directly to clean out old data from the database (only expired sessions at the moment). Does this in a live db friendly way by never hogging the connection too long. Options: -v VERBOSITY, --verbosity=VERBOSITY Verbosity level; 0=minimal output, 1=normal output, 2=all output --settings=SETTINGS The Python path to a settings module, e.g. "myproject.settings.main". If this isn't provided, the DJANGO_SETTINGS_MODULE environment variable will be used. --pythonpath=PYTHONPATH A directory to add to the Python path, e.g. "/home/djangoprojects/myproject". --traceback Print traceback on exception -s SLEEP_SECONDS, --sleep-seconds=SLEEP_SECONDS How long to sleep between each delete operation. -c DELETE_COUNT, --delete-count=DELETE_COUNT How many expired sessions to delete per iteration. -i ITERATION_COUNT, --iteration-count=ITERATION_COUNT How many iterations to run. --version show program's version number and exit -h, --help show this help message and exit
项目详情
关闭
django-graceful-session-cleanup-0.2.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | c52c665e6804e1bd751951c89457c5c8c96b982ab85395af0d32265d405ccecc |
|
MD5 | 95f452f75801a4a77a9c59c418dce042 |
|
BLAKE2b-256 | 716470258e03e35d675f3856faf6f4d4bf5cb288eef3b7a09fae0886b061eb22 |