Getting the best out of WURFL InFuze for Varnish-Cache
Posted: 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.
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
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.
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);
}
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);
}
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.