gpt4 book ai didi

php - Nginx+php5-fpm+varnish+APC 上的 Wordpress 高 CPU 和内存使用率

转载 作者:行者123 更新时间:2023-12-03 17:45:32 25 4
gpt4 key购买 nike

经过数天的调试和设置调整,我已经精疲力尽,无法找到解决方案。请指导。

我在DigitalOcean上具有以下服务器:

64GB Memory
8 Core processor
200GB SSD drive

而且我正在其上运行单个Wordpress网站。网站流量很高。 (2000至3000个并发实时用户)并且我敢肯定,由于我的设置不正确,我失去了流量并且无法为用户提供页面。我希望实时用户为5000+,但始终保持在2000左右。

我经常收到OOM错误,并且由于 mysqlphp5-fpm被杀死而导致站点关闭。如果我调整 php-fpmnginx,则会收到 502503错误。或者我收到 upstream timed out (110: Connection timed out)'FastCGI sent in stderr: PHP message: PHP Fatal error: Maximum execution time of 30 seconds exceeded错误。

现在,我对设置进行了调整,以使我没有任何错误,但是访问量已下降到大约1500个并发用户,并且拒绝增加流量。因此,我确定我的设置中有问题。
/etc/php5/fpm/pool.d/www.conf设置:
pm = dynamic
pm.max_children = 150
pm.start_servers = 40
pm.min_spare_servers = 30
pm.max_spare_servers = 50
pm.max_requests = 1000

FastCGI设置: /etc/nginx/conf.d/default.conf
location ~ \.php$ {
try_files $uri =404;
# proxy buffers - no 502 errors!
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;

fastcgi_buffers 256 16k;
fastcgi_buffer_size 128k;
fastcgi_max_temp_file_size 0;
fastcgi_intercept_errors on;
fastcgi_keep_conn off;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/dev/shm/php-fpm-www.sock;


}

APC设置: /etc/php5/fpm/php.ini
[apc]
apc.write_lock = 1
apc.slam_defense = 0
apc.shm_size = "1024M"

我注意到 php5-fpm进程占用大量内存。
例如。当我计算每个进程的平均内存时,我得到: ps --no-headers -o "rss,cmd" -C php5-fpm | awk '{ sum+=$1 } END { printf ("%d%s\n", sum/NR/1024,"M") }'为我提供了1100并发流量的 238M

请指导我我的配置不正确的地方。因为我100%确信我的交通阻塞。

附加信息

Nginx配置: /etc/nginx/nginx.conf
worker_processes  24;
worker_rlimit_nofile 20000;


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

但是我注意到服务器上的ulimit是:
ulimit -n仅显示 1024。这和我的问题有关吗?

Daniel回应后添加了VCL
# This is a basic VCL configuration file for varnish.  See the vcl(7)
# man page for details on VCL syntax and semantics.
#
# Default backend definition. Set this to point to your content
# server.
#
backend default {
.host = "127.0.0.1";
.port = "8080";
.connect_timeout = 600s;
.first_byte_timeout = 600s;
.between_bytes_timeout = 600s;
.max_connections = 800;
}


acl purge {
"localhost";
}

sub vcl_recv {
set req.grace = 6h;

# Set X-Forwarded-For header for logging in nginx
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = client.ip;


# Remove has_js and CloudFlare/Google Analytics __* cookies.
set req.http.Cookie = regsuball(req.http.Cookie, "(^|;\s*)(_[_a-z]+|has_js)=[^;]*", "");
# Remove a ";" prefix, if present.
set req.http.Cookie = regsub(req.http.Cookie, "^;\s*", "");



# Either the admin pages or the login
if (req.url ~ "/wp-(login|admin|cron)") {
# Don't cache, pass to backend
return (pass);
}

# Remove the wp-settings-1 cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", "");

# Remove the wp-settings-time-1 cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", "");

# Remove the wp test cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", "");

# Static content unique to the theme can be cached (so no user uploaded images)
# The reason I don't take the wp-content/uploads is because of cache size on bigger blogs
# that would fill up with all those files getting pushed into cache
if (req.url ~ "wp-content/themes/" && req.url ~ "\.(css|js|png|gif|jp(e)?g)") {
unset req.http.cookie;
}

# Even if no cookies are present, I don't want my "uploads" to be cached due to their potential size
if (req.url ~ "/wp-content/uploads/") {
return (pass);
}

# Check the cookies for wordpress-specific items
if (req.http.Cookie ~ "wordpress_" || req.http.Cookie ~ "comment_") {
# A wordpress specific cookie has been set
return (pass);
}



# allow PURGE from localhost
if (req.request == "PURGE") {
if (!client.ip ~ purge) {
error 405 "Not allowed.";
}
return (lookup);
}


# Force lookup if the request is a no-cache request from the client
if (req.http.Cache-Control ~ "no-cache") {
return (pass);
}
# Try a cache-lookup
return (lookup);

}

sub vcl_fetch {
#set obj.grace = 5m;
set beresp.grace = 6h;

}

sub vcl_hit {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}

sub vcl_miss {
if (req.request == "PURGE") {
purge;
error 200 "Purged.";
}
}

最佳答案

有了这种流量和这种配置,您就失去了很多机会(和收入):)。您真的应该动手使用Nginx微缓存和Varnish!

关于php - Nginx+php5-fpm+varnish+APC 上的 Wordpress 高 CPU 和内存使用率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39476976/

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