Django:上传太慢了

时间:2016-10-27 06:41:26

标签: django nginx

我有一个在Compute Engine(GCE)中运行的Django应用程序,我的问题是,每次上传一个不大的文件(如1MB)时,上传时间都超过一分钟。这是正常的吗?或者我在代码中的某处错误配置,例如在Nginx中。

我测试了在我的本地和生产网站上传2个图像文件(1.2MB和2.4MB)。

1.2MB

本地:2 -3秒

直播:50-60秒

2.4 MB

本地:5-6秒

直播:1.5 - 2分钟

Python 2.7,带有nginx和uWSGI的Django 1.8

计算引擎实例:n1-standard-2(2个vCPU,7.5 GB内存)

nginx config

server {
    listen 80;
    server_name example.com www.example.com;
    return 301 https://www.example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com www.example.com;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-EDH-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:RSA-RSA-AES256-SHA:AES128-GCM-AES128:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';

    location / {
        include    uwsgi_params;
        uwsgi_pass    unix:/sock/path/application.sock;
        uwsgi_read_timeout 600;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        alias /project/static_path/static/;
    }

    location /media  {
        alias /project/static_path/static/uploads;
    }

    location ~ /.well-known{
        allow all;
    }
}

uwsgi config

[uwsgi]
project_path = /project/path/
chdir = %(project_path)
home = /environment/path/
module = root.wsgi:application
master = true
processes = 5
socket = %(project_path)application.sock
chmod-socket = 666
vacuum = true
uid = current_user
gid = www-data
die-on-term = true
logto = /var/log/uwsgi/app/%n.log

修改

nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
        client_max_body_size 20M;
        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;

        client_header_buffer_size    1k;
        large_client_header_buffers  4 4k;
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";



    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

谢谢!

0 个答案:

没有答案