带有MPEG-TS流量的清漆 解决问题

问题描述

我们正在尝试使用Varnish作为媒体服务器的代理/缓存。我们的流是基于http的MPEG-TS(h264 / h265)。该媒体服务器上有1000个实时流,每个流都具有多个连接。我们尝试配置如下所示的Varnish,但存在这些问题。

  1. 流在短时间内关闭
  2. 有时无法连接到流,停留在连接中...
  3. 在varnislog上找到了这些错误;
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Resource temporarily unavailable
-   FetchError     eof socket fail
-   FetchError     Resource temporarily unavailable
-   FetchError     eof socket fail
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Could not get storage
-   FetchError     Resource temporarily unavailable
-   FetchError     eof socket fail
-   FetchError     Resource temporarily unavailable
-   FetchError     eof socket fail
-   FetchError     Resource temporarily unavailable
-   FetchError     eof socket fail
-   FetchError     Could not get storage
-   FetchError     Could not get storage

我的配置;

vcl 4.0;

import directors;


backend s6855 {
    .host = "127.0.0.1";
    .port = "6855";
    .first_byte_timeout     = 10s;   # How long to wait before we receive a first byte from our backend?
    .connect_timeout        = 5s;     # How long to wait for a backend connection?
    .between_bytes_timeout  = 30s;     # How long to wait between bytes received from our backend?
}

backend s6866 {
    .host = "127.0.0.1";
    .port = "6866";
    .first_byte_timeout     = 10s;   # How long to wait before we receive a first byte from our backend?
    .connect_timeout        = 5s;     # How long to wait for a backend connection?
    .between_bytes_timeout  = 30s;     # How long to wait between bytes received from our backend?
    }

backend s6877 {
    .host = "127.0.0.1";
    .port = "6877";
    .first_byte_timeout     = 10s;   # How long to wait before we receive a first byte from our backend?
    .connect_timeout        = 5s;     # How long to wait for a backend connection?
    .between_bytes_timeout  = 30s;     # How long to wait between bytes received from our backend?
}

backend s6888 {
    .host = "127.0.0.1";
    .port = "6888";
    .first_byte_timeout     = 10s;   # How long to wait before we receive a first byte from our backend?
    .connect_timeout        = 5s;     # How long to wait for a backend connection?
    .between_bytes_timeout  = 30s;     # How long to wait between bytes received from our backend?
}

backend s6899 {
    .host = "127.0.0.1";
    .port = "6899";
    .first_byte_timeout     = 10s;   # How long to wait before we receive a first byte from our backend?
    .connect_timeout        = 5s;     # How long to wait for a backend connection?
    .between_bytes_timeout  = 30s;     # How long to wait between bytes received from our backend?
}


sub vcl_init {
    new fb = directors.round_robin();
    fb.add_backend(s6855);
    fb.add_backend(s6866);
    fb.add_backend(s6877);
    fb.add_backend(s6888);
    fb.add_backend(s6899);

}


sub vcl_recv {

    set req.grace = 120s;

    set req.backend_hint = fb.backend();

    if (req.url ~ "(\.ts)" ) {
    unset req.http.Range;
    }
    if (req.http.cookie) {
        unset req.http.cookie;
    }

    if (req.method != "GET" && req.method != "HEAD") {
    return (pipe);
    }

    if (req.method == "GET" && req.url ~ "(\.ts)"  ) {
        unset req.http.Accept-Encoding;
        return(hash);
    }
return(hash);
}

sub vcl_hash {
    hash_data(req.url);
    return(lookup);
}

sub vcl_backend_response {
    set beresp.grace = 2m; 
    set beresp.ttl = 120s;
    set beresp.do_gunzip = false;
    set beresp.do_gzip = false;

    if (bereq.url ~ "(\.ts)") {
    set beresp.ttl = 60s;
    set beresp.http.X-Cacheable = "YES";
    }

                else    {
    set beresp.ttl = 10m;
    set beresp.http.X-Cacheable = "NO";
    }

    if ( beresp.status == 404 ) {
    set beresp.ttl = 5m;
    }
 
    return(deliver);
}


sub vcl_hit {
    if (obj.ttl == 0s) {
    return(pass);
    }

    return(deliver);
}

sub vcl_miss {
}

sub vcl_deliver {
    set resp.http.X-Served-By = "For Test";

    if (obj.hits > 0) {
    set resp.http.X-Cache = "HIT";
    set resp.http.X-Cache-Hits = obj.hits;

    } else {
    set resp.http.X-Cache = "MISS";
    }



    if(resp.http.magicmarker) {
    unset resp.http.magicmarker; 
    set resp.http.Age="0";
    }

    unset resp.http.Via;
    unset resp.http.X-Varnish;

}

Varnish Usage

由于Varnish还很陌生,所以不确定如何调试问题,我们将不胜感激。

谢谢

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)