Django Channels + Apache + Docker 效能停留在 10rq/s

Django Channels + Apache + Docker 效能停留在 10rq/s

設定

我已經在伺服器 Ubuntu 20.04 OVH VPS(8vCore,16Go RAM)上的 docker 容器內配置了 Django Channels。為了運行 django-channels,我使用了 daphne。版本:

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

我將 Docker-compose 與 Daphne-Apache 的映像、Mysql 的映像、Redis 的映像一起使用。

問題

我使用 Locust 來檢查應用程式的負載效能。當我超過10rq/s時,伺服器HTTP 回應時間變得巨大(> 10 秒)並且應用程式變得不可用。

瓶頸在哪裡?什麼可以提高效能?

額外資訊

  • 註 1:我已將 SQL 查詢量減少到非常低的數量,大約每頁 5 個。
  • 註2:在VPS資訊頁面上,CPU、Mem、頻寬根本沒有充分利用。
  • 註 3:我使用 Apache Alias 提供靜態文件,但是當應用程式過載時,即使是靜態文件也需要時間來載入。
  • 註4:負載太大時出現的錯誤ConnectionError(ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response')))

我搜尋並發現使用多個進程監督者或者庫伯內斯有幫助。但我想在進化到那樣之前確保一切正常。

我可以共享專案檔案 docker-compose.yml、routing.py、settings.py 但目前對我來說似乎沒有幫助。

答案1

謝謝,這裡是命令輸出

A) 運行到 root ubuntu 運行 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) 跑進mysql容器: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) 顯示全域變量,如“%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) 顯示全域狀態,如「%dirty%」;

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

E) 顯示「正常運作時間」等全球狀態;

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

相關內容