I have the following bash-function to add static-ip
function add_ip_addr() {
for i in {100..200}
do
ipaddr="100.100.100."$i
command="ip addr add "$ipaddr" dev eth0"
echo $command
$($command)
done
}
And then I have the following Python3-application to create 1M socket connection
import socket
n = 0
sockSet = set()
try :
for I in range(100, 200):
ipaddr = "100.100.100." + str(I)
print("\rProcessing", ipaddr, end="")
for port in range(10000, 20000):
s1=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s1.bind((ipaddr, port))
sockSet.add(s1)
n+=1
except OSError as ex:
# Too many open files in system
if ex.errno == 23:
print("\n"+str(n))
But I always get Too many open files in system
exception with the following ouput
root@c8c1c6a106c2:~/programs/python# python3 socket-limit.py
Processing 100.100.100.163
630730
root@c8c1c6a106c2:~/programs/python#
The ulimit values are as shown below
root@c8c1c6a106c2:~/programs/python# ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 24682
max locked memory (kbytes, -l) 82000
max memory size (kbytes, -m) unlimited
open files (-n) 1048576
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) unlimited
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
root@c8c1c6a106c2:~/programs/python#
The /etc/sysctl.conf
values are as shown below
root@c8c1c6a106c2:~/programs/python# tail -6 /etc/sysctl.conf
fs.file-max = 1048576
fs.nr_open = 1048576
net.ipv4.netfilter.ip_conntrack_max = 1048576
net.nf_conntrack_max = 1048576
root@c8c1c6a106c2:~/programs/python#
What other change do I have to do to achieve 1 million socket connection ?