Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
864 views
in Technique[技术] by (71.8m points)

sockets - Linux Allows Only 99 TCP Connections with a single remote IP

When I try to create more than 99 TCP connections in less than a millisecond from my local computer with a TCP listener running at a DigitalOcean droplet with Ubuntu, only 99 of them works and rest says connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. Sending the same amount of connection requests to multiple ports seem to work okay.

I already tried to increase tcp_max_syn_backlog and somaxconn but it didn't help. I tried to track TcpExtListenOverflows and TcpExtListenDrops but they don't seem to be increasing as well. I tried to do the same thing with another server to make sure the problem is not about my local computer. I also contacted to DigitalOcean support and they told they are not aware of any hard limits placed by their infrastructure.

Can anyone give me any pointers to create more than 99 TCP connections in less than a millisecond with a single port at an Ubuntu server and a single remote IP?

Scripts I'm using:

Listener:

package main

import (
    "log"
    "net"
)

const port = "1919"

func main() {
    listener, err := net.Listen("tcp", ":"+port)
    if err != nil {
        log.Fatal(err)
    }
    for {
        _, err := listener.Accept()
        if err != nil {
            log.Fatal(err)
        }
    }
}

Dialer:

package main

import (
    "fmt"
    "net"
    "sync"
)

const ConnectionCount = 250

const raddr = "<IP_ADDRESS_IS_INSERTED_HERE>:1919"

func main() {
    wg := &sync.WaitGroup{}
    mu := &sync.Mutex{}
    var success, fail int
    for i := 0; i < ConnectionCount; i++ {
        wg.Add(1)
        go func() {
            defer wg.Done()
            _, err := net.Dial("tcp", raddr)
            mu.Lock()
            defer mu.Unlock()
            if err == nil {
                success++
            } else {
                fail++
            }
            fmt.Print("33[2K
Success: ", success, ", Fail: ", fail)
        }()
    }
    wg.Wait()
}

Output is always 99 Success and 151 Fail. Tried to same thing with direct HTTP requests as well, still only 99 of them works if they are sent at the same time.

question from:https://stackoverflow.com/questions/65871454/linux-allows-only-99-tcp-connections-with-a-single-remote-ip

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...