<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <title></title>
  </head>
  <body bgcolor="#ffffff" text="#000000">
    It is true that there are potentially better places to setup the
    hash, but it is best to check for a null pointer<br>
    for the hash object anyway any time you use it. The setup itself is
    also very fast; you just don't want to do<br>
    it every time. Note in my init function I forgot a 'hash = new
    hashc()'.<br>
    <br>
    Also; if you are going to do this, you will likely have a preset
    list of domains you are using.<br>
    In such a case, the best type of hash to use would be a 'minimal
    perfect hash'.<br>
    You could use the 'gperf' library to generate a suitable algorithm
    to map your domain strings<br>
    into an array.<br>
    <br>
    On 3/7/2011 10:30 AM, AD wrote:
    <blockquote
      cite="mid:AANLkTimtiFpuRZ_A=dd2nsuH+L9MqU5jmkNhX_f6v7Xf@mail.gmail.com"
      type="cite">Cool, as for the startup, i wonder if you can instead
      of trying to insert into VCL_Init, try to do just, as part of the
      startup process hit a special URL to load the hash_Table.  Or
      another possibility might be to load an external module, and in
      there, populate the hash.
      <div>
        <br>
      </div>
      <div><br>
        <br>
        <div class="gmail_quote">On Mon, Mar 7, 2011 at 9:45 AM, David
          Helkowski <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:dhelkowski@sbgnet.com">dhelkowski@sbgnet.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            padding-left: 1ex;">
            <div bgcolor="#ffffff" text="#000000"> vcl configuration is
              turned straight into C first of all.<br>
              You can put your own C code in both the functions and
              globally.<br>
              When including headers/libraries, you essentially just
              have to include the code globally.<br>
              <br>
              I am not sure if there is any 'init' function when varnish
              is called, so I was suggesting that<br>
              the hash be initiated by just checking if the hash has
              been created yet.<br>
              <br>
              This will cause a penalty to the first vcl_recv call that
              goes through; but that shouldn't<br>
              matter.<br>
              <br>
              Note that I just passed a dummy number as an example to
              the custom config, and that<br>
              I didn't show how to do anything in the custom function.
              In this example, all custom<br>
              stuff would be in straight C. You would need to use
              varnish itself to compile what config<br>
              you want and look at the C code it generates to figure out
              how to tie in all your custom<br>
              configs....<br>
              <br>
              eg:<br>
              <br>
              C{<br>
                #include "hash.c" // a string hashing store/lookup
              libary; you'll need to write one<br>
                  // or possibly just use some freely available one.<br>
                hashc *hash=0;<br>
                <br>
                void init_hash() {<br>
                  if( hash ) return;<br>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <blockquote
      cite="mid:AANLkTimtiFpuRZ_A=dd2nsuH+L9MqU5jmkNhX_f6v7Xf@mail.gmail.com"
      type="cite">
      <div>
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            padding-left: 1ex;">
            <div bgcolor="#ffffff" text="#000000">     hash.store( '<a
                moz-do-not-send="true" href="http://test.com"
                target="_blank">test.com</a>', &test_com );<br>
                  // same for all domains<br>
                }<br>
                <br>
                void test_com( int n ) {<br>
                  // custom vcl_recv stuff for domain 'test'<br>
                }<br>
              }<br>
              <br>
              sub vcl_recv {<br>
                C{<br>
                  char *domain;<br>
                  // [ place some code to fetch domain and put it in
              domain here ]<br>
                  if( !hash ) init_hash();<br>
                  void (*func)(int);<br>
                  func = hash.lookup( domain );<br>
                  func(1);
              <div>
                <div class="h5"><br>
                    }<br>
                  }<br>
                  <br>
                  On 3/7/2011 9:23 AM, AD wrote:
                  <blockquote type="cite">but dont all the configs need
                    to be loaded at runtime, not sure the overhead here?
                     I think what you mentioned seems like a really
                    innovative way to "call" the function but what about
                    anyimpact to "loading" all these configs?  
                    <div> <br>
                    </div>
                    <div>If i understand what you are saying, i put a
                      "call test_func;" in vcl_recv which turned into
                      this in C</div>
                    <div><br>
                    </div>
                    <div>
                      <div>    if (VGC_function_test_func(sp))</div>
                      <div>        return (1);</div>
                      <div>      if</div>
                      <div><br>
                      </div>
                      <div>Are you suggesting your hash_table would take
                        over this step ?</div>
                      <div><br>
                      </div>
                      <div>Adam</div>
                      <br>
                      <div class="gmail_quote">On Mon, Mar 7, 2011 at
                        8:02 AM, David Helkowski <span dir="ltr"><<a
                            moz-do-not-send="true"
                            href="mailto:dhelkowski@sbgnet.com"
                            target="_blank">dhelkowski@sbgnet.com</a>></span>
                        wrote:<br>
                        <blockquote class="gmail_quote" style="margin:
                          0pt 0pt 0pt 0.8ex; border-left: 1px solid
                          rgb(204, 204, 204); padding-left: 1ex;">
                          <div bgcolor="#ffffff" text="#000000"> The
                            best way would be to use a jump table.<br>
                            By that, I mean to make multiple subroutines
                            in C, and then to jump to the different
                            subroutines by looking<br>
                            up pointers to the subroutines using a
                            string hashing/lookup system.<br>
                            <br>
                            You would also need a flag to indicate
                            whether the hash has been 'initialized' yet
                            as well.<br>
                            The initialization would consist of storing
                            function pointers at the hash locations
                            corresponding to each<br>
                            of the domains.<br>
                            <br>
                            I attempted to do this myself when I first
                            started using varnish, but I was having
                            problems with varnish<br>
                            crashing when attempting to use the code I
                            wrote in C. There may be limitations to the
                            C code that can be<br>
                            used.
                            <div>
                              <div><br>
                                <br>
                                On 3/6/2011 5:39 PM, AD wrote: </div>
                            </div>
                            <blockquote type="cite">
                              <div>
                                <div>Hello,
                                  <div> </div>
                                  <div> what is the best way to run an
                                    instance of varnish that may need
                                    different vcl configurations for
                                    each hostname.  This could end up
                                    being 100-500 includes to map to
                                    each hostname and then a long
                                    if/then block based on the hostname.
                                     Is there a more scalable way to
                                    deal with this?  We have been toying
                                    with running one large varnish
                                    instance with tons of includes or
                                    possibly running multiple instances
                                    of varnish (with the config broken
                                    up) or spreading the load across
                                    different clusters (kind of like
                                    sharding) based on hostname to keep
                                    the configuration simple.</div>
                                  <div><br>
                                  </div>
                                  <div> Any best practices here?  Are
                                    there any notes on the performance
                                    impact of the size of the VCL or the
                                    amount of if/then statements in
                                    vcl_recv to process a unique call
                                    function ?</div>
                                  <div><br>
                                  </div>
                                  <div> Thanks</div>
                                  <div><br>
                                  </div>
                                </div>
                              </div>
                              <pre><fieldset></fieldset>
_______________________________________________
varnish-misc mailing list
<a moz-do-not-send="true" href="mailto:varnish-misc@varnish-cache.org" target="_blank">varnish-misc@varnish-cache.org</a>
<a moz-do-not-send="true" href="http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" target="_blank">http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a></pre>
                            </blockquote>
                            <br>
                          </div>
                          <br>
_______________________________________________<br>
                          varnish-misc mailing list<br>
                          <a moz-do-not-send="true"
                            href="mailto:varnish-misc@varnish-cache.org"
                            target="_blank">varnish-misc@varnish-cache.org</a><br>
                          <a moz-do-not-send="true"
                            href="http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc"
                            target="_blank">http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                  </blockquote>
                  <br>
                </div>
              </div>
            </div>
            <br>
            _______________________________________________<br>
            varnish-misc mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
            <a moz-do-not-send="true"
              href="http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc"
              target="_blank">http://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
    <br>
  </body>
</html>