Getting the best out of WURFL InFuze for Varnish-Cache

Questions about our enterprise "in the network" WURFL components
kirsten_sekhaolelo
Posts: 18
Joined: Thu May 29, 2014 10:38 am

Getting the best out of WURFL InFuze for Varnish-Cache

Postby kirsten_sekhaolelo » Wed Sep 03, 2014 7:20 am

Good day every

I had previously gotten a great deal of support and help configuring WURFL InFuze for Varnish-Cache and I really appreciate it.

I think at the moment we are not getting the best of varnish cache because of our implementation of WURFL InFuze for Varnish-Cache in VCL configuration file.

Here is our implementation of the VCL configuration file.

Code: Select all

import wurfl;
import std;

backend apache {
   .host = "127.0.0.1";
   .port = "8080";
}

sub vcl_init {
   wurfl.set_root("/usr/share/wurfl/wurfl.xml");
   #wurfl.add_patch("...");

   #wurfl.set_engine_target_high_performance();
   wurfl.set_engine_target_high_accuracy();

   #wurfl.set_cache_provider_none();
   #wurfl.set_cache_provider_lru(10000);
   wurfl.set_cache_provider_double_lru(10000,3000);

   # Mandatory Capabilities: You MUST leave the following capability requests
   wurfl.add_requested_capability("device_os");
   wurfl.add_requested_capability("device_os_version");
   wurfl.add_requested_capability("is_tablet");
   wurfl.add_requested_capability("is_wireless_device");
   wurfl.add_requested_capability("pointing_method");
   wurfl.add_requested_capability("preferred_markup");
   wurfl.add_requested_capability("resolution_height");
   wurfl.add_requested_capability("resolution_width");
   wurfl.add_requested_capability("ux_full_desktop");
   wurfl.add_requested_capability("xhtml_support_level");

   # User required capabilities
   wurfl.add_requested_capability("brand_name");
   wurfl.add_requested_capability("mobile_browser");
   wurfl.add_requested_capability("mobile_browser_version");
      
   wurfl.load();

   if (wurfl.error()) {
         std.syslog(0, wurfl.error());
         panic wurfl.error();
   }
}

sub vcl_hit {
    return (deliver);
}

sub vcl_miss {
    return (fetch);
}

sub vcl_recv {
    set req.http.X-Wurfl-Cap-Brand-Name = wurfl.get_capability("brand_name");
    set req.http.X-Wurfl-Cap-Is-Wireless-Device = wurfl.get_capability("is_wireless_device");
    set req.http.X-Wurfl-Cap-Is-Tablet = wurfl.get_capability("is_tablet");
    set req.http.X-Wurfl-Cap-Resolution-Width = wurfl.get_capability("resolution_width");
    set req.http.X-Wurfl-Cap-Resolution-Height = wurfl.get_capability("resolution_height");
       
    #Virtual Capabilities
    set req.http.X-Wurfl-Cap-Is-Smartphone = wurfl.get_virtual_capability("is_smartphone");
    set req.http.X-Wurfl-Cap-Is-Touchscreen = wurfl.get_virtual_capability("is_touchscreen");
    set req.http.X-Wurfl-Cap-Is-Full-Desktop = wurfl.get_virtual_capability("is_full_desktop");
    set req.http.X-Wurfl-Cap-Device-Os = wurfl.get_virtual_capability("advertised_device_os");
    set req.http.X-Wurfl-Cap-Device-Os-Version = wurfl.get_virtual_capability("advertised_device_os_version");
    set req.http.X-Wurfl-Cap-Mobile-Browser = wurfl.get_virtual_capability("advertised_browser");
    set req.http.X-Wurfl-Cap-Mobile-Browser_version = wurfl.get_virtual_capability("advertised_browser_version");
    set req.http.X-Wurfl-Cap-Is-Windows-Phone = wurfl.get_virtual_capability("is_windows_phone");
    set req.http.X-Wurfl-Cap-Is-Android = wurfl.get_virtual_capability("is_android");    
    
    if (wurfl.error()) {
      std.syslog(0, wurfl.error());
      panic wurfl.error();
   }
}

sub vcl_hash {
   hash_data(req.url+req.http.host+wurfl.get_device_id());
   return (hash);
}
Our strategy was to add WURFL capabilities as headers in the HTTP specs in the vcl_recv sub so that I can be able to grab them in my PHP script by looking into $_SERVER variable and redirect the user to a specific theme.

That works as expected and that is thanks to the Scientiamobile support guys.

Notice the hash_data() function

