zoukankan      html  css  js  c++  java
  • 【Jmeter实战】压测后端接口,Cannot assign requested address出现的原因及解决方案(转)

    网上找了下原因,大致上是由于客户端频繁的连服务器,由于每次连接都在很短的时间内结束,导致很多的TIME_WAIT,以至于用光了可用的端 口号,所以新的连接没办法绑定端口,即“Cannot assign requested address”。是客户端的问题不是服务器端的问题。通过netstat,的确看到很多TIME_WAIT状态的连接。

    client端频繁建立连接,而端口释放较慢,导致建立新连接时无可用端口。

    netstat -a|grep TIME_WAIT
    tcp 0 0 e100069210180.zmf:49477 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49481 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49469 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49505 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49547 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49513 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49543 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49571 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49488 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49582 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49476 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49462 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49561 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49259 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49371 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49455 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49572 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49509 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49546 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49539 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49468 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49496 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49313 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49479 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49486 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49452 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49500 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49447 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49580 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49565 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49454 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49499 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49494 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49591 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49566 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49557 e100069202104.zmf.tbs:websm TIME_WAIT
    tcp 0 0 e100069210180.zmf:49495 e100069202104.zmf.tbs:websm TIME_WAIT
     

    解决办法

    执行命令修改如下内核参数 (需要root权限) 

    调低端口释放后的等待时间,默认为60s,修改为15~30s:

    sysctl -w net.ipv4.tcp_fin_timeout=30

    修改tcp/ip协议配置, 通过配置/proc/sys/net/ipv4/tcp_tw_resue, 默认为0,修改为1,释放TIME_WAIT端口给新连接使用:

    sysctl -w net.ipv4.tcp_timestamps=1

    修改tcp/ip协议配置,快速回收socket资源,默认为0,修改为1:

    sysctl -w net.ipv4.tcp_tw_recycle=1

    允许端口重用:

    sysctl -w net.ipv4.tcp_tw_reuse = 1
    ————————————————
    版权声明:本文为CSDN博主「fzhqcjc」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/fzhqcjc/article/details/84924724

  • 相关阅读:
    BFS visit tree
    Kth Largest Element in an Array 解答
    Merge k Sorted Lists 解答
    Median of Two Sorted Arrays 解答
    Maximal Square 解答
    Best Time to Buy and Sell Stock III 解答
    Best Time to Buy and Sell Stock II 解答
    Best Time to Buy and Sell Stock 解答
    Triangle 解答
    Unique Binary Search Trees II 解答
  • 原文地址:https://www.cnblogs.com/conquerorren/p/13093416.html
Copyright © 2011-2022 走看看