首页 > 解决方案 > 使用 NGINX 上传图像文件需要很长时间?

问题描述

我正在尝试使用 gunicorn、nginx、flask 和 MySQL 上传一个简单的 .png 图像,但是上传一个 5 mb 的图像需要 10 秒?我正在运行一个 ec2 微实例,但上传时 CPU 使用率低于 30%。

我的烧瓶代码 # 帖子名称为每个图像使用唯一 ID post_name = str(postID) + '_post.png' destination = os.path.join(target, post_name)

    c.execute('UPDATE posts set filename=%s, filetype="picture" 
         where postID=%s', 
              (destination, postID))

    file.save(destination)

我的 nginx 配置

location / {
    include proxy_params;
    client_max_body_size 250M;
    proxy_pass http://127.0.0.1:8000;
    root /home/ubuntu ;
    client_body_buffer_size 8M;
}

标签: nginxflaskgunicorn

解决方案


在声明上传速度很慢之前,请在其他地方进行测试。EC2 带宽取决于实例大小,而 t2.micro 没有太多。请参阅https://cloudonaut.io/ec2-network-performance-cheat-sheet/


推荐阅读