V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
themostlazyman
V2EX  ›  程序员

Java websocket 部署 centos7.6,同时连接 7000 个连接,总是报文件打开过多,有大佬处理过这种高并发吗

  •  
  •   themostlazyman · Feb 5, 2021 · 2945 views
    This topic created in 1907 days ago, the information mentioned may be changed or developed.
    之前修改过 ulimit 的 open file 个数 改成 6w 了,查看进程的占用文件句柄数也是 8000 多。
    Supplement 1  ·  Feb 7, 2021
    open files 设定成 100w 了,另外 net.ipv4.ip_local_port_range = 1024 65535,过了个周六,到现在没出现问题,具体不清楚这哪两个配置生效,因为程序的进程的打开文件数是 8000 多,我估计是本地端口范围这个参数起了作用。
    Supplement 2  ·  Feb 9, 2021
    net.ipv4.ip_local_port_range 这个参数貌似没啥影响,为防止端口占用,改为初始 32768 60999,综上具体原因不明,将 ulimit 中 open files 由 6w 改为 100w 目前没出问题。
    9 replies    2021-02-06 12:47:34 +08:00
    sunnyadamm
        1
    sunnyadamm  
       Feb 5, 2021 via Android
    看下 pam
    byte10
        2
    byte10  
       Feb 5, 2021
    是客户端报错吗?服务端也要设置下啊 openfile 数量。我目前没遇到这样的问题。单机连接 50w,还是很轻松的,并发的大概是 5w 左右,8 核
    themostlazyman
        3
    themostlazyman  
    OP
       Feb 5, 2021
    @byte10 服务端报错,openfile 设置成 6w 多了,客户端再发请求一直 wait 了。
    byte10
        4
    byte10  
       Feb 5, 2021
    @themostlazyman 你先设置一百万。
    themostlazyman
        5
    themostlazyman  
    OP
       Feb 5, 2021
    @byte10 设置了,观察下明天会不会出现相同问题,同时设定了 net.ipv4.ip_local_port_range = 1024 65535
    v2orz
        6
    v2orz  
       Feb 5, 2021
    不只是 openfile,还有 tcp 的几个参数,比如 port reuse 、tw
    不过这几个参数最好你看明白他们的意义,再决定如何调整
    okletswin
        7
    okletswin  
       Feb 5, 2021
    cat /proc/<pid>/limits 确认下程序获得的 openfile 数量配置是否符合预期
    themostlazyman
        8
    themostlazyman  
    OP
       Feb 5, 2021
    @okletswin 确认过了,跟设置的一样
    LinSP
        9
    LinSP  
       Feb 6, 2021
    不如看看报错的时候打开的 fd 数量到底是多少个
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4019 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 10:25 · PVG 18:25 · LAX 03:25 · JFK 06:25
    ♥ Do have faith in what you're doing.