Question: http video streaming and nginx ram usage

birdy nginx-forum at nginx.us
Tue Mar 8 08:15:23 MSK 2011


Hi everyone,

I'm using Nginx to forward incoming http requests (from the Internet) to
an Aviosys 9100A+ (low-cost) IP video server.


My Nginx 0.7.64 runs on a small embedded linux device under OpenWRT -
the device has only 13 MB of
free ram when nginx is loaded. The user's http requests get forwarded to
nginx on the OpenWRT box, and nginx
reverse proxies the requests on to the video server over LAN.

The job of nginx is to prevent people on the Internet from changing the
settings of the video server via the http interface - only viewing of
the streams should be allowed! Therefore, nginx acts as a reverse-proxy
and forwards only the allowed URL on to the server. So the viewers of
the stream cannot change the video server's settings via the web
interface, because my nginx config does not forward the "banned" URLs.

It is OK for me for now that e.g. 3 simultaneous viewers consume 3 times
the bandwidth.

[ Just if you are wondering : It is not possible to set a password on
the video server, since I can only disable authentication altogether. It
is a low-cost device and configuration options are very limited. ]


Now here is where I get stuck:

This video server transfers the images to the viewing person's web
browser in one long http response in real-time.

As I wrote, In my setup, I reverse-proxy only the allowed URLs (i.e. the
ones to "get the video") on to the video server with nginx. This works
fine, but nginx seems to buffer the http data that it forwards locally.
So while viewing the video stream, nginx consumes more and more RAM
until the little linux device crashes. 

However, if I stop viewing the stream after 1 or 2 minutes, before RAM
runs out, the memory gets freed again.
I believe it frees the ram because the request is finished.

On a Linux PC server, it all works perfectly. But in order to save
electricity, I would like to use the small linux device.

Has anyone got a hint for me what I could do to stop nginx from keeping
the long request in RAM (this is what I think what happens, at least)?

Any help would be greatly appreciated!




Here is my nginx.conf. 192.168.3.46 Is the IP of the video server.

user  root;
worker_processes  1;

#access_log off;
error_log off;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  10;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    proxy_buffering off;
    proxy_buffer_size 4k;
    proxy_buffers 10 4k;
    proxy_max_temp_file_size 0;

    client_body_buffer_size 4k;
    client_header_buffer_size 1k;
    client_max_body_size 4k;
    large_client_header_buffers 1 1k;



    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

#        location / {
#            root   html;
#            index  index.html index.htm;
#        }


    location /GetStatus.cgi?JsVar=sStatus {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/GetStatus.cgi?JsVar=sStatus;
        } 
    location /Simple/home.htm?IMG {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/Simple/home.htm?IMG;
        }
    location /Simple/home.htm?ATV {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
 #           proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/Simple/home.htm?IMG;
        }


    location /Simple/core.jar {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46:80;
        }


    location /Simple/home.htm {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/Simple/home.htm;
        }


    location /GetData.cgi {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/GetData.cgi;
        }

    location /GetStatus.cgi {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/GetStatus.cgi;
        }



    location /Jpeg/ {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/Jpeg/;
        }

    location /Simple/WinWebLite.cab {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/Simple/WinWebLite.cab;
        }
    location /Simple/bg1.jpg {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/Simple/bg1.jpg;
        }


    location /html/favicon.ico {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/html/favicon.ico;
        }



    location /simple_load.swf {
            proxy_buffering           off;
            proxy_ignore_client_abort off;
            proxy_intercept_errors    on;
            proxy_next_upstream       error timeout invalid_header;
            proxy_redirect            off;
            proxy_set_header          X-Host $http_host;
#            proxy_set_header          X-Forwarded-For $remote_addr;
            proxy_connect_timeout     60;
            proxy_send_timeout        60;
            proxy_read_timeout        60;
            proxy_pass http://192.168.3.46/simple_load.swf;
        }



        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


    }

}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,180840,180840#msg-180840




More information about the nginx mailing list