Nginx 和 NodeJs 静态文件服务缓慢

Nginx 和 NodeJs 静态文件服务缓慢

负载下

我有一个小型 NodeJS 应用程序,使用 Nginx 前端来提供静态文件以提高性能。

bundle.js文件在没有加载的情况下大约需要 1 秒,但是,添加一些并发用户,就会bundle.js产生很大的影响!

这是在磨合k8s,但这是一个全新的环境,所以应该不会有其他影响。

CPU 没有峰值,内存使用率处于最低水平,并且我已经尝试了所有常用send_file技巧 - 有什么方法可以在这里获得一些吞吐量吗?

默认配置文件

server {
    listen 80;

    root /mnt/app;
    index index.html index.htm;

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
        expires 365d;
    }

    access_log off;

    open_file_cache          max=2000 inactive=3600s;
    open_file_cache_valid    3600s;
    open_file_cache_min_uses 1;
    open_file_cache_errors   off;

    location /public/ {
        try_files $uri $uri/ =404;
    }

    location /Healthcheck/ {
        proxy_pass http://localhost:8080;
    }

    location /auth/login/ {
        proxy_pass http://localhost:8080;
    }

    location /auth/connect/ {
        proxy_pass http://localhost:8080;
    }

    location /data/ {
        proxy_pass http://localhost:8080;
    }
}

http配置文件

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
 connect-frontend-nginxpid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


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

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

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

    keepalive_timeout  65;

    gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

gzip配置文件

## Compression.
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 1;
gzip_http_version 1.1;
gzip_min_length 10;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript image/x-icon application/vnd.ms-fontobject font/opentype application/x-font-ttf;
gzip_vary on;
gzip_proxied any; # Compression for all requests.
## No need for regexps. See
## http://wiki.nginx.org/NginxHttpGzipModule#gzip_disable
gzip_disable msie6;

## Serve already compressed files directly, bypassing on-the-fly
## compression.
##
# Usually you don't make much use of this. It's better to just
# enable gzip_static on the locations you need it.
# gzip_static on;

根据@Tim的评论-CURL输出:

My Machine

10.244.0.1 - - [07/Jun/2018:08:15:45 +0000] "GET /Public/JS/Auth/bundle.js HTTP/1.1" 200 1007996 "http://51.144.234.135/auth/login/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36" request-time: 0.579 Upstream-time: - .

CURL localhost

127.0.0.1 - - [06/Jun/2018:15:04:37 +0000] "GET /Public/JS/Auth/bundle.js HTTP/1.1" 200 3081261 "-" "curl/7.60.0" "-"

CURL to IP - From host

10.244.0.1 - - [06/Jun/2018:15:04:57 +0000] "GET /Public/JS/Auth/bundle.js HTTP/1.1" 200 3081261 "-" "curl/7.60.0" "-"

相关内容