gpt4 book ai didi

mysql - Django、nginx 和 uWSGI 缓存结果直到 uWSGI/MySQL 重启

转载 作者:可可西里 更新时间:2023-11-01 08:49:41 28 4
gpt4 key购买 nike

我用 Django 编写了一个服务器应用程序,并使用 Tastypie 为移动应用程序提供 API,并使用本地 MySQL 服务器为数据库提供服务。

在进程被杀死或结束之前,查询似乎被缓存了。如果我在后端创建一个新用户,如果我重新启动 uWSGI 或 MySQL,或者如果我从不同的浏览器登录到后端,它将首先出现在列表中。

Mysql进程列表

41  example localhost:58747   example        13  Sleep                                                                                                                     
42 example localhost:58748 example 16 Sleep

此外,如果我终止处于休眠状态的进程,它也会触发数据刷新。

uWSGI配置

[uwsgi]
vhost = true
plugins = python
socket = /tmp/example.com.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /var/sites/example-server/example/example/wsgi.py
virtualenv = /var/sites/example-server/PYTHON_ENV
chdir = /var/sites/example-server/example
touch-reload = /var/sites/example-server/example/reload

nginx 配置

server {
client_max_body_size 20M;
listen 80;
server_name example.com;
access_log /var/log/nginx/example.com_access.log;
error_log /var/log/nginx/example.com_error.log;

location / {
uwsgi_pass unix:///tmp/example.com.sock;
include uwsgi_params;
}

location /media/ {
alias /var/sites/example-server/example/example/media/;
}

location /static/ {
alias /var/sites/example-server/example/example/static/;
}
}

我的.cnf

[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0

[mysqld]
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
bind-address = 127.0.0.1
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
mysqldump]
quick
quote-names
max_allowed_packet = 16M

[mysql]

[isamchk]
key_buffer = 16M

transaction-isolation = READ-COMMITTED
!includedir /etc/mysql/conf.d/

我该怎么做才能解决这个问题?

干杯莫腾

最佳答案

我有同样的行为并找到了这篇文章 https://plus.google.com/u/0/101898908470597791359/posts/AuMJdgEo93k

在 Django 的 settings.py 中添加这一行(仅 OPTIONS 键):

DATABASES = {
'default': {
'OPTIONS': { "init_command": "SET storage_engine=INNODB, SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED", }
}
}

似乎已经解决了问题。

关于mysql - Django、nginx 和 uWSGI 缓存结果直到 uWSGI/MySQL 重启,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17208659/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com