나는 토네이도를 꽤 많이 사용해 왔지만, 이런 종류의 오류가 발생한 것은 이번이 처음입니다. 나는 매우 기본적인 URL 단축키를 작업 해왔다. URL은 다른 응용 프로그램에 의해 데이터베이스에 저장됩니다.이 URL은 MongoDB 저장소에서 URL을 읽고 클라이언트를 리디렉션합니다. 기본 코드를 작성한 후 간단한 Siege 테스트를 설정 한 후 약 30 초 동안 포위 공격 (siege -c 64 -t 5m -r 1 http://example.com/MKy
을 4 개의 응용 프로그램 스레드에 대해 실행)을 실행 한 후 500 개의 응답을 받기 시작했습니다. 오류 로그를보고 나는 이것을 보았다.토네이도 "오류 : [Errno 24] 열린 파일이 너무 많음"오류
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
error: [Errno 24] Too many open files
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)]
중요 (추측);
error: [Errno 24] Too many open files
코드는;
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!")
내가 사용하고 dev에 서버는 레드햇 엔터프라이즈 리눅스 5와 파이썬 2.6을 실행하는 8 개 코어 및 64 기가 바이트 메모리를 가지고 (그것은 매우 간단합니다). 이전에는 Tornado/Async Mongo 응용 프로그램과 관련해서 이런 종류의 문제를 겪어 보지 못했습니다.
아마도 유용한 정보입니다.
[[email protected] ~]# 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가 연결을 제대로 종료되지 않는 이유는 무엇입니까? 응용 프로그램은 NGINX 뒤에 있지만 HTTP를 사용하여 연결합니다. Apymongo는 TCP를 통해 연결해야하지만 소켓을 사용해야합니다. 그럼에도 불구하고 공유/연결 풀링이 있어야하지 않습니까?
편집 제안으로
는 포위에서 실행되는 약 30 초 후에 61440의 최대 열린 파일 제한, 같은 오류와 함께 우리의 테스트 서버 중 하나에 응용 프로그램을 이동했다.
가능한 경우, 메타 새로 고침 태그가있는 HTML을 보내지 마십시오. 요청을 리디렉션하는 올바른 방법은 HTTP 301 또는 302 응답입니다. –
@ThomasK 우리가 그렇게하는 이유는 여러 가지가 있습니다. 주된 이유는 참조 헤더를 보존/덮어 쓰는 것입니다. 트위터의 t.co는 클라이언트에 따라 비슷한 일을합니다 (CURL-ing a t을 시도하십시오.진짜 URL을 가진 co URL) – Smudge
해결책은 여기에 있습니다 : http://stackoverflow.com/questions/2569620/socket-accept-error-24-to-many-open-files –