@wikiloops opened this Issue on October 28th 2014

Scenario:
I am running a project on a shared hosting account and have been told to move to a dedicated server for "causing too much load".
This issue may only be relevant for rather low traffic sites on similar hosting contracts, but maybe implementing it can be easily done, so I thought I'd adress the following idea:

When analyzing my log files it became quite obvious that about 15% of all http hits of my project are caused by PIWIK, while I am seeing 1400+ visitors and around 17k pageviews/tracked actions a day.

Looking closer, it turns out a lot of the hits created are caused by the live widget refreshing.
Looks like the live widget refreshes about every five seconds, and with me having PIWIK open in some browser tab all the time, the live widget causes about as many http hits in 24 hours as the users I am tracking.

Proposed fix:
If possible, could the live Widget go to sleep as soon as the browser tab looses focus or is blurred, and wake up the moment the tab gains focus again ?

I imagine there may be quite a lot of PIWIK lovers who can't help having a look at their live statistics every now and then and keep it running like I do... this fix would save around 5% of my http hits, and it may be even more depending on the number of visitors a site has.

p.s.
I'm fairly new to GitHub, so please excuse my throwing ideas at you without creating a fork myself.
I believe someone familiar with the code will be a lot quicker doing this. Thanks for PIWIK :)

@tsteur commented on October 28th 2014 Owner

:+1:

@mattab commented on November 3rd 2014 Owner

Thanks for the suggestion, fetching real time visits only when the tab is actively viewed makes sense!

@mattab commented on November 3rd 2014 Owner

see also Make Real time Live widget faster: one bulk HTTP request instead of two #6575

@wikiloops commented on November 3rd 2014

Great, thanks for taking it on the list!
I believe there might be some more quickly-refreshing widgets like the RealTime-Map thing and the RealTime-VisitorCount which should ideally be "sent to sleep" as well.
Including the "has tab lost focus?"-check outside the widgets and passing a kind of global parameter to each widget might be a good approach to use it for all related widgets. Guess I'm just stating the obvious ;)

@Glisse1 commented on November 10th 2014

If possible, this idea of sending the live plugin to sleep (which makes sense and is a good one, especially in that low-resource server scenario) should be an OPTION.. not a forced behavior for everyone.

The best way i can think is to have it in config.ini. "Live refresh time= x seconds", "Live auto-sleep mode=disabled/enabled". Or something like that.

I for one DO want the live widget to refresh itself every couple of seconds, even without tab focus.. and i also have some customized scripts and additional php code relying on the live widget auto-refresh. And the prospect of focusing the tab and syncing all of a sudden everything that had happened since my last tab focus would turn my desktop into a complete mess :)

@wikiloops commented on November 10th 2014

@Glisse1 -
I understand your concern, and making the "sleep-mode" optional makes sense.
I'd strongly recommend to set sleep mode to "active" by default, because it lowers PIWIKs resource need quite a bit.
If I were someone offering shared hosting and had to reach a decision about wether to allow or even pre-install piwik on my tiny-budget starter accounts (which is great promo for PIWIK), I would dread the live widgets 17.5k requests per day quite a bit.
Your customized script setup will be quite unique, while the traffic/load saving is something the large majority will benefit from, and the default should respect that IMO.

@tsteur commented on November 10th 2014 Owner

@Glisse1 would it be ok if, once you focus the tab again it automatically refreshes all the displayed data? This is already done partially for real time visitors not yet for the counter and map. I am personally not a big fan of too many options and would rather try to solve it this way.

@Glisse1 commented on November 10th 2014

@tsteur the more I think the more i realize the wikiloops is right.. with respect to the fact that I, having a powerful server rented, with no problems regarding hits/day, and also in need of constant refreshing of real-time widget, am but a small minority of "power users".. if it is complicated to declare the option in config.ini, or just against the long-term vision of how piwik should be, then just drop it.. most likely there will be a way to make it auto-refresh directly in the code :)

But refreshing all displayed data on tab focus i believe is not a good idea.. and will tend to become frustrating for the user, focusing on that tab maybe tens of times per day, because there are widgets which load pretty slow, several seconds, even 10 or more sometimes, the more widgets the longer waiting..

on focus the only autorefresh must be for the real-time widget in my opinion, that`s the one that matter, the one with the real-time component.. for other widgets eg. OVERVIEW i tend to manually refresh it at the end of the day and get the data anyway.

@tsteur commented on November 10th 2014 Owner

Nice! The real time widget is already auto refreshing when focusing again. The live counter and real time map will simply update in their specified interval once the tab is focussed again. If you have defined an interval of 10 seconds it will take up to max 10 seconds until the other widgets will be updated but it could already update after 2 or 5 seconds...

BTW: There is a little trick that works at least in Chrome I think. You can open the tab in a separate browser window so it will never lose focus and will always update. Use another browser window to browse the web as normal.

FYI: It is neither complicated to add an option nor is it a long-term vision of Piwik. Some core developers even seem to love options as new ones are added quite often ;) I do not really believe in them. When we can solve it in a way to make 80% of the users happy without having to use an option it is easier for everyone. Of course this takes time and is more work than adding an option. By refreshing the data when the tab gets focus makes an option obsolete which is great as users won't have to worry about it. Most users wouldn't find the option anyway. Don't think many people actually read through all the possible config options. Probably many people don't even know about the config. In general: You can imagine that many users want to use Piwik in a different way and by adding new options all the time we end up in thousands of options which is not maintainable anymore. I'd currently rather remove some options :)

This Issue was closed on December 5th 2014
Powered by GitHub Issue Mirror