English 中文(简体)
“ror:[Errno 24] 太多的公开档案错误
原标题:Tornado "error: [Errno 24] Too many open files" error

我与“旋风”合作,但这是我第一次陷入这种错误。 我早就着手进行一项非常基本的“URL”缩短工作。 URLs通过不同的申请被输入数据库,这只是读出了MongoDB仓库中的URLs,并改写客户。 在我撰写了基本法典后,我在大约30秒后对其进行了简单的Siege测试(与siege -c 64 -t 5m -r 1 http://example.com/MKy对4份申请深线进行了试验)。 我开始收到500份答复。 查看错误标识,我看到这一点;

ERROR:root:500 GET /MKy (127.0.0.1) 2.05ms
ERROR:root:Exception in I/O handler for fd 4
Traceback (most recent call last):
  File "/opt/python2.7/lib/python2.7/site-packages/tornado-2.1-py2.7.egg/tornado/ioloop.py", line 309, in start
  File "/opt/python2.7/lib/python2.7/site-packages/tornado-2.1-py2.7.egg/tornado/netutil.py", line 314, in accept_handler
  File "/opt/python2.7/lib/python2.7/socket.py", line 200, in accept
错误:[第24号] 太多的公开档案
ERROR:root:Uncaught exception GET /MKy (127.0.0.1)
HTTPRequest(protocol= http , host= shortener , method= GET , uri= /MKy , version= HTTP/1.0 , remote_ip= 127.0.0.1 , body=  , headers={ Host :  shortener ,  Accept-Encoding :  gzip ,  X-Real-Ip :  94.23.155.32 ,  X-Forwarded-For :  94.23.155.32 ,  Connection :  close ,  Accept :  */* ,  User-Agent :  JoeDog/1.00 [en] (X11; I; Siege 2.66) })
Traceback (most recent call last):
  File "/opt/python2.7/lib/python2.7/site-packages/tornado-2.1-py2.7.egg/tornado/web.py", line 1040, in wrapper
  File "main.py", line 58, in get
  File "main.py", line 21, in dbmongo
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/connection.py", line 349, in __init__
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/connection.py", line 510, in __find_master
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/connection.py", line 516, in __try_node
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/database.py", line 301, in command
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/collection.py", line 441, in find_one
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/cursor.py", line 539, in loop
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/cursor.py", line 560, in _refresh
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/cursor.py", line 620, in __send_message
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/connection.py", line 735, in _send_message_with_response
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/connection.py", line 591, in __stream
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/connection.py", line 200, in get_stream
  File "/opt/python2.7/lib/python2.7/site-packages/apymongo-0.0.1-py2.7-linux-x86_64.egg/apymongo/connection.py", line 559, in __connect
AutoReconnect: could not connect to [( 127.0.0.1 , 27017)]

重要(我猜测);

错误:[第24号] 太多的公开档案

守则(非常简单)

import tornado.ioloop
import tornado.web
import tornado.escape
import apymongo
import time
import sys

#Useful stuff (Connect to Mongo)
class setup(tornado.web.RequestHandler):
    def dbmongo(self):
        if not hasattr(self,  _dbmongo ):
            self._dbmongo = apymongo.Connection("127.0.0.1", 27017)
        return self._dbmongo
        

#Basic method to lookup URLs from Mongo and redirect accordingly
class expand(setup):
    @tornado.web.asynchronous
    def get(self, url):
        self.mongo = self.dbmongo()
        
        #Lookup the URL
        cursor = self.mongo.rmgshortlinks.links.find_one({ short :url}, self.direct)
    
    def direct(self, response):
        if response == None:
            self.send_error(404)
            self.finish()
            return
        
        link = tornado.escape.url_unescape(response[ long ])
        
        #Bounce the client
        self.write("<!DOCTYPE html><html><head><meta charset="UTF-8" /><meta http-equiv="refresh" content="0;URL="+link+""</head><body><a href=""+link+"">Click Here</a></body></html>")
        self.finish();


#Define the URL routes
application = tornado.web.Application([
    (r"/([a-zA-Z0-9]+)", expand)
])

#Start the server
if __name__ == "__main__":
    listening_port = int(sys.argv[1])
    
    if listening_port > 0:
        application.listen(listening_port)
        tornado.ioloop.IOLoop.instance().start()
    else:
        sys.stderr.write("No port specified!")

服务器Im使用有8个核心和64个多彩的记忆,可操作RedHat企业第5栏和第2.6段。 以前,我从未有过“旋风”/Async Mongo”的申请。

可证明有用的信息;

[root@puma ~]# 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) 31374
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
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) 31374
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

(公开档案只定在1024处,但我想这还不够)

是否“旋风”/Apymongo没有适当关闭连接线? 这些申请在NGIS书后面,但利用吉大港山区连接,Apimongo应通过TCP连接,但可能使用记本。 即便如此,它还是应当分享/共享连接?

Edit

按照建议,将 app移至我们的测试服务器之一,其最高公开文件限额为61440,在大约30秒后,同样的错误。

最佳回答

简言之,请求Handler的物体应每一份请求即时发射。 哪一种意思是,你再次储蓄的附庸标在请求Handler(例如,扩大)的标的上。

如果你在蒙博蒙戈(......)的职能中添加一个简单的“印本!” ,你就会看到,它根据全球教育运动的每一项要求创立。

你们需要做的是,把手放在一类物体上,或按需要“全球”上,尽管最好的情况是把它放在“旋风式应用”上。

简单:

class setup(tornado.web.RequestHandler):
    @classmethod
    def dbmongo(cls):
        if not hasattr(cls,  _dbmongo ):
            cls._dbmongo = apymongo.Connection("127.0.0.1", 27017)
        return cls._dbmongo

第二种做法是把它当作一个全球性的文件:

dbmongo_connection = None
def dbmongo():
    if not dbmongo_connection:
        dbmongo_connection = apymongo.Connection("127.0.0.1", 27017)
    return dbmongo_connection

这两种情况都存在同样的问题,即如果你有希望利用非行连接的许多班级,就更难以分享。 由于非行是一个共同实体,你很可能想一一一一一去。

class MongoMixin(object):
    def mongodb(self):
        if not hasattr(self.application,  mongodb ):
            self.application.mongodb = apymongo.Connection(self.application.settings.get("mongohost", "127.0.0.1"), 27017)
        return self.application.mongodb

class expand(tornado.web.RequestHandler, MongoMixin):
    def get(self):
       db = self.mongodb()
问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签