Code: Select all

sub vcl_hash {
   hash_data(req.url+req.http.host+wurfl.get_device_id());
   return (hash);
}
The Hit ratio has been too low due to the number of unique devices hitting our servers which result in thousand cache pools. We get over 5000 unique devices accessing our website every day. So if we are caching by requested URL + Device ID we will get a cache pool for each unique device hitting a page.
Because our objective is to use WURFL InFuze for Varnish-Cache to differentiate between desktop, tablets, smartphones and feature phones/low-end mobile devices and serve a different template for each of those 4 categories, we were thinking of a way in our VCL configuration file to use algorithm like one below to achieve that:

If(Is_desktop)
DeviceClass = ‘Device-class-A’
Else If(Is_tablet)
DeviceClass = ‘Device-class-B’
Else If (is_smartphone)
DeviceClass = ‘Device-class-C’
Else If (is_mobile && not is_smartphone)
DeviceClass = ‘Device-class-D’

In the sub vcl_hash sub we call hash_data function and instead of hashing by requested URL with the Device ID by requested URL + DeviceClass
In that way I will have 4 cache pools which will result in high hit rate.

How can I implement something like that and have very few cache pools and thus high hit rate?

Thank you.

Elliotfehr

Re: Getting the best out of WURFL InFuze for Varnish-Cache

Postby Elliotfehr » Wed Sep 03, 2014 10:49 am

Hello,

I have reached out to our engineering team to assist you further.

I did notice that you are running WURFL in high-accuracy mode at the moment. I would recommend using WURFL in high-performance mode to prevent further capability matching for desktop devices.

Thank you,

Elliot

kirsten_sekhaolelo
Posts: 18
Joined: Thu May 29, 2014 10:38 am

Re: Getting the best out of WURFL InFuze for Varnish-Cache

Postby kirsten_sekhaolelo » Fri Sep 05, 2014 6:15 am

Hi Elliot

Have you heard anything from the engineers yet?

Kind regards,

Kirsten

fulvio.crivellaro
Posts: 38
Joined: Tue Jan 31, 2012 10:27 am

Re: Getting the best out of WURFL InFuze for Varnish-Cache

Postby fulvio.crivellaro » Fri Sep 05, 2014 8:16 am

Hello Krinsten,
sorry for the delay in our answer, our Varnish guru is currently on vacation.
I will do my best to give you the solution for this (just feel free to correct possible syntax errors)

If I understood correctly what you are doing, you simply have to restrict the possible IDs being passed to the hash function.
Something like this code snippet (derived from the code you post) should work:

Code: Select all

sub vcl_hash {
	if (wurfl.get_virtual_capability("is_full_desktop") == "true") {
		hash_data(req.url+req.http.host+"Device-class-A");
	} else if (wurfl.get_virtual_capability("is_tablet") == "true") {
		hash_data(req.url+req.http.host+"Device-class-B");
	} else if (wurfl.get_virtual_capability("is_smartphone") == "true") {
		hash_data(req.url+req.http.host+"Device-class-C");
	} else #if (wurfl.get_virtual_capability("is_mobile") == "true" && wurfl.get_virtual_capability("is_smartphone") == "false") {
		hash_data(req.url+req.http.host+"Device-class-D");
	}	#else {
		#hash_data(req.url+req.http.host+"Device-class-Unknown");
	#}
	return (hash);
}
Some lines are commented on purpose, since your code did not have an overall else, but I don't know if you are planning to manage a fifth device unknown class in some custom way, or just associate to some other class behavior.

As Elliot already said, it is definitively a better solution for your purpose to run WURFL in high-performance mode.

I hope this will help you. Let us know if you have any more question.

Regards,
Fulvio

kirsten_sekhaolelo
Posts: 18
Joined: Thu May 29, 2014 10:38 am

Re: Getting the best out of WURFL InFuze for Varnish-Cache

Postby kirsten_sekhaolelo » Tue Oct 07, 2014 5:53 am

Hi there

I have made a few modifications to the configuration file. Please have a look at advice.

Code: Select all

import wurfl;
import std;

backend apache {
   .host = "127.0.0.1";
   .port = "8080";
}

