V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
MungBeanSoup

golang 实现的 tcp 服务器 500 个左右并发就出现 connection reset by peer

  •  
  •   MungBeanSoup · Oct 17, 2017 · 3708 views
    This topic created in 3124 days ago, the information mentioned may be changed or developed.

    使用 golang 实现的一个简单的 tcp 服务器,主要就是接收客户端连接然后做 rpc 转发 发现在 500 个连接开始就陆续出现 connection reset by peer,5000 个以上的时候甚至有 60%报错 服务端就启动在本地,由于没有头绪也不知道要给出什么参数 MacBook Pro (Retina, 13-inch, Early 2015) Golang 1.9 有高手指点迷津么

    11 replies    2017-10-19 14:54:15 +08:00
    ChristopherWu
        1
    ChristopherWu  
       Oct 17, 2017
    接收的服务器是怎么实现的? golang 的 rpc 有设置 req.Close 吗?
    可能是服务器关闭了链接,但 golang 复用了之前的链接,所以提示 reset by peer
    MungBeanSoup
        2
    MungBeanSoup  
    OP
       Oct 17, 2017
    @ChristopherWu
    connection reset by peer 不是 rpc 调用的时候报的错,是我自己的 tcp 服务器 RST 了连接
    sagaxu
        3
    sagaxu  
       Oct 17, 2017 via Android
    Transport.MaxIdleConnsPerHost 设置了吗?
    MungBeanSoup
        4
    MungBeanSoup  
    OP
       Oct 18, 2017
    @sagaxu tcp 服务器该怎么设置这个配置
    sagaxu
        5
    sagaxu  
       Oct 18, 2017
    @MungBeanSoup 那要看你的连接池是怎么写的了
    90928yao
        6
    90928yao  
       Oct 18, 2017
    请复用,你看下端口 应该都是 close_wait
    MungBeanSoup
        7
    MungBeanSoup  
    OP
       Oct 18, 2017
    @90928yao 请问 tcp 该如何复用连接
    我搜索都是 http 复用的 tcp 连接
    wcsjtu
        8
    wcsjtu  
       Oct 18, 2017
    @MungBeanSoup SO_REUSEADDR
    petelin
        9
    petelin  
       Oct 18, 2017
    @90928yao close_wait 是服务端没有主动调起 close 吧和复用有什么关系?
    reus
        10
    reus  
       Oct 19, 2017
    ……没代码有什么好说的。
    MungBeanSoup
        11
    MungBeanSoup  
    OP
       Oct 19, 2017
    最后设置服务器的 somaxconn 和 backlog 让连接能上 W 了,接下来看看有没有别的能优化的地方
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   985 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 45ms · UTC 19:09 · PVG 03:09 · LAX 12:09 · JFK 15:09
    ♥ Do have faith in what you're doing.