varnishcache / varnish-devicedetect

VCL based device detection for Varnish Cache.
Other
300 stars 88 forks source link

[regex] detection logic based on Mobile_Detect.json #13

Closed serbanghita closed 10 years ago

serbanghita commented 10 years ago

Hi,

I'd suggest improving the detection getting the detection logic from https://github.com/serbanghita/Mobile-Detect/blob/master/Mobile_Detect.json

It's just an idea, we made that .json to allow people to better port the script. We update it also on every release.

lkarsten commented 10 years ago

Hi. Thanks for the suggestion. Great idea to pull the ruleset into a separate file. This is a fairly low-effort kind of script, so I don't think we'll spend the effort importing your ruleset.

If anyone wants to write a VCL translator for your data, I would be happy to link to it though.

serbanghita commented 10 years ago

@lkarsten cool, we had quite a few requests about this, I will find someone to link to this project. Thanks for your response!

willemk commented 10 years ago

@serbanghita I made a little php translate script to do this: https://github.com/willemk/varnish-mobiletranslate

I've tested it with ~ 20 UA strings and it works good so far.

serbanghita commented 10 years ago

@willemk - Holy crap that was fast! Nice! :beers:

Btw, at Mobile_Detect we have a lot of UnitTests that keep the library relevant on each update (see https://github.com/serbanghita/Mobile-Detect/blob/master/tests/UA_List.inc.php ). Maybe you can use the tests exported to JSON at https://github.com/serbanghita/Mobile-Detect/blob/master/tests/ualist.json - it's in an unformatted format.

@willemk - can you make a README for noobs for the project https://github.com/willemk/varnish-mobiletranslate - I want to list it on our README also. Thanks!!!

lkarsten commented 10 years ago

@willemk Thanks, I've added a link to your generator in the README.rst file now.

Since we're generating the VCL anyway, I would love if someone took the time to optimise the output regexes a bit.

Doing massive case-insensitive regex checks for every request has do add some extra delay. For example check the most common ones first, or do a two-level matching by building an initial check on only the first characters or something similar.

I wrote a time-to-first-byte measurement tool at some point (https://github.com/lkarsten/httpttfb ) that perhaps can be used to put numbers on this.

serbanghita commented 10 years ago

@lkarsten are you refering to the https://github.com/willemk/varnish-mobiletranslate/blob/master/mobile_detect.vcl regex list? That is the same order we use on Mobile_Detect.php it's based on the frequency of devices - this is something researched monthly based on visitor logs.

Any updates to regexes should be double-checked via our UnitTests to prevent regex collisions. ( see: https://github.com/serbanghita/Mobile-Detect/pull/43 )

willemk commented 10 years ago

@lkarsten I've ran your tool on my $20 linode test box and it shows about an 0.1ms (100μs) increase:

With device checking:

root@linode:~/httpttfb/httpttfb# ./measure 8080 Measuring...(dry run) 1 2 3 4 5 done

localhost:8080 (2014-01-22 01:08:17 on linode)

mean: 459.361μs (stdev 58.504μs) median: 450.573μs mean: 309.921μs (stdev 39.811μs) median: 305.879μs mean: 369.633μs (stdev 46.786μs) median: 364.229μs mean: 349.279μs (stdev 39.669μs) median: 347.044μs mean: 386.895μs (stdev 49.983μs) median: 384.037μs

Avg Mean: 374μs

Without device checking: root@linode:~/httpttfb/httpttfb# ./measure 8080 Measuring...(dry run) 1 2 3 4 5 done

localhost:8080 (2014-01-22 01:09:56 on linode)

mean: 307.663μs (stdev 50.453μs) median: 299.464μs mean: 315.561μs (stdev 41.959μs) median: 316.391μs mean: 245.779μs (stdev 37.341μs) median: 226.765μs mean: 245.985μs (stdev 28.984μs) median: 236.468μs mean: 330.259μs (stdev 47.495μs) median: 322.861μs

Avg Mean: 288μs

willemk commented 10 years ago

@serbanghita I've updated the readme file to be a little more user friendly.