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

Potential bug with DevicesDetection #20139

Open
mikkeschiren opened this issue Dec 25, 2022 · 5 comments
Open

Potential bug with DevicesDetection #20139

mikkeschiren opened this issue Dec 25, 2022 · 5 comments
Labels
Potential Bug Something that might be a bug, but can't be reproduced (yet).

Comments

@mikkeschiren
Copy link
Contributor

With DevicesDetection installed and making a request for any reports, thousands of requests are made for cached items for DevicesDetection even when it's not required. We are using Redis for cache. Could be that this a general "thing", not just for DevicesDetection. And could also be expected behaviour, that I don't know.

Expected Behavior

Cached items should only be asked for when needed.

Current Behavior

Requests are done for cached items not needed.

Steps to Reproduce (for Bugs)

  1. Activate DevicesDetection
  2. Do a request for a report not displaying any info about devices.
  3. With a network sniffer, you could see requests done for DevicesDetection cached items.

Your Environment

  • Matomo Version: 4.12.3
  • PHP Version: 8..0.25
  • Server Operating System: Linux Alpine

bild

bild

@mikkeschiren mikkeschiren added Potential Bug Something that might be a bug, but can't be reproduced (yet). To Triage An issue awaiting triage by a Matomo core team member labels Dec 25, 2022
@mikkeschiren
Copy link
Contributor Author

As an example, the cache for "carbrowser604-all" is requested 30 times for one request on the example report, which contains no devices at all. All the cache requests return the same thing.

@mikkeschiren
Copy link
Contributor Author

My guess is that every day in the visitor overview, which is 30 days, makes requests for the cached items of devices.

@sanchezzzhak
Copy link

This is the expected behavior for Device Detector, since one php instance is launched for each visitor.

in my projects, I use Device Detector like this:

namespace app/helpers 

class DeviceDetectorHelper 
{
    /**
     * @param string $userAgent - user agent string
     * @param array $headers - http headers
     * @return DeviceDetector
     */
    public static function detect(string $userAgent, array $headers = []): DeviceDetector
    {
        static $detector;
        if ($detector === null) {
            $detector = new DeviceDetector();
            $detector->setCache(new Cache());
        }
        $clientHints = ClientHints::factory($headers);
        $detector->setUserAgent($userAgent);
        $detector->setClientHints($clientHints);
        $detector->parse();

        return $detector;
    }

}

I will share my experience, maybe give ideas for the future
I analyze data in the background, I write all the data to the buffer table as is.
in the console script, I analyze the data from the buffer table.

the script is looped through + cron * * * * *
```php

// mutex file lock (only single process)
if ($this->getMutex()->acquire('stat')) {
    return;
}
$repeat = 0;
while (true) {
   $data = $this->getBufferData($limit = 10000);
   $countRows = count(data);
   if ($countRows === 0 ) {
     $iterate++;
   } else {
     // prepare visitors save and clean tmp buffer data;
     $this->processBufferAndClean($data);
      countine;
   }
   // if there is no data for more than 3 attempts, we exit
   if ($iterate === 3) {
       break;
   }
   // timeout delay 5 second
   sleep(5);
}

with this approach, you lose the minimum amount of time.

@mikkeschiren
Copy link
Contributor Author

Ok, so you are not using the plugin to get the devices?

@sgiehl
Copy link
Member

sgiehl commented Jan 9, 2023

@mikkeschiren He is using device detector for something else than Matomo.
Nevertheless your report does not have anything to do with the DevicesDetection plugin.
Matomo tries to identify the browser as user is visiting with in order to display a warning if it is not supported.
This should normally be at most done once per request and should also be cached.
Might be worth looking at that, as doing unneeded device detections might cost some useless time.

@sgiehl sgiehl removed the To Triage An issue awaiting triage by a Matomo core team member label Jan 9, 2023
@sgiehl sgiehl added this to the For Prioritization milestone Jan 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Potential Bug Something that might be a bug, but can't be reproduced (yet).
Projects
None yet
Development

No branches or pull requests

3 participants