doulei1965 2019-06-25 07:13
浏览 104

大量tcp拨号并发超时超过10000

When the concurrency is raised to more than 10000, I got mass tcp dialog timeout.

$ go version

go version go1.12.1 linux/amd64

$ go env

GOARCH="amd64"
GOBIN="/home/zhoudazhuang/gobin/"
GOCACHE="/home/zhoudazhuang/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/zhoudazhuang/db11/jm/pro"
GOPROXY=""
GORACE=""
GOROOT="/home/zhoudazhuang/usr/local/go1.12.1/go"
GOTMPDIR=""
GOTOOLDIR="/home/zhoudazhuang/usr/local/go1.12.1/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build631445118=/tmp/go-build -gno-record-gcc-switches"

What did I do?

My tested code: Server:

func main() {
    l, err := net.Listen("tcp", ":8888")
    if err != nil {
        log.Println("listen error:", err)
        return
    }

    for {
        c, err := l.Accept()
        if err != nil {
            log.Println("accept error:", err)
            break
        }
        go c.Close()
        // start a new goroutine to handle
        // the new connection.
        //log.Println("accept a new connection")
        //go handleConn(c)
    }
}

Client:

package main

import (
    "fmt"
    "github.com/jessevdk/go-flags"
    "net"
    "os"
    "sync"
    "time"
)

var args struct {
    Addr string `short:"a"  required:"yes" description:"服务端地址"`
    Concurrence int `short:"c"  required:"yes" description:"并发请求数"`
    Count int `short:"t" required:"yes" description:"测试次数"`
}

func main() {
    argParser := flags.NewNamedParser("tcp_test", flags.PassDoubleDash)
    argParser.AddGroup("Mock parameters", "", &args)
    _, err := argParser.Parse()
    if err != nil {
        fmt.Println(err)
        argParser.WriteHelp(os.Stdout)
        os.Exit(1)
    }
    fmt.Printf("测试参数: %+v
",args)
    wg := sync.WaitGroup{}
    for j:=0; j<args.Count;j++ {
        for i:=0; i<args.Concurrence;i++{
            wg.Add(1)
            go func() {
                defer wg.Done()
                time.Sleep(time.Second*5)
                conn, err := net.DialTimeout("tcp", args.Addr, time.Second*3)
                if err != nil {
                    fmt.Printf("dialog err: %+v i为%d:
",err,j)
                    return
                }
                time.Sleep(time.Millisecond*10)
                conn.Close()
            }()
        }
    }
    fmt.Println("start wait")
    wg.Wait()
    fmt.Println("ok")
}

The cmd: ./Test -a 127.0.0.1:8888 -c 10000 -t 3

╰─># cat /proc/sys/net/ipv4/ip_local_port_range
4096 65535 ╰─># ulimit -a

core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 386849
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 10000000
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 1000000
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

What did you expect to see?

no tcp dial timeout.

What did you see instead?

dialog err: dial tcp 127.0.0.1:8888: i/o timeout i为3:
dialog err: dial tcp 127.0.0.1:8888: i/o timeout i为3:
dialog err: dial tcp 127.0.0.1:8888: i/o timeout i为3:
dialog err: dial tcp 127.0.0.1:8888: i/o timeout i为3:

Ref Issue:

issue

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 iqoo11 如何下载安装工程模式
    • ¥15 本题的答案是不是有问题
    • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
    • ¥15 C++使用Gunplot
    • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
    • ¥15 matlab数字图像处理频率域滤波
    • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
    • ¥15 ELGamal和paillier计算效率谁快?
    • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
    • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?