Django Channels + Apache + Docker performance stuck to 10rq/s

Setup

I have configured Django Channels inside a docker container on server Ubuntu 20.04 OVH VPS (8vCore, 16Go RAM). To run django-channels I used daphne. Versions:

Django==3.1.4
channels==3.0.2
daphne==3.0.1

I used Docker-compose with an image for Daphne-Apache, an image for Mysql, an image for Redis.

Issue

I used Locust to check the load performance of the application. When I have more than 10rq/s, the server HTTP response time becomes huge (> 10 sec) and the application becomes unavailable.

Where is the bottleneck? What could improve the performance?

Extra Info

  • Note 1: I have reduced the SQL Querries to very low amount, about 5 per page.
  • Note 2: On the VPS info page, CPU, Mem, bandwidth is not fully used at all.
  • Note 3: I serve static files with Apache Alias, but when the application is overloaded, even static files takes time to load.
  • Note 4: The error I get when there is too much load ConnectionError(ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))

I've searched and found out using multiples process with supervisord or Kubernetes could help. But I want to be sure everything is normal before evolving to that.

I can share project files docker-compose.yml, routing.py, settings.py but it doesn't seems helpful to me for now.


Solution 1:

Thanks, here the commands output

A) Runned into the root ubuntu running Docker: ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 62405
max locked memory       (kbytes, -l) 65536
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 62405
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

B) Runned into the mysql container: SHOW GLOBAL STATUS LIKE '%open%';

+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| Com_ha_open                | 0     |
| Com_show_open_tables       | 0     |
| Innodb_num_open_files      | 29    |
| Open_files                 | 14    |
| Open_streams               | 0     |
| Open_table_definitions     | 113   |
| Open_tables                | 114   |
| Opened_files               | 149   |
| Opened_table_definitions   | 113   |
| Opened_tables              | 121   |
| Slave_open_temp_tables     | 0     |
| Table_open_cache_hits      | 25    |
| Table_open_cache_misses    | 121   |
| Table_open_cache_overflows | 0     |
+----------------------------+-------+

C) SHOW GLOBAL VARIABLES LIKE '%open%';

+----------------------------+---------+
| Variable_name              | Value   |
+----------------------------+---------+
| have_openssl               | YES     |
| innodb_open_files          | 2000    |
| open_files_limit           | 1048576 |
| table_open_cache           | 2000    |
| table_open_cache_instances | 16      |
+----------------------------+---------+

D) SHOW GLOBAL STATUS LIKE '%dirty%';

+--------------------------------+-------+
| Variable_name                  | Value |
+--------------------------------+-------+
| Innodb_buffer_pool_pages_dirty | 0     |
| Innodb_buffer_pool_bytes_dirty | 0     |
+--------------------------------+-------+

E) SHOW GLOBAL STATUS LIKE 'uptime';

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Uptime        | 544   |
+---------------+-------+