My environment is Mac OS 10.9.2, python3.3, redis-2.6.9 (64-bit).
I have many threads (nealy 2000) that use the same redis instance to write data, but some threads throw the following exceptions:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 250, in connect
sock = self._connect()
File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 268, in _connect
self.socket_timeout)
File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/socket.py", line 417, in create_connecti
on
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno 8] nodename nor servname provided, or not known
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/threading.py", line 901, in _bootstrap_i
nner
self.run()
File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/threading.py", line 858, in run
self._target(*self._args, **self._kwargs)
File "proxypool.py", line 289, in _efficiency_proxy
self.rdb.zadd(db_proxy, time_delay, proxy)
File "/usr/local/lib/python3.3/site-packages/redis/client.py", line 1345, in zadd
return self.execute_command('ZADD', name, *pieces)
File "/usr/local/lib/python3.3/site-packages/redis/client.py", line 464, in execute_command
connection.send_command(*args)
File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 334, in send_command
self.send_packed_command(self.pack_command(*args))
File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 316, in send_packed_command
self.connect()
File "/usr/local/lib/python3.3/site-packages/redis/connection.py", line 253, in connect
raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 8 connecting localhost:6379. nodename nor servname provided, or not known.
Is there some way to solve this problem?
I tried to connect to redis server when this exception happens and use ulimit -n
to set a larger number, but the two methods don't work.
I know why this happened. It's caused by the max number of connections to redis-server and it's related to the max number of file handlers that the OS sets.
If I set:
$ ulimit -n 1024
it works.