Piwik erratically slows web sites

Performance of web sites is variable, but mostly determined by the logging request to Piwik, according to testing at http://tools.pingdom.com. For example, testing on http://black-sheep-research.com most requests for the home page take nearly 8 seconds. Most of that time is the request to Piwik, to piwik.php. But a significant number of requests take less than one second. The web site is making a number of requests to the same database server as Piwik - both are connected in the same way through a private network. There is no indication of problems with the database or the servers generally. There doesn’t seem to be a general problem with the Piwik server - piwik.js is loaded quickly even when the response from piwik.php is many seconds. Oddly, if I make the Piwik PHP request from a browser, it seems to come back immediately. How can I pin down what is causing the slowness?

Allow me to mention that tools.pingdom.com has given me a lot of false responses in the past while testing. Perhaps you can use another similar service and compare the requests?

Thanks, fair point. However, see similar result at http://gtmetrix.com - http://black-sheep-research.com/gtmetrix.png
I also note with a browser that the page can load quite quickly, but then I see that piwik.php is still loading for a good number of seconds more.

I have found that in some cases using POST in the tracking code makes Piwik load faster:


<script type="text/javascript">
var _paq = _paq || [];
[b]_paq.push(['setRequestMethod', 'POST']);[/b]
_paq.push(['appendToTrackingUrl', 'bots=1']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
...

Try to disable the Provider plugin as it may be slow on some servers due to slow reverse DNS requests?

Just FYI, I tried http://gtmetrix.com on 2 of my sites (Piwik being on a different server then the Web ones) and GET Piwik was under 160 ms.

Dali

Thanks, but my tracking code doesn’t contain “POST”:


<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://piwik.webhosting-ace.net/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 4]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
    g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>

I’m seeing the same slow responses some times for piwik.php since turning off Provider plugin:

I don’t know why your Piwik is so slow. Maybe it’s a bug in PIwik but we can’t tell easily. You can enable tracker debug: Tracking HTTP API: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

Then look in the output - you can see the seconds / date time on the left.

What part of the execution takes longer?