python time wait_解决nginx+php/java/go/python+mysql下time_wait连接数过多问题

查看连接数

netstat -n | wc -l # 总连接数

netstat -n | grep -i time_wait | wc -l # time_wait 连接数

netstat -anp # 查看占用端口过多的程序

tcp复用解决方案

网上大部分解决方案是修改sysctl.conf回收重用ipv4连接,但是可能带来其他问题

net.ipv4.tcp_syncookies = 1

net.ipv4.tcp_timestamps=1

net.ipv4.tcp_tw_reuse=1

net.ipv4.tcp_tw_recycle=1

net.ipv4.tcp_fin_timeout=30

net.ipv4.tcp_keepalive_time = 600

nginx fastcgi(php) 解决方案

修改nginx.conf

upstream fastcgi_backend {

server 127.0.0.1:9000;

keepalive 60;

}

location ~ \.php$ {

fastcgi_pass fastcgi_backend;

fastcgi_keep_conn on;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

主要是 fastcgi_keep_conn on 与 upstream 的 keepalive

nginx + proxy (python/go/java) 解决方案

upstream wxpic {

keepalive 60;

server 127.0.0.1:xxx;

}

server {

keepalive_requests 10000; # 默认100

location / {

proxy_http_version 1.1;

proxy_set_header Connection "";

}

}

主要是 proxy_http_version, proxy_set_header Connection ""以及keepalive_requests

mysql/数据库连接解决方案

修改yii数据库配置采用长链接

'db' => [

'class' => 'yii\db\Connection',

'dsn' => '*', 'username' => '*',

'password' => '*',

'charset' => 'utf8mb4',

'attributes' => [

PDO::ATTR_PERSISTENT => true

]

],

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值