Memcache间歇性错误

3

希望能得到关于以下间歇性Memcache连接失败可能原因的建议:

Memcache::connect(): Server 127.0.0.1 (tcp 11211, udp 0) failed with: 
Only one usage of each socket address (protocol/network address/port) is normally permitted.

据我观察,PHP脚本只在构建控制器时尝试打开连接,即没有多次尝试打开连接。错误报告出现在尝试打开连接的唯一位置。
我还查看了memcached统计信息,似乎没有问题:
array(36) {
  ["pid"]=> string(4) "5788"
  ["uptime"]=> string(6) "731274"
  ["time"]=> string(10) "1533137924"
  ["version"]=> string(16) "1.4.5_4_gaa7839e
  ["pointer_size"]=> string(2) "64"
  ["curr_connections"]=> string(1) "2"
  ["total_connections"]=> string(8) "31881420"
  ["connection_structures"]=> string(3) "163"
  ["cmd_get"]=> string(8) "26219501"
  ["cmd_set"]=> string(8) "17532714"
  ["cmd_flush"]=> string(4) "1110"
  ["get_hits"]=> string(8) "25834764"
  ["get_misses"]=> string(6) "384737"
  ["delete_misses"]=> string(1) "5"
  ["delete_hits"]=> string(7) "1252043"
  ["incr_misses"]=> string(1) "0"
  ["incr_hits"]=> string(1) "0"
  ["decr_misses"]=> string(1) "0"
  ["decr_hits"]=> string(1) "0"
  ["cas_misses"]=> string(1) "0"
  ["cas_hits"]=> string(1) "0"
  ["cas_badval"]=> string(1) "0"
  ["auth_cmds"]=> string(1) "0"
  ["auth_errors"]=> string(1) "0"
  ["bytes_read"]=> string(11) "12021422144"
  ["bytes_written"]=> string(12) "163830241155"
  ["limit_maxbytes"]=> string(10) "4294967296"
  ["accepting_conns"]=> string(1) "1"
  ["listen_disabled_num"]=> string(1) "0"
  ["threads"]=> string(1) "4"
  ["conn_yields"]=> string(1) "0"
  ["bytes"]=> string(8) "89537575"
  ["curr_items"]=> string(5) "15811"
  ["total_items"]=> string(7) "2871704"
  ["evictions"]=> string(1) "0"
  ["reclaimed"]=> string(6) "570282"
}

如果系统运行在Windows Server上,则会影响某些事情。

1个回答

1

这篇文章似乎解决了这个问题。

这意味着你正在耗尽机器上所有可用的网络端口。默认情况下,操作系统只有大约4000个未被系统保留的可用端口。当任何网络连接关闭时,它会进入240秒的TIME_WAIT状态,并且在此等待状态结束之前不能被重用。因此,例如,如果每秒有16个连接持续4分钟(16 * 4 * 60 = 3840),则很快就会耗尽所有端口。现在,如果您在同一台机器上拥有HAS和MTA,则会更快地耗尽,因为除了它们相互通信使用2个端口(一个用于MTA,一个用于HAS)外,MTA发送邮件时使用大量端口。

解决方案如下:

您可以通过修改以下值来解决此问题。
  1. 其中一种方法是增加动态端口范围。默认最大值为5000,您可以将其设置为65534。 HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\MaxUserPort 是要使用的键。

  2. 另一件事是,一旦连接进入 TIME_WAIT 状态,您可以减少它在该状态下的时间。默认值为4分钟,但您可以将其设置为30秒。 HKLM\System\CurrentControlSet\Services\Tcpip\Parameters\TCPTimedWaitDelay 是要使用的键。

进行这些更改后,必须重新启动系统。

如果这些方法都无效,请尝试使用 resmon(一个鲜为人知的 Windows 资源监视器)检查端口使用情况以查找冲突服务。您可以从 Cortana 搜索框或命令 shell 中访问它...

(我想为此声称功劳,但这是一个团队合作!)

最后,当你连接到 Memcache 时,检查使用 connect 方法返回的结果来确定连接是否成功。如果使用 Memcache::add_server 方法,则可能需要采用不同的方法,因为此方法仅在第一次访问 memcache 时才会发现连接失败。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接