Mailing List Archive

Varnish backend timeout doesn't work with keep alive backend
Hi,All:
I set varnish backend that:
backend default { .host = "127.0.0.1"; .port = "4567"; .connect_timeout = 1s; .first_byte_timeout = 2s; .between_bytes_timeout = 1s; }
The first timeout is right, but if the prev connection is right, varnish use keepalive to deal with the next connection with same url and the timeout conf doesn't wok.
How can make timeout work with all connections even with backend keepalive.

Thanks.
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
On Wed, Dec 28, 2016 at 05:12:54PM +0800, JackDrogon wrote:

> I set varnish backend that:
> backend default { .host = "127.0.0.1"; .port = "4567"; .connect_timeout
> = 1s; .first_byte_timeout = 2s; .between_bytes_timeout = 1s; }
> The first timeout is right, but if the prev connection is right,
> varnish use keepalive to deal with the next connection with same url
> and the timeout conf doesn't wok.

Please elaborate. Describe the situation that doesn't work as you expect, and what you would expect to happen.

--
Andreas

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
On Wed, Dec 28, 2016 at 10:24 AM, Andreas Plesner <apj@mutt.dk> wrote:
> On Wed, Dec 28, 2016 at 05:12:54PM +0800, JackDrogon wrote:
>
>> I set varnish backend that:
>> backend default { .host = "127.0.0.1"; .port = "4567"; .connect_timeout
>> = 1s; .first_byte_timeout = 2s; .between_bytes_timeout = 1s; }
>> The first timeout is right, but if the prev connection is right,
>> varnish use keepalive to deal with the next connection with same url
>> and the timeout conf doesn't wok.
>
> Please elaborate. Describe the situation that doesn't work as you expect, and what you would expect to happen.

Possibly a known problem [1] for first_byte_timeout, apparently still
an open issue.

Dridi

[1] https://github.com/varnishcache/varnish-cache/issues/1772

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
OK.
 I run a go server, such as:

func handler(res http.ResponseWriter, req *http.Request) {
        atomic.AddUint32(&times, 1)
        number := rand.Intn(100)
        fmt.Printf("Random number: %d.\n", number)
        t := atomic.LoadUint32(&times)
        if t%4 == 1 {
                time.Sleep(7 * time.Second)
        }
        fmt.Fprintf(res, "Random number: %d.\n", number)
        fmt.Println("=========================")
}


I use this as varnish backend, and setting hash_always_miss
so I curl 127.0.0.1:8000 for 5 times.

curl 127.0.0.1:8000  0.00s user 0.00s system 0% cpu 2 total
curl 127.0.0.1:8000  0.00s user 0.00s system 77% cpu 0.005 total
curl 127.0.0.1:8000  0.00s user 0.00s system 66% cpu 0.005 total
curl 127.0.0.1:8000  0.00s user 0.00s system 68% cpu 0.004 total
curl 127.0.0.1:8000  0.00s user 0.00s system 0% cpu 7.005 total 

I think the fifth requet's time usage is 2s, but It's 7s. How can I set varnish to make it be 2s

On 28 December 2016 at 18:19:21, Boukelmoune Dridi (dridi@varni.sh) wrote:

On Wed, Dec 28, 2016 at 10:24 AM, Andreas Plesner <apj@mutt.dk> wrote:
> On Wed, Dec 28, 2016 at 05:12:54PM +0800, JackDrogon wrote:
>
>> I set varnish backend that:
>> backend default { .host = "127.0.0.1"; .port = "4567"; .connect_timeout
>> = 1s; .first_byte_timeout = 2s; .between_bytes_timeout = 1s; }
>> The first timeout is right, but if the prev connection is right,
>> varnish use keepalive to deal with the next connection with same url
>> and the timeout conf doesn't wok.
>
> Please elaborate. Describe the situation that doesn't work as you expect, and what you would expect to happen.

Possibly a known problem [1] for first_byte_timeout, apparently still
an open issue.

Dridi

