当并发度提高到10000以上时,我得到了大量tcp对话框超时。
go版本go1.12.1 linux / amd64
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"
我测试过的代码: 服务器:
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)
}
}
客户:
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\n",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:\n",err,j)
return
}
time.Sleep(time.Millisecond*10)
conn.Close()
}()
}
}
fmt.Println("start wait")
wg.Wait()
fmt.Println("ok")
}
该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
核心文件大小(块,-c)0
数据段大小(千字节,-d)无限
调度优先级(-e)0
文件大小(块,-f)无限
待处理信号(-i)386849
最大锁定内存(千字节,-l)64
最大内存大小(千字节,-m)无限制
打开文件(-n)10000000
管道大小(512字节,-p)8
POSIX消息队列(字节,-q)819200
实时优先级(-r)0
堆栈大小(KB,-s)10240
cpu时间(秒,-t)无限
最大用户进程(-u)1000000
虚拟内存(千字节,-v)无限
文件锁(-x)无限
没有tcp拨号超时。
对话框错误:拨打tcp 127.0.0.1:8888:I / O超时i为3:
对话框错误:拨打tcp 127.0.0.1:8888:I / O超时i为3:
对话框错误:拨打tcp 127.0.0.1:8888:I / O超时i为3:
对话框错误:拨打tcp 127.0.0.1:8888:I / O超时i为3: