dongyingtang3803 2018-09-21 10:34
浏览 124

使用PDO和Ubuntu无法正确处理TCP连接

Let me briefly explain you my problem.

The architecture(for the problem) is as follow:

  • 1 Ubuntu 16.04 with Apache 2.4 server; php-fpm 7.2 and Laravel
  • 1 Ubuntu 16.04 with MariaDB v.15.2 distrib 10.2.14 server

The problem that started from couple of days is that web server is throwing this error:

SQLSTATE[HY000] [2002] Cannot assign requested address

What I've found so far:

On MariaDB

  • ~30-40 concurrent connections

    netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n

  • shows average ~800-900 connections in TIME_WAIT status

So far everything seems legit. But on Apache server the findings are as follow:

netstat -nat | awk '{print $6}' | sort | uniq -c | sort -n

  • ~10-12k connections in TIME_WAIT status

When they get > 28k I receive the error mentioned above. That's because the server has ~28k free ports. (range 32768 - 61000). I've changed the range to 10000 - 63000 yesterday and I've changed waiting in TIME_WAIT status to 5 seconds,so far the error stopped. But this is not real solution of the problem.

Questions that I have in mind are:

  1. Does php PDO start DB connection for every user and open TCP connection for every query to DB and reuse created DB connection? If this is true, is it possible to fix this without additional web server ?

  2. Why and how there is such big difference between the connections in TIME_WAIT status on Apache and MariaDB ? Is it a PDO problem that is not closing connections properly ?

Thanks in advance.

P.S.: The connections to MariaDB are not persistent

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭
    • ¥15 2020长安杯与连接网探
    • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么