Zend certified PHP/Magento developer

Serving static file from Nginx on localhost cannot exceed 10MB/s

I was experimenting with static file serving. So picked up the simplest possible setup.

In /etc/hosts I added (127.0.0.1 mysite.test)

I created a vhost in nginx and placed a single file in the folder (test.mkv ~ 3.5G)

I started hitting it

  1. Chrome – started very slow, within 15 sec picked up speed spiked at 13MB/s with average 8MB/s
  2. JDownloader – started at 1.6MB/s quickly climbed to 8MB/s and for the next 2 minutes it was playing between 9-14MB/s)
  3. Custom PHP script running in docker – in 2 minutes it slowly increased speed from 1.2MB/s to 8MB/s)
  4. wget – started very slow, after about 15sec hit speeds of 14MB-16MB/s

Given it is localhost I was expecting to easily max out over 1GB/s.

Here’s my nginx configuration (running on a MacBook pro with intel chip)

Nginx Main config

worker_processes  4;
events {
    worker_connections  1024;
    multi_accept on;
}
http {
    server_names_hash_max_size 1024;
    server_names_hash_bucket_size 128;

    fastcgi_buffers 32 4096k;
    fastcgi_buffer_size 2048k;
    proxy_buffering off;

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

    # Max File Upload Size (also needs to be set in php.ini)
    client_max_body_size 120M;

    gzip off;
    open_file_cache max=200000 inactive=20s;
    open_file_cache_valid 30s;
    open_file_cache_min_uses 2;
    open_file_cache_errors on;
    sendfile    on;
    tcp_nodelay on;
    tcp_nopush  on;
    keepalive_timeout  30;
    reset_timedout_connection on;

Nginx static file serving config (has some CORS stuff inside also but they shouldn’t be affecting the streaming of a single file)

server {
    listen 80;
    listen 38888 default;
    server_name mysite.test;
    root /at/some/folder;

    sendfile on;
    aio off;
    output_buffers 1 2m;
    keepalive_timeout 15;
    send_timeout 30s;
    tcp_nopush on;
    tcp_nodelay on;
    client_max_body_size 102400m;
    reset_timedout_connection on;

    location / {
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, HEAD' always;
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
            add_header 'Access-Control-Max-Age' 1728000;
            add_header 'Content-Type' 'text/plain; charset=utf-8' always;
            add_header 'Content-Length' 0 always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
            return 204;
        }

        if ($request_method = 'GET') {
            add_header 'Access-Control-Allow-Origin' '*' always;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, HEAD' always;
            add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range' always;
            add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always;
            add_header 'Access-Control-Allow-Credentials' 'true' always;
         }

         try_files $uri $uri/ = 404;
    }
}

Can anyone suggest how to improve the static file serving on localhost?