Matomo makes website very slow once per hour

I am managing the website embeetle.com and I recently installed Matomo (self-hosted). Since then, the website reacts very slowly from time to time, with loading times of multiple seconds up to 60 seconds and the browser showing it is waiting for Matomo. Normally, the website home page loads in less than a second.

The website currently has very few visitors (a few per day) but I expect that to change soon, so it is important to get rid of this delay. In an attempt to figure out what is wrong, I wrote a script that downloads (using wget) the website’s home page and also does the same http request as the javascript code for Matomo. The home page always loads fast, but the Matomo request is very slow just once per hour. Other requests are fast. My conclusion is that the problem is not my server, but something in the Matomo code.

Except for this hourly delay, Matomo seems to work well.

I have no clue how to continue debugging this issue, so I am looking for suggestions.

I am running Matomo 3.13.0. The server is a VPS running Ubuntu with Nginx.

This is the Matomo code in the head section of the embeetle home page:

<script type="text/javascript">
  var _paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(["setDomains", ["*.embeetle.com"]]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  _paq.push(['enableHeartBeatTimer']);
  (function() {
  var u="//matomo.embeetle.com/";
  _paq.push(['setTrackerUrl', u+'matomo.php']);
  _paq.push(['setSiteId', '1']);
  var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

And this is the script I use for testing:

#!/bin/sh
mkdir -p ~/work/matomo-test
cd ~/work/matomo-test

while true; do
etime=$({ /usr/bin/time -f ‘%e’ wget ‘https://embeetle.com’ -a embeetle.log; } 2>&1)
mtime=$({ /usr/bin/time -f ‘%e’ wget ‘https://matomo.embeetle.com/matomo.php?action_name=Embeetle%20IDE&idsite=1&rec=1&r=506807&h=12&m=12&s=52&url=https%3A%2F%2Fembeetle.com%2F&_id=f8c7680a866091c6&_idts=1572725488&_idvc=26&_idn=0&_refts=1574593973&_viewts=1574593973&_ref=https%3A%2F%2Fembedoffice.com%2F&send_image=1&pdf=0&qt=0&realp=0&wma=0&dir=0&fla=1&java=0&gears=0&ag=0&cookie=1&res=1680x1050&gt_ms=165&pv_id=7O7vI4’ -O matomo.gif -a matomo.log; } 2>&1)
echo “$(date) $etime $mtime” | tee -a test.log
sleep 300
done

Hi,

Do you by chance have set up a cron job for Matomo:
https://matomo.org/docs/setup-auto-archiving/

Good question, but no, I do not have a cron job for Matomo. There are also no other hourly cronjobs on the server.

Hi,

My guess would be the following: Matomo needs to run all kind of scheduled tasks regularly (you can view them with Tasks Timetable - Matomo Plugins Marketplace). And when you don’t have a cronjob set up, this needs to be done during the normal piwik.php call which might cause it to take a longer time. Maybe try to set up a cronjob and see if it improves.

Setting up a cron job for archiving and changing the settings to not archive reports when viewed from the browser does indeed improve the situation a lot. I am still testing to confirm this, but the hourly very long load times are gone. Thank you for your advice.

The Tasks Timetable plugin shows 21 other scheduled tasks, and the website is indeed still a bit slow from time to time (between and 2 seconds). Is there a way to run these other tasks in a cron job as well?

I am surprised that the advice given in the UI to use a cronjob for archiving is for medium to high traffic websites only. I experienced loading delays of more than a minute for the underlying website (not the Matomo UI), which doesn’t seem acceptable for any website including low traffic websites.

For medium to high traffic websites, it is recommended to disable Matomo
archiving to trigger from the browser. Instead, we recommend that you
setup a cron job to process Matomo reports every hour.

I’m pretty sure the cronjob also runs scheduled tasks:

@Lukas I guess you are right about most of the tasks. However, I am still observing a delay of 1.5 to 4 seconds approximately every hour at half past the hour. According to the Tasks Timetable plugin, there are no scheduled tasks at that time; all scheduled tasks are at the hour (9:00, 12:00, …) and never around half past the hour (9:26, 10:27, 11:28, …).

So I am still looking for ideas on how to figure out what is happening here.