1

我有一个使用 python+django+fastcgi(flup)+mysql+redis 构建的 Web 服务。

但它总是偶尔会引发一些异常,例如OperationalError: (2001, "Can't create UNIX socket (24)")ConnectionError: Error 24 connecting 10.160.94.231:6379. Too many open files.

日志文件显示如下:

2012-08-19 12:36:36,322 ERROR Internal Server Error: /xxxx
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
  File "/xxxxxx/push_notifi/models.py", line 60, in get_device_token
  File "/usr/lib/python2.6/site-packages/redis-2.4.12-py2.6.egg/redis/client.py", line 773, in sadd
  File "/usr/lib/python2.6/site-packages/redis-2.4.12-py2.6.egg/redis/client.py", line 283, in execute_command
  File "/usr/lib/python2.6/site-packages/redis-2.4.12-py2.6.egg/redis/connection.py", line 260, in send_command
  File "/usr/lib/python2.6/site-packages/redis-2.4.12-py2.6.egg/redis/connection.py", line 243, in send_packed_command
  File "/usr/lib/python2.6/site-packages/redis-2.4.12-py2.6.egg/redis/connection.py", line 191, in connect
ConnectionError: Error 24 connecting 10.160.94.231:6379. Too many open files.
2012-08-19 12:38:54,942 ERROR Internal Server Error: xxxxx
Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/django/core/handlers/base.py", line 111, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/xxxxxx/users_stat/views.py", line 85, in receiver
    saveUser(user)
  File "/xxxxxx/users_stat/models.py", line 86, in saveUser
  File "/xxxxxxx/users_stat/models.py", line 46, in syncVersionToPushService
  File "/xxxxxxx/utility/db_access.py", line 37, in execNonQuery
  File "/usr/lib/python2.6/site-packages/MySQLdb/__init__.py", line 81, in Connect
  File "/usr/lib/python2.6/site-packages/MySQLdb/connections.py", line 187, in __init__
OperationalError: (2001, "Can't create UNIX socket (24)")

我认为这可能是由某种文件描述符泄漏引起的,但我使用redis.Redis连接 redis 并将 redis 连接超时设置为 100 秒。

在 mysql 连接中,我在每次查询后都调用了cursor.close()and 。db.close()我真的不知道 fd 泄漏发生在哪里。

我也检查了cat /proc/sys/fs/file-nr,总是有足够的文件描述符。喜欢:

2272    0   170019

你对此有什么想法吗?

4

0 回答 0