我正在处理大量文件(100m到10g),我使用启用了proxy_request_buffering的nginx并实现了chunked upload。
虽然这样可行,但我打算使用stream_request_body而不是nginx禁用proxy_request_buffering并处理龙卷风中的文件。
龙卷风工作示例代码:
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, stream_request_body, Application
from tornado.httpserver import HTTPServer
@stream_request_body
class Upload(RequestHandler):
def data_received(self, chunk):
pass
def post(self):
self.finish(b'Done')
return None
io_loop = IOLoop.current()
app = Application([
(r'/upload', Upload),
], chunk_size=104857600, max_body_size=10737418240)
http_server = HTTPServer(app, chunk_size=104857600, max_body_size=10737418240, xheaders=True)
http_server.listen(8888)
while True:
try:
io_loop.start()
except KeyboardInterrupt:
break
except Exception as e:
print(e)
finally:
io_loop.stop()
nginx示例配置:
worker_processes auto; # 1 per cpu core
worker_rlimit_nofile 800000;
events {
worker_connections 2048;
use epoll;
multi_accept on;
accept_mutex off;
}
http {
upstream up {
server 127.0.0.1:8888;
}
client_max_body_size 10G;
proxy_request_buffering off;
proxy_send_lowat 3000;
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
access_log off;
location /upload {try_files $uri @proxy_upload;}
location @proxy_upload {
proxy_redirect off;
proxy_pass http://up;
}
}
}
此处的示例代码完全符合我的要求,但是,即使我在data_received方法中什么都不做,cpu对于一个文件(一个上传过程)总是大约50%
我应该如何使用龙卷风来避免如此高的CPU使用率?
我应该更改配置来修复此问题吗?如果是,那么配置是什么?它与Linux有关吗?
龙卷风不能做得这么好吗?那么这个任务的框架是什么?为了完整起见,我用于测试的cpu是Intel(R)Xeon(R)CPU E3-1276 v3 @ 3.60GHz
由于