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

Live.getCounters times out on very large instance #7399

Merged
merged 6 commits into from Mar 11, 2015
Merged

Live.getCounters times out on very large instance #7399

merged 6 commits into from Mar 11, 2015

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Mar 9, 2015

fixes #6758

We do only display the number of visits and actions in the Real time widget so let's only request those. This should make it very fast as we can avoid the visitors counter which is slow. Eg the visitors counter takes a few seconds on many million rows whereas the visits counter standalone takes maybe 0.05 seconds if at all. If someone uses the API it will be still "slow" on a very large instance.

Adding a separate query for visits and visitors shouldn't make a huge difference as the visitors one is so slow compared to the visits one.

In the actual "Live counter" widget we do only request the last 3 minutes were we shouldn't have any problem with the unique visitors counter as MYSQL will choose a different index automatically.

I added another tweak: If visits is 0 we can assume that all other counters are 0 as well so we do not execute any further query at all. We can assume this as we request the last_action_time so we should be sure there was no further action etc.

$idSite,
$lastMinutes,
$segment,
'COUNT(log_visit.visit_last_action_time)',
Copy link
Member Author

Choose a reason for hiding this comment

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

When using count(*) and passing a segment eg pageUrl this method fails. It took me a long time to figure out what is going on. Anyway, we do not get an error when passing a log_visit field here and I made sure count(log_visit.visit_last_action_time) is as fast as count(*) as it still can do everything on the index and doesn't have to query the table.

@tsteur tsteur added the Needs Review PRs that need a code review label Mar 9, 2015
@tsteur tsteur added this to the Piwik 2.12.0 milestone Mar 9, 2015
@tsteur tsteur added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. and removed Needs Review PRs that need a code review labels Mar 9, 2015
* If we know there are 0 visits, do not execute any further query.
* Added showColumns as it is more appropriate
@tsteur tsteur added Needs Review PRs that need a code review and removed Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. labels Mar 10, 2015
@mattab
Copy link
Member

mattab commented Mar 11, 2015

Looks good to me! 👍

mattab pushed a commit that referenced this pull request Mar 11, 2015
Live.getCounters times out on very large instance
@mattab mattab merged commit 3bafa52 into master Mar 11, 2015
@mnapoli mnapoli deleted the 6758 branch March 11, 2015 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants