nginx 和 Mysql 伺服器負載限制(取決於伺服器設定)

nginx 和 Mysql 伺服器負載限制(取決於伺服器設定)

我的伺服器配置是

Technology: Ivy Bridge
Processor:  Intel Xeon E3 1245v2
            Intel Smart Cache: 8MB
Cores:  4
Threads:    8
Frequency:  3.4GHz+
Turbo Boost:    3.8GHz
Virtualization: yes
RAM :        32 GB DDR3
Hard drive: Intel SSD 2 x 120GB
RAID:           SOFT - 0/1
                (RAID-1 by default)
NIC:    GigaEthernet
Bandwidth: 200 Mbps guaranteed 
Version:    Parallels Plesk Panel v11.5.30_build115130819.13 os_CentOS 6
OS: CentOS 6.4 (Final)
Server Soft: Apache \ PHP

現在我需要知道我為 Nginx 設定了什麼(設定我的伺服器需要的最大值)

worker_connections (what i set here);
worker_processes (what i set here);

資料庫

set-variable=max_connections= (what i set here)
set-variable=max_user_connections= (what i set here)

任何其他感謝 mysql、Nginx 和任何其他幫助我控制更多負載請告訴我我真的需要幫助請幫助謝謝

答案1

最後,所有這些值都必須根據您將在 Nginx 和 MySQL 伺服器上運行的內容進行設置,因此沒有靈丹妙藥公式可以回答您的問題並在每種可能的用例中都是正確的。儘管如此,我還是嘗試收集一些數據,以幫助您找到問題的答案:

nginx

關於worker_processesNginx文件說:

If Nginx is doing CPU-intensive work such as SSL or gzipping and you have 2 or
more CPUs/cores, then you may set worker_processes to be equal to the number
of CPUs or cores.

If you are serving a lot of static files and the total size of the files is 
bigger than the available memory, then you may increase worker_processes to 
fully utilize disk bandwidth.

關於worker_connections,考慮我從中得到的這個公式這裡

max_clients = worker_processes * worker_connections

因此,在了解您的worker_processes值後,您可以worker_connections根據您可能需要服務的最大並發客戶端數來計算。

MySQL

關於max_connectionsMySQL 上的值,您應該嘗試計算出在高峰時間 MySQL 上同時需要多少個連線。例如,如果您的應用程式在 PHP 上運行,並且您有 32 個 PHP 工作進程,並且 PHP 是訪問 MySQL 的唯一應用程序,則可以安全地假設您在 MySQL 上不需要超過 32 個連接。你也不想把這個值設定得太高,因為必須為每個連接分配一大堆緩衝區,所以如果這個max_connections值太高,你就會冒著某些東西通過創建到它的連接而殺死你的MySQL 的風險,直到它耗盡了記憶體。

max_user_connections基本上是一樣的,只是針對每個 MySQL 使用者群,而不是整個 MySQL 伺服器的全域值。

如果您還沒有看過它,這裡是相關文件:

最大連線數/最大用戶連線數

相關內容