[1] https://github.com/varnishcache/varnish-cache/issues/1772

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
On Wed, Dec 28, 2016 at 11:45 AM, JackDrogon <jack.xsuperman@gmail.com> wrote:
> OK.
> I run a go server, such as:
>
> func handler(res http.ResponseWriter, req *http.Request) {
> atomic.AddUint32(&times, 1)
> number := rand.Intn(100)
> fmt.Printf("Random number: %d.\n", number)
> t := atomic.LoadUint32(&times)
> if t%4 == 1 {
> time.Sleep(7 * time.Second)
> }
> fmt.Fprintf(res, "Random number: %d.\n", number)
> fmt.Println("=========================")
> }
>
>
> I use this as varnish backend, and setting hash_always_miss
> so I curl 127.0.0.1:8000 for 5 times.
>
> curl 127.0.0.1:8000 0.00s user 0.00s system 0% cpu 2 total
> curl 127.0.0.1:8000 0.00s user 0.00s system 77% cpu 0.005 total
> curl 127.0.0.1:8000 0.00s user 0.00s system 66% cpu 0.005 total
> curl 127.0.0.1:8000 0.00s user 0.00s system 68% cpu 0.004 total
> curl 127.0.0.1:8000 0.00s user 0.00s system 0% cpu 7.005 total
>
> I think the fifth requet's time usage is 2s, but It's 7s. How can I set
> varnish to make it be 2s

I thought this bug had been fixed, but apparently not. A workaround
would be to disable keep-alive by forcefully closing backend
connections. With the obvious performance implication of having to
reconnect for every single request.

I'll try to remember to discuss this during next Monday's bugwash.

Dridi

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
How to disable backend keep-alive. I want to test it.


On 28 December 2016 at 20:55:23, Boukelmoune Dridi (dridi@varni.sh) wrote:
implication
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
On Thu, Dec 29, 2016 at 3:44 AM, JackDrogon <jack.xsuperman@gmail.com> wrote:
> How to disable backend keep-alive. I want to test it.

In vcl_backend_fetch, you can do:

set bereq.http.connection = "close";

That's how it's specified in HTTP/1.1, by default a connection is persistent.

Dridi

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
It's so diffcult for me to tracing the timeout problem.




I painted a map of the backend request.
I tracing varnish, found that cache/cache_obj.c:ObjWaitState lock for waiting backend response. But the vwe_thread epoll wait time is not right, it is default time 100s
When epoll_wait is run, it wait for backend response first_bytes_timeout, which in my case is 7s.
If I set cache_waiter_epoll.c:vwe_thread =>  vwe->next = now + 1, all is right. The timeout time became 2s.

I read some varnish code, not full. I want know where is the code that varnish add the backend response header read event to epoll when keepalive is enable.
I guess It's cnt_miss in my case, but I can't see the code, it's in vgc.so. How can see the vgc.so's origin code which is generated by libvcc.

Thanks.

On 29 December 2016 at 16:21:47, Boukelmoune Dridi (dridi@varni.sh) wrote:

On Thu, Dec 29, 2016 at 3:44 AM, JackDrogon <jack.xsuperman@gmail.com> wrote:
> How to disable backend keep-alive. I want to test it.

In vcl_backend_fetch, you can do:

set bereq.http.connection = "close";

That's how it's specified in HTTP/1.1, by default a connection is persistent.

Dridi
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
On Fri, Dec 30, 2016 at 11:10 AM, JackDrogon <jack.xsuperman@gmail.com> wrote:
>
> It's so diffcult for me to tracing the timeout problem.
>
>
>
> I painted a map of the backend request.
> I tracing varnish, found that cache/cache_obj.c:ObjWaitState lock for waiting backend response. But the vwe_thread epoll wait time is not right, it is default time 100s
> When epoll_wait is run, it wait for backend response first_bytes_timeout, which in my case is 7s.
> If I set cache_waiter_epoll.c:vwe_thread => vwe->next = now + 1, all is right. The timeout time became 2s.

Feel free to comment on github in the issue I mentioned if you think
you have a lead. I thought I had seen a commit fix this in the not so
recent past, but I must have confused it with another ticket (probably
1806). As I said, I plan to mention this during the next bugwash.

> I read some varnish code, not full. I want know where is the code that varnish add the backend response header read event to epoll when keepalive is enable.
> I guess It's cnt_miss in my case, but I can't see the code, it's in vgc.so. How can see the vgc.so's origin code which is generated by libvcc.

To translate your VCL code to C, see varnishd -C (in the varnishd
man). But this C code will not touch the waiting code, it's only code
that is called by varnishd for each step (sub) in the VCL engine,
executing your VCL logic (reading/setting variables, picking
transitions etc).

Dridi

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Varnish backend timeout doesn't work with keep alive backend [ In reply to ]
OK.
I will discuss about the problem on github. The problem is different from #1806.


On 30 December 2016 at 19:13:42, Boukelmoune Dridi (dridi@varni.sh) wrote:

but I must have confused it with another ticket (probably 
1806)