Tunning PHP-FPM
- Tunning PHP-FPM
+ PHP-FPM can listen on multiple sockets. I also listen on Unix sockets, or TCP sockets.
- Unix socket :
+ PHP-FPM can listen on multiple sockets. I also listen on Unix sockets, or TCP sockets.
- Unix socket :
sử trong trong trường hợp các process kết nối với nhau trên cùng một máy, dẫn đến tốc đô nhanh. Listening sockets live in the filesystem hierarchy and access to them can be controlled by filesystem permissions.
- TCP socket
- TCP socket
Các process có thể kết nối thông qua network. sẽ có tốc độ chậm hơn so với unix socket.
A connected TCP socket is identified by the combination of local IP, local port, remote IP and remote port. A listening TCP socket is identified by local port and possibly local IP.
+ How the process manager will control the number of child processes
A connected TCP socket is identified by the combination of local IP, local port, remote IP and remote port. A listening TCP socket is identified by local port and possibly local IP.
+ How the process manager will control the number of child processes
Tùy vào cấu hình sẽ ảnh hưởng tới RAM and CPU.
+ backlog
backlog is listen queue value is the number of requests pending connections to the pool.
- static :
Nếu lựa chon static thì sẽ có performance tốt nhất, nhưng cũng gây tiêu tốn tài nguyên của
server khi không cần thiết. Nếu server của bạn chỉ phục vụ cho web server thì đây là trường
hợp phù hợp để cấu hình.
- dynamic:
Với lựa chon dynamic sẽ cơ đông hơn so với static , nó cho phép chúng ta giới hạn được số child
process được sử dụng được cung cấp bởi: pm.min_spare_server, pm.max_spare_server.
Chúng ta cần tính toán hợp lý để đảm bào không lãng phí mà hiệu suất được ổn định
- Tính toán giá trị max_children
a. Tính toán mỗi children sẽ chiêm bao nhiêu RAM
ps --no-headers -o "rss,cmd" -C php-fpm7.2 | awk '{ sum+=$1 } END { printf ("%d%s\n",
sum/NR/1024,"Mb") }'
vd: output = 60MB
b. Bạn có 7GB muốn sư dụng cho php-fpm thì giá trị max_children = 7x1024/60=125
- pm.min_spare_servers = 20% of pm.max_children
- pm.max_spare_servers = 60% of pm.max_children
- pm.start_servers = min_spare_servers + (max_spare_servers –
- min_spare_servers) / 2
- pm.max_spare_servers = 60% of pm.max_children
- pm.start_servers = min_spare_servers + (max_spare_servers –
- min_spare_servers) / 2
pm = dynamic
pm.max_children = 75
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 500
- ondemand:
Không có children nào sẽ được tạo ra, và nó được tạo khi nào có request kết nối đến . Giup cho
việc tiết kiêm tài nguyên cho server, nhưng perfomance sẽ không cao so với 2 lựa chon ở trên.
pm = ondemand
pm.max_children = 75
pm.process_idle_timeout = 10s
pm.max_requests = 500
; Choose how the process manager will control the number of child processes.
; Possible Values:
; static - a fixed number (pm.max_children) of child processes;
; dynamic - the number of child processes are set dynamically based on the
; following directives. With this process management, there will be
; always at least 1 children.
; pm.max_children - the maximum number of children that can
; be alive at the same time.
; pm.start_servers - the number of children created on startup.
; pm.min_spare_servers - the minimum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is less than this
; number then some children will be created.
; pm.max_spare_servers - the maximum number of children in 'idle'
; state (waiting to process). If the number
; of 'idle' processes is greater than this
; number then some children will be killed.
; ondemand - no children are created at startup. Children will be forked when
; new requests will connect. The following parameter are used:
; pm.max_children - the maximum number of children that
; can be alive at the same time.
; pm.process_idle_timeout - The number of seconds after which
; an idle process will be killed.
; Note: This value is mandatory.
+ backlog
backlog is listen queue value is the number of requests pending connections to the pool.
Nguyên nhân dẫn tới lỗi như : 502, connet to socket failed => do việc cấu hình baclog không đủ.
Chúng ta sẽ tìm hiểu cấu hình backlog trong php-fpm,
.Giá trị mặc định trong linux là 511.
Để thực hiện điều chinh cho hdh thì cần điểu chinh nội dung /ete/sysctl.conf
Tham khảo : https://kienbv.blogspot.com/2019/08/tunning-linux.html
Conclusion
If you have a dedicated web server, then I would personally use static.
If you have server that does everything (web/db), dynamic would be a better bet.
If you’re running a really poxy server with little memory and you don’t get much traffic or if your application doesn’t take too long to process PHP code, then I suggest you use ondemand.
Tham khao:
https://gurdeep.ninja/php-fpm-process-management/
https://www.cnxct.com/something-about-phpfpm-s-backlog/
Chúng ta sẽ tìm hiểu cấu hình backlog trong php-fpm,
.Giá trị mặc định trong linux là 511.
Để thực hiện điều chinh cho hdh thì cần điểu chinh nội dung /ete/sysctl.conf
Tham khảo : https://kienbv.blogspot.com/2019/08/tunning-linux.html
Conclusion
If you have a dedicated web server, then I would personally use static.
If you have server that does everything (web/db), dynamic would be a better bet.
If you’re running a really poxy server with little memory and you don’t get much traffic or if your application doesn’t take too long to process PHP code, then I suggest you use ondemand.
Tham khao:
https://gurdeep.ninja/php-fpm-process-management/
https://www.cnxct.com/something-about-phpfpm-s-backlog/
https://www.cnblogs.com/ggjucheng/archive/2012/11/01/2750217.html
Trả lờiXóaNcaerePtiogi_1982 Bianca Gutierrez https://wakelet.com/wake/4oLIUUQAs5X14T2Yuyn2B
Trả lờiXóaanabolri
UspirrePrep_po Shannon Baker Microsoft Visio Professional
Trả lờiXóaWonderShare Recoverit
Internet Download Manager
bandmadmipha