I am trying to write TCP client-server program, to find the maximum number of concurrent connection handled by server. So I create a simple server and initiated multiple tcp connection (using go routine).
server.go
func main() {
ln, err := net.Listen("tcp", ":9100")
if err != nil {
fmt.Println(err.Error())
}
defer ln.Close()
fmt.Println("server has started")
for {
conn, err := ln.Accept()
if err != nil {
fmt.Println(err.Error())
}
conn.Close()
fmt.Println("received one connection")
}
}
client.go
func connect(address string, wg *sync.WaitGroup) {
conn, err := net.Dial("tcp", address)
if err != nil {
fmt.Println(err.Error())
os.Exit(-1)
}
defer conn.Close()
fmt.Println("connection is established")
wg.Done()
}
func main() {
var wg sync.WaitGroup
for i := 0; i < 10000; i++ {
wg.Add(1)
fmt.Printf("connection %d", i)
fmt.Println()
go connect(":9100", &wg)
}
wg.Wait()
fmt.Print("all the connection served")
}
I was expecting that server will become unresponsive because of TCP SYN attach but my client application got crashed after ~2000 connection request. Following is the error message :
dial tcp :9100: too many open files
exit status 255
I need help for the following questions :
What are the required changes in client.go
to emulate the TCP connection flooding on my go server.
How could I increase the number of open FD (mac OS), if there is limitation of maximum open FD for a precess.
What is the default TCP queue size for the Listen() (in C programming language, queue size is specified in the listen(fd, queue_size)
).
Edit :
ulimit settings
$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 10000
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 709
virtual memory (kbytes, -v) unlimited