sub vcl_init {
   wurfl.set_root("/usr/share/wurfl/wurfl.xml");
   #wurfl.add_patch("...");

   wurfl.set_engine_target_high_performance();
   #wurfl.set_engine_target_high_accuracy();

   #wurfl.set_cache_provider_none();
   #wurfl.set_cache_provider_lru(10000);
   wurfl.set_cache_provider_double_lru(10000,3000);

   # Mandatory Capabilities: You MUST leave the following capability requests
   wurfl.add_requested_capability("device_os");
   wurfl.add_requested_capability("device_os_version");
   wurfl.add_requested_capability("is_tablet");
   wurfl.add_requested_capability("is_wireless_device");
   wurfl.add_requested_capability("pointing_method");
   wurfl.add_requested_capability("preferred_markup");
   wurfl.add_requested_capability("resolution_height");
   wurfl.add_requested_capability("resolution_width");
   wurfl.add_requested_capability("ux_full_desktop");
   wurfl.add_requested_capability("xhtml_support_level");

   # User required capabilities
   wurfl.add_requested_capability("brand_name");
   wurfl.add_requested_capability("mobile_browser");
   wurfl.add_requested_capability("mobile_browser_version");
      
   wurfl.load();

   if (wurfl.error()) {
         std.syslog(0, wurfl.error());
         panic wurfl.error();
   }
}

sub vcl_hit {
    return (deliver);
}

sub vcl_miss {
    return (fetch);
}

sub vcl_recv {    
    if (wurfl.get_virtual_capability("is_tablet") == "true") 
    {
      set req.http.X-Wurfl-Device-Class = "Device-class-B";
    }
    else if(wurfl.wurfl.get_capability("is_wireless_device") == "true")
    {
      if(wurfl.get_virtual_capability("is_smartphone") == "true" && wurfl.get_virtual_capability("is_touchscreen") == "true")
      {
        set req.http.X-Wurfl-Device-Class = "Device-class-C";
      } 
      else
      {
        set req.http.X-Wurfl-Device-Class = "Device-class-D";
      }     
    }
    else 
    {
      set req.http.X-Wurfl-Device-Class = "Device-class-A";
    }    
    
    if (wurfl.error()) {
      std.syslog(0, wurfl.error());
      panic wurfl.error();
    }
}

sub vcl_hash {
      hash_data(req.url+req.http.host+req.http.X-Wurfl-Device-Class);
      return (hash);
}
As I have said above, the aim is to improve the hit ratio.

Thank you in advance for your assistance.

Kirsten

support-all
Posts: 32
Joined: Mon Oct 08, 2012 2:47 am

Re: Getting the best out of WURFL InFuze for Varnish-Cache

Postby support-all » Tue Oct 07, 2014 9:47 am

Hello Kirsten,

the config file should meet your requirements and of course it highly depends both on what you're looking for and the behaviour you're expecting from your module.
As long as the logic is okay and lets you sort the devices the way you want it to, I would say it is fine.

That said, which version of varnish-mod-wurfl and libwurfl are you currently using?


Regards,
Francesca

kirsten_sekhaolelo
Posts: 18
Joined: Thu May 29, 2014 10:38 am

Re: Getting the best out of WURFL InFuze for Varnish-Cache

Postby kirsten_sekhaolelo » Fri Oct 10, 2014 9:12 am

Hi Francesca

Thanks for the heads up.

We are currently running version 1.5.1.3. But we are planning on upgrading to 1.5.2.1 some time next week.

Thanks again.

Kirsten

support-all
Posts: 32
Joined: Mon Oct 08, 2012 2:47 am

Re: Getting the best out of WURFL InFuze for Varnish-Cache

Postby support-all » Tue Oct 21, 2014 5:33 pm

Hi Kirsten,

if you already have upgraded your libwurfl and Varnish packages to 1.5.2.1, and supposing you're still using the capability filter outlined in your previous posts, then you'll need to add a few more mandatory capabilities to the list.
This is the official mandatory capability list starting from WURFL 1.5.2.1:

wurfl.add_requested_capability("device_os");
wurfl.add_requested_capability("device_os_version");
wurfl.add_requested_capability("is_tablet");
wurfl.add_requested_capability("is_wireless_device");
wurfl.add_requested_capability("pointing_method");
wurfl.add_requested_capability("preferred_markup");
wurfl.add_requested_capability("resolution_height");
wurfl.add_requested_capability("resolution_width");
wurfl.add_requested_capability("ux_full_desktop");
wurfl.add_requested_capability("xhtml_support_level");
wurfl.add_requested_capability("is_smarttv");
wurfl.add_requested_capability("brand_name");
wurfl.add_requested_capability("can_assign_phone_number");
wurfl.add_requested_capability("marketing_name");
wurfl.add_requested_capability("model_name");


Best Regards,
Andrea


Who is online

Users browsing this forum: No registered users and 4 guests