3

I've written a server app in Django and serve an API to a mobile app with Tastypie and serving the DB with a local MySQL server.

It seems like queries are cached until the process is killed or ended. If I create a new user in the backend it will first appear in the list if I restart uWSGI or MySQL or if I log into the backend from a different browser.

Mysql process list

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

Also if I kill the processes which are Sleep'ed it will also trigger a refresh of the data.

uWSGI config

[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 config

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/;
    }
}

my.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/

What can I do to make this problem go away?

Cheers Morten

mbogh
  • 1,361
  • 11
  • 28

1 Answers1

1

I had the same behavior and found this post https://plus.google.com/u/0/101898908470597791359/posts/AuMJdgEo93k

Adding this line on settings.py (only the OPTIONS key) on Django:

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

seems to have resolved the problem.

ThorSummoner
  • 16,657
  • 15
  • 135
  • 147
LGama
  • 561
  • 4
  • 10