nginx upload module 性能差,是我的问题还是设置的问题?

2020-09-23 09:44:31 +08:00
 Te11UA

Python 使用者,对比了一下用 Tornado Fastapi 和 Nginx 做文件上传服务器,在 100+ 并发的情况下测试,发现 Nginx 这个模块只用了 120% 左右的 CPU,而 Python 这些服务可以打满 CPU,从而造成 Nginx 上传速度比 Python 慢 2-3 倍的情况。upload 模块版本为 2.3.0,Nginx 为 1.19.1,upload 的 conf 如下:

server {
    listen 80;

    client_max_body_size 10M;   # 文件传输限制 10M
    upload_buffer_size 10M;     # 文件 buffer 10M

    location /upload {
        upload_pass @after_upload;

        upload_store /storage;
        upload_store_access user:rw group:rw all:r;

        upload_set_form_field $upload_field_name.name "$upload_file_name";
        upload_set_form_field $upload_field_name.content_type "$upload_content_type";
        upload_set_form_field $upload_field_name.path "$upload_tmp_path";

        upload_aggregate_form_field $upload_field_name.md5 "$upload_file_md5";
        upload_aggregate_form_field $upload_field_name.size "$upload_file_size";

        upload_pass_form_field "^.*$";  #

        upload_cleanup 400 404 499 500-505;
    }

    location @after_upload {
        proxy_pass http://filesys_handler:8090;
    }
}

求大佬们能解惑,如果这个模块是因为缺乏支持而这样的话我就要弃用了

1823 次点击
所在节点    NGINX
3 条回复
nonduality
2020-09-23 16:30:34 +08:00
用 nginx upload module 不正是为了减轻 Python 后端的 CPU 占用么?而且能减少 502 超时错误(如果都是小文件另说),哪能拿 CPU 占用率评估上传速度。

以 Nginx 的性能,怎么都轮不到是 Nginx 是速度瓶颈,看看 Nginx 其他部分的配置。有时为了防止上传流量攻击,还需要在 ngxin upload module 加限速指令。
Te11UA
2020-09-23 16:53:47 +08:00
@nonduality 的确是,但是上传速率比 python 慢很多,我的场景主要是 1M 左右,100/s 并发的小文件上传,达不到要求呀
nonduality
2020-09-23 20:24:50 +08:00
如果你直接用 python 后端来接收上传文件,你要考虑 CPU 和内存占用过高的问题,而用 Nginx 则不存在这个问题,从提高运行效率的角度,无论如何都得选择 Nginx 。

你可以设置 worker_processes 从 auto 为某个更大的数目,减少 nginx fork worker process 带来的时间开销,再测试并发上传速度。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/709639

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX