Increasing the maximum number of TCP/IP connections in Linux

前端 未结 4 2075
终归单人心
终归单人心 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:08

    To improve upon the answer given by derobert,

    You can determine what your OS connection limit is by catting nf_conntrack_max.

    For example: cat /proc/sys/net/netfilter/nf_conntrack_max

    You can use the following script to count the number of tcp connections to a given range of tcp ports. By default 1-65535.

    This will confirm whether or not you are maxing out your OS connection limit.

    Here's the script.

    #!/bin/bash
    OS=$(uname)
    
    case "$OS" in
        'SunOS')
                AWK=/usr/bin/nawk
                ;;
        'Linux')
                AWK=/bin/awk
                ;;
        'AIX')
                AWK=/usr/bin/awk
                ;;
    esac
    
    netstat -an | $AWK -v start=1 -v end=65535 ' $NF ~ /TIME_WAIT|ESTABLISHED/ && $4 !~ /127\.0\.0\.1/ {
        if ($1 ~ /\./)
                {sip=$1}
        else {sip=$4}
    
        if ( sip ~ /:/ )
                {d=2}
        else {d=5}
    
        split( sip, a, /:|\./ )
    
        if ( a[d] >= start && a[d] <= end ) {
                ++connections;
                }
        }
        END {print connections}'
    

提交回复
热议问题