大量环回连接可能会减慢我们的速度

大量环回连接可能会减慢我们的速度

我正在尝试调试平均负载突然增加的问题。我查看了页面来查看我们是否遭受了 DDoS 攻击,但突出的 IP 地址是环回地址:

$ netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
...
3893 127.0.0.1

为了找出原因,我查看了我的 PostgreSQL 连接lsof -i | grep postgresql

pgbouncer  9751 postgres   42u  IPv4 83453387      0t0  TCP localhost:57025->localhost:postgresql (ESTABLISHED)
pgbouncer  9751 postgres   43u  IPv4 83479251      0t0  TCP localhost:34492->localhost:postgresql (ESTABLISHED)
pgbouncer  9751 postgres   44u  IPv4 83453393      0t0  TCP localhost:57028->localhost:postgresql (ESTABLISHED)
postgres   9791 postgres   11u  IPv4 83451361      0t0  TCP localhost:postgresql->localhost:56947 (ESTABLISHED)
postgres   9792 postgres   11u  IPv4 83451366      0t0  TCP localhost:postgresql->localhost:56948 (ESTABLISHED)
postgres   9800 postgres   11u  IPv4 83449299      0t0  TCP localhost:postgresql->localhost:56954 (ESTABLISHED)
postgres   9815 postgres   11u  IPv4 83452202      0t0  TCP localhost:postgresql->localhost:56962 (ESTABLISHED)
postgres   9816 postgres   11u  IPv4 83448763      0t0  TCP localhost:postgresql->localhost:56965 (ESTABLISHED)
postgres   9817 postgres   11u  IPv4 83448768      0t0  TCP localhost:postgresql->localhost:56967 (ESTABLISHED)
postgres   9820 postgres   11u  IPv4 83448776      0t0  TCP localhost:postgresql->localhost:56970 (ESTABLISHED)
postgres   9821 postgres   11u  IPv4 83453105      0t0  TCP localhost:postgresql->localhost:56971 (ESTABLISHED)
postgres   9822 postgres   11u  IPv4 83453107      0t0  TCP localhost:postgresql->localhost:56975 (ESTABLISHED)
postgres   9825 postgres   11u  IPv4 83453109      0t0  TCP localhost:postgresql->localhost:56979 (ESTABLISHED)
postgres   9831 postgres   11u  IPv4 83449334      0t0  TCP localhost:postgresql->localhost:56987 (ESTABLISHED)
postgres   9836 postgres   11u  IPv4 83448808      0t0  TCP localhost:postgresql->localhost:56994 (ESTABLISHED)
postgres   9841 postgres   11u  IPv4 83448812      0t0  TCP localhost:postgresql->localhost:57003 (ESTABLISHED)
postgres   9842 postgres   11u  IPv4 83446596      0t0  TCP localhost:postgresql->localhost:57010 (ESTABLISHED)
postgres   9843 postgres   11u  IPv4 83453388      0t0  TCP localhost:postgresql->localhost:57025 (ESTABLISHED)
postgres   9844 postgres   11u  IPv4 83453394      0t0  TCP localhost:postgresql->localhost:57028 (ESTABLISHED)
postgres  10489 postgres   11u  IPv4 83479252      0t0  TCP localhost:postgresql->localhost:34492 (ESTABLISHED)

ps aux | grep <PID>当我对此列表中的某些 PID执行操作时,我通常会得到如下结果:

$ ps aux | grep 14010
postgres 14010 11.8  1.9 4191632 318244 ?      Ss   12:25   0:09 postgres: postgres mydb 127.0.0.1(58099) idle

这些都意味着什么?这是否意味着我有大量未超时的空闲连接?这可能是导致平均负载过高的原因吗?我正在使用 pgbouncer,但我使用的是默认值server_idle_timeout600,所以我将其更改为 60。

答案1

也许您使用 Postgresql 的应用程序没有正确关闭套接字。如果它是一个动态网站,如果每个页面都打开一个套接字但直到超时才关闭它,您的服务器容量就会超标。

你能检查一下连接到 PostgreSQL 的是什么吗?如果您的网站是 Web 服务器,请检查它是否有大量连接到您的网站

相关内容