我有一个迁移到新环境的Wordpress/Woocommerce站点。我将我的ec2实例从传统的m4.10xlarge升级到新的m5.8xlarge。一些主要的区别是旧的机器是在旧的传统Linux 1和php 7.2上,而新机器是在Linux 2和php 7.4上,我在Amazon RDS上复制了我的数据库,将它从mysql 5.6升级到5.7。该实例位于一个负载均衡器之后,我将该负载均衡器从旧的传统负载均衡器更改为新的应用程序负载均衡器。
这个环境正在工作,除了现在负载均衡器具有非常高的连接计数,并且RDS具有峰值数据库连接。有时,它们会来自10个DB连接,并随机增加到200-400,然后又下降。在此期间,站点运行速度极慢,有时某些页面会出现504网关超时。

这种行为在我的旧环境中绝对不存在,我已经经历了很多步骤来尝试解决这个问题。通常,我的旧RDS DB连接平均在20左右徘徊。我和亚马逊的技术支持人员通了好几个小时的电话,但他们只是让我与不同的团队沟通,结果却毫无结果。
我尝试调整/etc/httpd/conf/httpd.conf文件,设置我读到的或有人建议的某些值,例如:
KeepAlive On
KeepAliveTimeout 5
MaxKeepAliveRequests 500
TimeOut 300
AcceptFilter http none
AcceptFilter https none <IfModule mpm_prefork_module>
StartServers 300
MinSpareServers 50
MaxSpareServers 100
ServerLimit 1000
MaxRequestWorkers 1000
MaxConnectionsPerChild 10000
</IfModule>我试过调整它们,但没有用。连接仍在激增。我尝试在我的RDS参数组上设置值来限制连接,比如wait_timeout= 10 interactive_timeout = 60和net_write_timeout = 60
我甚至尝试从prefork切换到event模块,并使用php-fpm和快速cgi。每当我切换到使用它时,我的网页很少工作,50%的时间会得到504网关超时错误,所以我又回到了使用prefork模块。
我尝试调优的最后一组设置是/etc/sysctl.conf文件中的一些TCP网络值
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_fin_timeout = 30
# Protect Against TCP Time-Wait
net.ipv4.tcp_rfc1337 = 1
# Decrease the time default value for connections to keep alive
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_probes = 60
net.ipv4.tcp_keepalive_intvl = 20
#Increase TCP max buffer size setable using setsockopt():
net.core.rmem_max = 33554432
net.core.wmem_max = 33554432
#Increase Linux autotuning TCP buffer limits min, default, and max number of bytes to use set max to 16MB for 1GE, and 32M or 54M for 10GE:
net.ipv4.tcp_rmem = 4096 87380 33554432
net.ipv4.tcp_wmem = 4096 65536 33554432
#Determines how much packet processing can be spent among all NAPI structures registered to a CPU
net.core.netdev_budget = 600
#Increased the number of incoming connections backlog queue. This queue sets the maximum number of packets, queued on the INPUT side
net.core.netdev_max_backlog = 3000000
#Increased the limit of the socket listen() backlog, the maximum value that net.ipv4.tcp_max_syn_backlog can take
net.core.somaxconn = 1000000我没有尝试过减少数据库中的这些峰值和负载均衡器上的高连接。当我在我的服务器上运行top时,我有时会看到非常正常和低负载的平均负载,然后它会在我的新机器上的32个内核上变得非常大。我以前见过平均负载高达150,然后又下降了。
我的任何调整或调整都没有在nestat top上产生任何我能注意到的结果。结果仍然是一样的,行为永远不会改变。
如果任何人有任何想法,我可以尝试或研究下一步或任何建议,将不胜感激
发布于 2021-06-03 08:40:13
负载均衡器多久检查一次每台服务器上的活动?您的应用程序的平均响应时间是多少?如果前者比后者长,则是平衡器导致了问题。
您要在多少台服务器之间进行平衡?
乞求“循环”,而不是“聪明”。它更适合低延迟的应用程序。
另一方面,如果你的应用程序对任何查询都需要10秒或更长时间,那么你就需要追求这一点。
https://stackoverflow.com/questions/67813310
复制相似问题