gpt4 book ai didi

php - php-fpm 的负载平均/性能问题

转载 作者:行者123 更新时间:2023-11-29 09:42:24 24 4
gpt4 key购买 nike

当用户加载网站时(大约 3000 个在线用户),我遇到了很大的性能错误。我有nginx+php-fpm。当我有一些在线(~3k)php 时,会产生大量进程。然后平均负载达到 200+。拥有 128GB RAM 和 32 个核心。之后,mane 用户出现 502 错误。它有助于重新启动 php-fpm,但时间不会太长,进程会再次倍增,负载也会增加。

尝试了不同的 php 最大子值。

php.ini :
engine = On
short_open_tag = On
asp_tags = Off
precision = 14
output_buffering = Off
zlib.output_compression = Off
implicit_flush = Off
serialize_precision = 17
expose_php = Off
max_execution_time = 1000
max_input_time = 0
max_input_vars = 10000
error_reporting = E_ERROR
error_reporting =
display_errors = Off
display_startup_errors = On
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = On
ignore_repeated_source = Off
report_memleaks = On
track_errors = On
html_errors = On
error_log = /var/log/php-fpm/php-errors.log
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 100M
default_mimetype = "text/html"
default_charset = "UTF-8"
enable_dl = Off
file_uploads = On
upload_tmp_dir =/tmp/php/uploads
upload_max_filesize = 200M
max_file_uploads = 50
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60000
extension=memcache.so
extension=memcached.so
zend_extension=ioncube_loader_lin_7.1.so
cli_server.color = On
date.timezone = "Europe/Kiev"
SMTP = localhost
smtp_port = 25
sendmail_path="/usr/sbin/sendmail -t -i"
mail.add_x_header = On
mail.log =/var/log/php-fpm/php-mail.log
sql.safe_mode = Off
mysql.allow_local_infile = On
mysql.allow_persistent = On
mysql.cache_size = 2000
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 3
mysql.trace_mode = Off
mysqli.max_persistent = -1
mysqli.allow_persistent = On
mysqli.max_links = -1
mysqli.cache_size = 2000
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
mysqlnd.collect_statistics = On
mysqlnd.collect_memory_statistics = On
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
session.save_handler = files
session.save_path = "/tmp/php/sessions"
session.use_cookies = 1
;session.cookie_secure =
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 1440
session.bug_compat_42 = On
session.bug_compat_warn = On
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
tidy.clean_output = Off
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
soap.wsdl_cache_limit = 5
ldap.max_links = -1

ngix.conf:
worker_processes 32;
worker_rlimit_nofile 200000;
load_module "modules/ngx_http_geoip_module.so";

events {
worker_connections 8000;
use epoll;
multi_accept on;
}

http {
ssl_session_cache shared:SSL:100m;
ssl_session_timeout 1h;
include mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites/*;
server_tokens off;
sendfile on;
keepalive_timeout 65;
keepalive_requests 1000; ###
reset_timedout_connection on; ###
open_file_cache max=200000 inactive=20s; #####
open_file_cache_valid 30s; ####
open_file_cache_min_uses 2; ###
open_file_cache_errors on; ###
client_body_timeout 10; ###
send_timeout 2; ###
chunked_transfer_encoding off;
server_names_hash_max_size 1024;
server_names_hash_bucket_size 256;
client_max_body_size 128m;
proxy_send_timeout 6000;
proxy_read_timeout 600;
large_client_header_buffers 16 32k;
tcp_nodelay on;
tcp_nopush on; ####
include cloudflare;

#Compression.
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 8;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;


}

fpm.conf:
listen = 127.0.0.1:9001
user = website
group = website
request_slowlog_timeout = 3s
listen.allowed_clients = 127.0.0.1
pm = ondemand
pm.max_children = 4000
pm.start_servers = 5
pm.min_spare_servers = 5
pm.process_idle_timeout = 1s
pm.max_requests = 0
listen.backlog = 8193
pm.status_path = /php-status.html
request_terminate_timeout = 90s
rlimit_files = 131072
rlimit_core = unlimited
catch_workers_output = yes
env[HOSTNAME] = $HOSTNAME
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
catch_workers_output = yes
php_flag[display_errors] = on
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on

有人可以帮忙处理conf 文件吗?也许出了什么问题。他是很久以前创造的,不是我创造的。

最佳答案

此时,您的问题与 PHP 配置无关,恕我直言,您的问题与可扩展性有关。

我想,您没有提到您的服务器是有状态的还是无状态的,因为您的问题是它是有状态的。另外,您没有解释是否有具有负载平衡功能的服务器集群,但我认为您没有。

这是什么意思?

这意味着您的服务器为每个用户写入一个文件以将其 session 存储在服务器文件系统中。这个过程非常消耗内存,而且成本高昂。

一个简单的数学计算就能说明你的问题,

您说您有 128G 的 RAM,大约有 3000 个用户,这意味着如果您的 PHP 内存限制为每个用户大约 32M,那么他们会消耗所有可用的 RAM。说实话,2019 年的 Wich 基本上非常低。

解决方案?

对于单台服务器同时3000个用户,应该考虑负载均衡。负载平衡允许您的应用程序在多个服务器之间平衡,具体取决于流量。一开始它涉及大量的设置和配置,但它是可行的。

另一种解决方案是将您的应用程序迁移到无状态应用程序。意味着服务器不知道用户 session ,并且身份验证是通过 token 完成的(JWT 来救援)。如果您的应用程序很大,并且还需要一些工作,那么这个解决方案并不容易解决。

A link了解更多信息(查找 PHP session 的性能和可扩展性部分)

关于php - php-fpm 的负载平均/性能问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56338147/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com