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
Make widgets load faster on Piwik dashboard, and sparklines load faster on All Websites #7104
Comments
+1 for refactoring the session handling. |
I dont know if that would be correct. I close the session it in my application for some AJAX requests or longer exports where i know the session is only read. If you always close the session and reopen it, the behaviour could be strange (already had gone through that) Example: 2 requests are submitted from the user at the same time After the 2 requests, #1 have won and the change from request #2 is lost. The only "clean" solution in my mind, is to close it at the Plugin or explicit action level. |
Just to keep in mind: For the little benchmark i used a production system, which have 2 servers: one for apache/php and one for mysql (each one got 4 CPU and 8GB memory). Maybe a not so "powerful" setups could get problemes with the number of requests |
The problem will be to know which requests are session read only and which ones are read/write... I presume we don't use the session for API reports, eg we could close it immediately again for calls against the Metadata API (API.getProcessedReport, API.getReportMetadata) as eg. the mobile app sometimes requests many processed reports at once. Other API calls might use the session for some reason. In the UI the performance benefit would be more or less only relevant for the dashboard within the "Dashboard Report page" when many widgets are requested at once. We could close the session directly if It would be nice to test this on some more (production) servers. Eg on my local instance there is not really a performance benefit but this has different reasons... |
I did another test on a production system. I reloaded the pages many times to make sure it is not a random result because of something else. Without session close (load event after 8.8s): With session close (load event after 7.8s): As one can see most reports load faster especially the ones further below (they have to wait longer). Some requests take only 1 second instead of 3. For some other the benefit is not as big (because they didn't have to wait that long of course). One was actually able to see that reports were loading a bit faster and more in "parallel". BTW: Interesting was too see that getSearchEngines seems to be pretty slow! |
Re slow searchEngines report see #7119 . Prepared a pull request... |
If we make Piwik use Database sessions by default rather than file sessions, would this solve the concurrent session issue and slowness? |
Nope, it wouldn't I think |
Is this issue |
I think this should be done partly in short term for some views. e.g my "All websites dashboard" also needs nearly 2min to load all evolutionGraphs from the 37 websites. With See the PR #7166 |
I think we can work on it in Piwik 2.12.0 but would only do it for widgets (win for Piwik) and Edit: Sparklines might benefit from it as well! |
Added to 2.12 as per your note! |
FYI: I noticed for all API calls we already do not even start the session. So we do not have to care about |
…ajax requests are made within widget or when sparklines are requested
Nonces shouldn't be a problem as we use TTL based expiration and not hops based (which are usually more "secure"). If we try to write an Nonce and session was already closed an exception will be triggered and shown in the UI (as anyone could append Otherwise only notifications can be a potential problem I think but those widget and sparkline requests shouldn't trigger any. In an implementation I am working on I do check whether there is a referrer so in case one opens it directly we would still display/register those notifications. I don't check the referrer for security as anyone can send any referrer anyway. For example we do need to check the referrer in case the URL parameter If referrer information is not there (eg was filtered because of whatever) the session would just be not closed but everything would still work. For the widget requests that also have a |
I will maybe do another test for this on our demo test server to check whether there is a performance improvement. @ThaDafinser maybe you can give this change a test as well? https://github.com/piwik/piwik/compare/7104 |
@tsteur i use now your patch. For now it seems to work. If i get problems, i will inform you 👍 |
…ion. Sometimes, eg when module=API, we do not start a session. If any code part during such a request uses SessionNamespace although we did not start a session, Zend_Session_Namespace will start a Zend_Session which does not respect our configuration. It would use default Zend Session options and therefore probably file based sessions. Therefore, we force the creation of a "Piwik session". If we have created the session before it won't be started again.
Kuddos @ThaDafinser for the suggestion and @tsteur for the power fix! |
tl;dr:
Change https://github.com/piwik/piwik/blob/master/core/FrontController.php#L470 with this code (its an ugly hack to just show the gain)
Somehow i always felt that the GUI, especially the dashboard, is quite slow.
I now measured it and and remembered an easy solution when i comes to speed up AJAX requests.
Since Piwik starts the session for each request, all pending requests are queued by php if i remember correctly https://github.com/piwik/piwik/blob/master/core/FrontController.php#L470
(Reason: every request could write to the session and so it should be queued to have consistent session data)
So if you disable the ability to write session, the queueing is not needed anymore.
_Note_
This is an ugly hack to just show the performance gain! Of course each action (or plugin) have to decide if it dont need to write anytime
without hack
with hack
.
The text was updated successfully, but these errors were encountered: