Initial Connect Optimization

Only just started using Piwik (1.1.1) a few weeks ago and love it!

One annoying thing we’ve noticed is that when a user initially accesses a site page there is a delay of 5-10 seconds for that first Piwik access (verified that removing the Javascript code from the page eliminates the delay). Haven’t found anything related in the documentation or FAQ.

The working assumption is that this is related to the initial DB connection (using MySQL (4.1.12a-nt) on a Windows Server 2008).

Piwik is running on the same server so the embedded Piwik script code defines pkBaseURL by a relative URL as ‘…/piwik/’
(a fully qualified URL has the same delay problem)
We’ve also modified the hosts file to include the server/IP name
both hoping to minimize any DNS associated delays in the DB connection.

Looking for other configuration / optimization suggestions to minimize or eliminate that initial delay.




the things you say sound quite unusual to me. I am no Win server expert but having a 5+ second delay while opening a socket to your DB looks to me as if your server suffers from serious performance issues. My first bet is to not look at Piwik but at MySQL. A good starting point, given that your databases reside on performant storage and you have enough free RAM, might be MySQL :: MySQL 5.7 Reference Manual.
Also, take a look at the included example confiurations, i might be wrong but i think i once saw a Windows-optimized MySQL.conf around there.

Good Luck,


Please make use of firebug to check, where the delay is exactly caused (dns / query data / response data / etc.)

  1. Use the asynchronous tracking method to improve the perceived page load/render performance.
  2. Use the js/ proxy to compress (and cache) piwik.js
  3. Apply this patch to core/Tracker.php (only works for first party cookies):
Index: Tracker.php
--- Tracker.php	(revision 4022)
+++ Tracker.php	(working copy)
@@ -83,6 +83,8 @@
 	public function main()
+		$this->outputTransparentGif();
 		try {
@@ -133,7 +135,7 @@
 			case self:: STATE_LOGGING_DISABLE:
 				printDebug("Logging disabled, display transparent logo" );
-				$this->outputTransparentGif();
+// 				$this->outputTransparentGif();
 			case self:: STATE_EMPTY_REQUEST:
@@ -145,7 +147,7 @@
 			case self:: STATE_NOTHING_TO_NOTICE:
 				printDebug("Nothing to notice => default behaviour" );
-				$this->outputTransparentGif();
+// 				$this->outputTransparentGif();
 		printDebug("End of the page." );

Definitely try the first two.

Caveat: the patch to Tracker.php may not have any effect due to output buffering.