V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
Te11UA
V2EX  ›  NGINX

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

  •  
  •   Te11UA · 2020-09-23 09:44:31 +08:00 · 1804 次点击
    这是一个创建于 1283 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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;
        }
    }
    
    

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

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

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

    你可以设置 worker_processes 从 auto 为某个更大的数目,减少 nginx fork worker process 带来的时间开销,再测试并发上传速度。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2882 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 21ms · UTC 13:05 · PVG 21:05 · LAX 06:05 · JFK 09:05
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.