[Varnish] #513: Implement a VCL "constructor"

Varnish varnish-bugs at projects.linpro.no
Thu May 28 02:45:10 CEST 2009


#513: Implement a VCL "constructor"
-------------------------+--------------------------------------------------
 Reporter:  kb           |       Owner:  phk
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:     
Component:  varnishd     |     Version:  2.0
 Severity:  normal       |    Keywords:     
-------------------------+--------------------------------------------------
 I'm building up Varnish to replace a Squid install, and I'm doing
 something along these lines inside vcl_recv():

 {{{
 C{
    #include "regex.h" // (at top level, not here)
    regex_t *preg ;

    preg = calloc(N);
    regcomp( preg, "pattern", flags );
    if ( regexec( preg, ... ) )
       // do stuff
    regfree(preg);
 }C
 }}}

 However, this should perform much better:

 {{{
 C{
    #include "regex.h"
    regex_t *preg ;
 }C

 sub vcl_init {
    C{
       preg = calloc(N);
       regcomp( preg, "pattern", flags );
    }C
 }

 sub vcl_recv {
    C{
       if ( regexec( preg, ... ) )
          // do stuff
    }C
 }
 }}}

 This assumes that vcl_init() is an initializer that only runs once after
 the config is loaded, before threads are created.

 I implemented a "callonce" command that uses the POSIX pthread_once
 business:

 {{{
 sub vcl_recv {
    callonce vcl_init ;
    C{ ... }C
 }
 }}}

 But properly tracking arbitrary once-called functions would be ugly.  As
 is most of POSIX.

 This is why I thought a constructor or initializer that skips the
 complication of locks and pthread_once would be a nice addition for more
 efficient C integration.

 If there were a preferred way of implementing this, I'd love the feedback
 and pointers to do it in my off-time.

 Thx,[[br]]
 -- [[br]]
 Ken.

-- 
Ticket URL: <http://varnish.projects.linpro.no/ticket/513>
Varnish <http://varnish.projects.linpro.no/>
The Varnish HTTP Accelerator


More information about the varnish-bugs mailing list