简体   繁体   English

樱桃不关闭插座

[英]cherrypy not closing the sockets

I am using cherrypy as a webserver. 我使用cherrypy作为网络服务器。 It gives good performance for my application but there is a very big problem with it. 它为我的应用程序提供了良好的性能,但它有一个非常大的问题。 cherrypy crashes after couple of hours stating that it could not create a socket as there are too many files open: 几个小时之后,由于打开的文件太多而无法创建套接字,因此会发生崩溃:

[21/Oct/2008:12:44:25] ENGINE HTTP Server 
cherrypy._cpwsgi_server.CPWSGIServer(('0.0.0.0', 8080)) shut down    
[21/Oct/2008:12:44:25] ENGINE Stopped thread '_TimeoutMonitor'.    
[21/Oct/2008:12:44:25] ENGINE Stopped thread 'Autoreloader'.    
[21/Oct/2008:12:44:25] ENGINE Bus STOPPED    
[21/Oct/2008:12:44:25] ENGINE Bus EXITING    
[21/Oct/2008:12:44:25] ENGINE Bus EXITED    
Exception in thread HTTPServer Thread-3:    
Traceback (most recent call last):    
  File "/usr/lib/python2.3/threading.py", line 436, in __bootstrap    
    self.run()    
  File "/usr/lib/python2.3/threading.py", line 416, in run   
    self.__target(*self.__args, **self.__kwargs)    
  File "/usr/lib/python2.3/site-packages/cherrypy/process/servers.py", line 73, in 
_start_http_thread    
    self.httpserver.start()    
  File "/usr/lib/python2.3/site-packages/cherrypy/wsgiserver/__init__.py", line 1388, in start
    self.tick()    
  File "/usr/lib/python2.3/site-packages/cherrypy/wsgiserver/__init__.py", line 1417, in tick    
    s, addr = self.socket.accept()    
  File "/usr/lib/python2.3/socket.py", line 167, in accept    
    sock, addr = self._sock.accept()    
error: (24, 'Too many open files')    
[21/Oct/2008:12:44:25] ENGINE Waiting for child threads to terminate..

I tried to figure out what was happening. 我试图弄清楚发生了什么。 My application does not open any file or any socket etc. My file only opens couple of berkeley dbs. 我的应用程序没有打开任何文件或任何套接字等。我的文件只打开几个berkeley dbs。 I investigated this issue further. 我进一步研究了这个问题。 I saw the file descriptors used by my cherrypy process with id 4536 in /proc/4536/fd/ Initially there were new sockets created and cleaned up properly but after an hour I found that it had about 509 sockets that were not cleaned. 我在/ proc / 4536 / fd中看到了我的cherrypy进程使用的文件描述符id为4536 /最初创建并正确清理了新的套接字但是一小时后我发现它有大约509个未清理的套接字。 All the sockets were in CLOSE_WAIT state. 所有套接字都处于CLOSE_WAIT状态。 I got this information using the following command: 我使用以下命令获取此信息:

netstat -ap | grep "4536" | grep CLOSE_WAIT | wc -l

CLOSE_WAIT state means that the remote client has closed the connection. CLOSE_WAIT状态表示远程客户端已关闭连接。 Why is cherrypy then not closing the socket and free the file descriptors? 为什么cherrypy然后关闭套接字并释放文件描述符? What can I do to resolve the problem? 我该怎么做才能解决问题?

I tried to play with the following: 我尝试使用以下内容:

cherrypy.config.update({'server.socketQueueSize': '10'})

I thought that this would restrict the number of sockets open at any time to 10 but it was not effective at all. 我认为这会限制任何时候打开的插座数量达到10个,但它根本没有效果。 This is the only config I have set, so , rest of the configs hold their default values. 这是我设置的唯一配置,因此,其余的配置保持其默认值。

Could somebody throw light on this? 有人会对此有所了解吗? Do you think its a bug in cherrypy? 你认为这是一个樱桃的错误吗? How can I resolve it? 我该如何解决? Is there a way I can close these sockets myself? 有没有办法可以自己关闭这些插座?

Following is my systems info: 以下是我的系统信息:

CherryPy-3.1.0 CherryPy的-3.1.0

python 2.3.4 python 2.3.4

Red Hat Enterprise Linux ES release 4 (Nahant Update 7) 红帽企业Linux ES版本4(Nahant Update 7)

Thanks in advance! 提前致谢!

I imagine you're storing (in-memory) some piece of data which has a reference to the socket; 我想你正在存储(内存中)一些数据,这些数据引用了套接字; if you store the request objects anywhere, for instance, that would likely do it. 例如,如果您将请求对象存储在任何位置,则可能会执行此操作。

The last-ditch chance for sockets to be closed is when they're garbage-collected; 套接字关闭的最后机会是它们被垃圾收集; if you're doing anything that would prevent garbage collection from reaching them, there's your problem. 如果您正在做任何可以防止垃圾收集到达它们的事情,那就是您的问题。 I suggest that you try to reproduce with a Hello World program written in CherryPy; 我建议您尝试使用CherryPy编写的Hello World程序重现; if you can't reproduce there, you know it's in your code -- look for places where you're persisting information which could (directly or otherwise) reference the socket. 如果你不能在那里重现,你知道它在你的代码中 - 寻找你可以(直接或以其他方式)引用套接字的持久信息的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM