Updating the backend definitions in VCL at runtime


#1

Hi,

We’ve got a system where some of the requests take a little longer than others, and we need to increase the timeout on them.

Rather than creating a new origin definition, I’m wondering if it is possible to update the origin on the fly in the VCL?

I’ve seen the other thread at Can I set set req.backend.host dynamically - which indicates if this is possible. However, in that thread mpapper is looking to update the item on every request.

If I update the backend (req.backend) rather than F_origin, does this override the setting for future requests?

The VCL I’m looking at for this is as follows - though I don’t seem to be allowed to update the timeout as I want to in the code below.

    ## Use SSL backend for SSL requests
    ## Use the _post variants for POST requests and close connection after each request
    if (req.request == "POST") {
        set req.http.Connection = "close";
        if (req.http.Fastly-SSL) {
            set req.backend = F_origin_ssl_post;
        } else {
            set req.backend = F_origin_post;
        }
    } else {
        if (req.http.Fastly-SSL) {
            set req.backend = F_origin_ssl;
        } else {
            set req.backend = F_origin;
        }
    }
    
    ## Handle the special case of login
    if ( (req.request == "POST") && (req.url == "/AjaxCustomLogon") ) {
        set req.backend.first_byte_timeout = 60s;
        set req.backend.between_bytes_timeout = 60s;

The only other option I can see is another backend definition, which I’d rather not have to do.

Many thanks,
Will.


#2

Hi Will,

The backend timeouts you change with the req.backend variables are only changed for that particular request.

Cheers,

Doc


#3

Hi Doc,

I am interested in doing what Will described above as well. Changing these backend timeouts at runtime would be useful for me, and simplify something I’m already doing in the VCL.

I tried setting req.backend.first_byte_timeout and was shown a validation error when uploading my VCL.

Unknown variable 'req.backend.first_byte_timeout'
At: (input Line 1782 Pos 17)
            set req.backend.first_byte_timeout = 120s;
----------------##############################--------
Running VCC-compiler failed

Will this be something supported in the future? Thanks!


#4

I got the same issue when I tied too (as I stated as “though I don’t seem to be allowed to update the timeout as I want to in the code below”).

Frustrating, as allowing this would be an elegant solution. We know which requests are likely to take longer than ‘normal’ requests. I’d rather not have to create a new backend (we have enough of these anyway!).

@Doc - any change of an enhancement to allow this to be set?


#5

Oh, crud, I do apologize. I was just going off of code that I knew was there in our Varnish, I never actually verified what the VCL variables were.

Instead of req.backend.* it’s actually bereq.backend.* and only in vcl_miss and vcl_pass.

The three that are available are:

bereq.connect_timeout
bereq.first_byte_timeout
bereq.between_bytes_timeout

#6

Thanks for the response Doc - much appreciated!


#7

So for those using this right now, there’s actually a bug with connection re-use at the moment. Fix has been written, hopefully going out with the next rollout. I’ll post here when it’s in production.


#8

Hi @drwilco,

I just wanted to check if this bug was fixed. I’m still hoping to implement these new VCL variables.

Let us know. Thanks!


#9

The bug was fixed, and the fix was rolled out. I forgot to update here, sorry.