Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to DeviceDetector 2.X #305

Merged
merged 41 commits into from Jun 17, 2014
Merged

Switch to DeviceDetector 2.X #305

merged 41 commits into from Jun 17, 2014

Conversation

sgiehl
Copy link
Member

@sgiehl sgiehl commented Jun 8, 2014

  • Switched to DeviceDetector 2.X
  • Do detection only once (in tracker/settings). There is no need doing device type detection in DeviceDetection plugin as all those detections are already done before (Doing them twice slows down tracking)
  • Introduce new DeviceDetectorCache to use an optimal caching for DeviceDetector (File Cache + Static Caching)
  • Speed up detection for bulk requests (thx to @cbonte)
  • Use special parsers where only those are needed (e.g. check for bots or mobile os)

sgiehl added 30 commits May 24, 2014 18:37
Conflicts:
	core/Tracker/Visit.php
Conflicts:
	core/Tracker/Settings.php
	plugins/API/API.php
…or. This cache combines file and static caching to speed up detections as much as possible
cbonte and others added 6 commits June 8, 2014 01:00
By caching parsed DeviceDetectors, we reduce the number of regexes to process.
It allows to process more requests per second when the same user agent is met.
The previous commit had at least 2 issues :

one identified by sgiehl, who reported that the static variable was useless
if we always create a new cache instance, and indeed, he's absolutely right !

Another one can be classified as a potential security issue, where a request
can forge a user agent as a key to an object which is not meant to be accessed
(CacheStatic instances share their data).
…detector based on the given user agent. That provides the possibility to reuse DeviceDetector for bot and visitor data detection.
@cbonte
Copy link
Contributor

cbonte commented Jun 8, 2014

@sgiehl Tests are in progress. From the first results, It seems it's a little better but I can't import more than 800-810req/s (which is still quite good compared to the results without any cache). I'm making some more tests but I think it's because with the factory, we're calling the parse() method for everything and not only for bots.

@sgiehl
Copy link
Member Author

sgiehl commented Jun 8, 2014

DeviceDetector skips parsing additional data when a bot is detected. So it
should be the optimal way as parsing is always only done once.
The only thing that could be improved might be caching more devicedetector
instances. But I guess that would only make sense using memcache or
something similar as file cache is too slow for that.

@cbonte
Copy link
Contributor

cbonte commented Jun 8, 2014

Yes, I saw the tests after posting.
After several tests with 2.4.0-b5 and this branch, that's OK for me, the performances are nearly equal, using the same logs.

@@ -0,0 +1,65 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe files core/DeviceDetector* should be in plugins/DevicesDetection/ ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about that, too. But the classes using those files are mostly located in Core.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tsteur is working on this in this branch: https://github.com/piwik/piwik/tree/report_and_dimension_refactoring
In this branch. all reports and custom columns will be put in their own plugins after this huge refactor.

After Thomas merges master in his branch, then the code regarding DevicesDetection should be all (or almost all) in the plugin itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it makes sense after the refactoring, it would be the best solution if he moves it there then

@mattab
Copy link
Member

mattab commented Jun 17, 2014

That was a great Pull request... well done Stefan, you're the man! Merging now... feel free to make edits as you see fit!

mattab pushed a commit that referenced this pull request Jun 17, 2014
Switch to DeviceDetector 2.X
@mattab mattab merged commit d4f1ce6 into master Jun 17, 2014
@sgiehl sgiehl deleted the DeviceDetector2 branch June 17, 2014 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants