Increasing the maximum number of TCP/IP connections in Linux

前端 未结 4 2091
终归单人心
终归单人心 2020-11-22 15:59

I am programming a server and it seems like my number of connections is being limited since my bandwidth isn\'t being saturated even when I\'ve set the number of connections

4条回答
  •  无人共我
    2020-11-22 16:29

    There are a couple of variables to set the max number of connections. Most likely, you're running out of file numbers first. Check ulimit -n. After that, there are settings in /proc, but those default to the tens of thousands.

    More importantly, it sounds like you're doing something wrong. A single TCP connection ought to be able to use all of the bandwidth between two parties; if it isn't:

    • Check if your TCP window setting is large enough. Linux defaults are good for everything except really fast inet link (hundreds of mbps) or fast satellite links. What is your bandwidth*delay product?
    • Check for packet loss using ping with large packets (ping -s 1472 ...)
    • Check for rate limiting. On Linux, this is configured with tc
    • Confirm that the bandwidth you think exists actually exists using e.g., iperf
    • Confirm that your protocol is sane. Remember latency.
    • If this is a gigabit+ LAN, can you use jumbo packets? Are you?

    Possibly I have misunderstood. Maybe you're doing something like Bittorrent, where you need lots of connections. If so, you need to figure out how many connections you're actually using (try netstat or lsof). If that number is substantial, you might:

    • Have a lot of bandwidth, e.g., 100mbps+. In this case, you may actually need to up the ulimit -n. Still, ~1000 connections (default on my system) is quite a few.
    • Have network problems which are slowing down your connections (e.g., packet loss)
    • Have something else slowing you down, e.g., IO bandwidth, especially if you're seeking. Have you checked iostat -x?

    Also, if you are using a consumer-grade NAT router (Linksys, Netgear, DLink, etc.), beware that you may exceed its abilities with thousands of connections.

    I hope this provides some help. You're really asking a networking question.

提交回复
热议问题