The Live! plugin is now bundled in Piwik core but disabled by default. Here is the list of bugs or changes that we would like to address for a public release:
Bugs
See original ticket at #44
Keywords: visitor log, live plugin
Attachment:
piwik.patch
Attachment:
Live.patch
Attachment:
Live.zip
Attachment:
Live2.patch
Attachment:
Live-0-5-5.zip
Attachment:
Piwik-3.patch
Attachment:
Live-0-6-rc2.patch
Attachment: Adjustment of the Plugin to new UI
LivePluginDesignAdjustment.patch
Attachment: Fixing #1375, #1319
[#1120-27LivePlugin.diff](http://issues.piwik.org/attachments/1120/#1120-27LivePlugin.diff)
Attachment: 1st review worked into
[#1120-#v2.patch](http://issues.piwik.org/attachments/1120/#1120-#v2.patch)
Attachment:
[#1120-#v2-1.patch](http://issues.piwik.org/attachments/1120/#1120-#v2-1.patch)
Attachment: Show goal details per action; Highlight action field in the row, where conversion happened; + Minor Updates
[#1120-#20100731-v2.patch](http://issues.piwik.org/attachments/1120/#1120-#20100731-v2.patch)
http://www.wpwp.org/ -> nice idea for live statistics
This wordpress stats plugin looks nice indeed: http://www.wpwp.org/whatis/ the spyview with the google maps is interesting.
(In [1803]) refs #1120 - suppress broken image link where no search engine icon defined
Now added the actual Version:
open issues:
Live Widget
Visitor Log
(In [1868]) refs #1120 - merged from Live.zip as there were too many conflicts with piwik.patch against the svn trunk
Thomas: please "svn up" and sanity check my merge. Thanks.
Performance issues
To understand the problem, you can enable mysql slow query log and try to generate the Live! on a test website with 50,000 visits per day, generated using the visits generator.
To solve the issue, we can either: add new INDEXes on the log tables (not really something we would like to do), or we can denormalize the log tables so that we can fetch the data without doing JOINs.
Performance issues
We need an new index:
ALTER TABLE piwik_log_visit
ADD INDEX index_visit_last_action_time
( idsite
, visit_last_action_time
)
So i added and replaced the live.zip with the actual stand of the svn.
I also added a patch named live.patch. I can't delete the piwik.patch file :-(
jr-ewing, adding a new index is possible but very heavy update task. Can you please document why this index is needed and why is is sufficient to make Live! plugin work fine on high traffic website? for example, can you post mysql slow logs before and after the INDEX, details of the website you are testing against (how much traffic today, yesterday, the last N days, etc.)
Thanks!
Reported on the forum: when the Live widget refreshes, it reverts back to displaying visits from idsite=1, while the rest of the dashboard is displaying a different idsite (e.g., 2).
Problem:
Live-Plugin triggers slow query, that locks up the table. This is especially critical, when it is used over the desktop client since it doesn't wait for a query to finish. The query stack then fills up until - in worst case - the database crashes.
Adding an index to the single col visit_last_action_time may solve the problem.
For testing, I used a simplified SQL-Query in a simplified test-case (query cache off / flushed):
("SELECT * FROMpiwik_log_visit
WHERE
idsite= 2 AND
visit_last_action_time` > DATE_SUB( NOW( ) , INTERVAL 30
MINUTE )")
There are ~2Mio rows in the whole table.
Testing results:
Then I added an index to visit_last_action_time (ALTER TABLE piwik_log_visit
ADD INDEX ( visit_last_action_time
) )(query time ~35 s):
A deeper view in this explains, why this key changes the query times so much:
SQL: (EXPLAIN SELECT [...] INTERVAL 10 DAYS..) - changed interval to 10 days, because the effect is manifesting better here:
previosly (without the index on visit_last_action_time), MySQL uses the index_idsite_date_config-key for the query (since idSite is in the where-clause). MySQL then scans all Rows, where idSite is x and then sorts out the rows where the date-range definition of the query doesn't fit. This causes a big data throughput because many rows are queried that aren't needed in the end.
With an index on visit_last_action_time, MySQL changes the query-type to "range" and uses the visit_last_action_time-index for the query. So it doesn't fetch any other rows that aren't needed in the result set. A lot of data overhead could be saved here to speed the query up extremely.
Cheers
A deeper look at the problem seems to be tracked down to this (extracted Query):
("SELECT piwik_log_visit.* , piwik_goal.match_attribute
FROM piwik_log_visit
LEFT JOIN piwik_log_conversion ON piwik_log_visit.idvisit
= piwik_log_conversion.idvisit
LEFT JOIN piwik_goal ON piwik_goal.idgoal
= piwik_log_conversion.idgoal
AND piwik_goal.deleted
= 0
WHERE piwik_log_visit.idsite = '3' AND piwik_log_visit.idvisit > ''
ORDER BY idvisit DESC
LIMIT 10")
These multiple Joins are extremly expensive for performance because MySQL is using nested loops. In this case, MySQL joins over a Million rows (using a tmp table) and then limits them to the ten highest idvisit-id's. This is a huge piece of data to process. As we can't know how large the tables will grow in a high-traffic environment, we should avoid table joins here but rather use a stepwise approach: fetching the relevant idvisit-id's from the first table, query them from the second one and so on. So it will be possible to build an array of correlated data and it's mich faster.
Cheers
Note, the work on the timezone see #5476, will add an index on ( idsite , visit_last_action_time ) which should help with Live! performance issues correct?
the new index will be available in the next public release (likely 0.6)
With this new INDEX, are there still performance bottlenecks on high traffic websites?
Actually, the exact INDEX is likely to be
'ALTER TABLE ' . Piwik::prefixTable('log_visit') . ' ADD INDEX `index_idsite_datetime_config` ( `idsite` , `visit_last_action_time` , `config_md5config` ( 8 ) ) ;' => false,
but we will remove the existing INDEX piwik_log_visit.visit_server_date - will this pose some problem to Live! plugin?
Replying to matt:
Yes the index will help enormous
With this new INDEX, are there still performance bottlenecks on high traffic websites?
No - i have 6000 Visits on a Webseite a day with response time of 2,4s
piwik_log_visit.visit_server_date is not using by the live plugin.
but it would be useful to test it on the Piwik Demo
2.4s sounds reasonnable, but still quite slow; is the INDEX fully hit during the query?
Also, would it be possible to add the request throttle, so that you only send one request at a time, and not queue up requests on the server? Currently, I believe that if the request hits the DB and takes 60s to return, the Live! plugin will queue up dozens of requests, killing the webserver. What do you think?
We need one Request to get
For all these Requests we need the index because we only need the last visitors.
Point 1-4 is repeat every 20 Sec.
Point 5 is also performant, because getting the goals for every pageview for the last 10 visitors. For this feature 2 Joins are needed :-(
So i dont know how to get a good performance for so many data.
The new INDEX was committed to trunk: see http://dev.piwik.org/trac/changeset/2006#file14
jr-ewing, my comment meant that the Javascript should only send the request to the server if the previous AJAX request was received. You could add a test in the response handler that would set a flag, allowing other AJAX to trigger. If the flag is not set, it means that the AJAX request wasn't received yet and no other requests should go to the DB until the first request was received.
(In [2019]) refs #1120 - commiting update from Live-0.5.5.zip
I enabled Live! plugin on piwik.org/demo and it broke down the server.
Here is the mysql Slow query analysis:
Tab Visitors>Visitor Log
Count : 2 (7.69%)
Time : 319 s total, 159.5 s avg, 140 s to 179 s max (9.71%)
Lock Time (s) : 0 total, 0 avg, 0 to 0 max (0.00%)
Rows sent : 1.00k avg, 1.00k to 1.00k max (44.37%)
Rows examined : 7.51M avg, 7.51M to 7.51M max (47.51%)
Database :
Users :
user<a class='mention' href='https://github.com/localhost'>@localhost</a> : 100.00% (2) of query, 92.31% (24) of all users
Query abstract:
SELECT piwik_log_visit.* , piwik_goal.match_attribute FROM piwik_log_visit LEFT JOIN piwik_log_conversion ON piwik_log_visit.idvisit = piwik_log_conversion.idvisit LEFT JOIN pi
wik_goal ON piwik_goal.idgoal = piwik_log_conversion.idgoal AND piwik_goal.deleted = N WHERE piwik_log_visit.idsite = 'S' ORDER BY idvisit DESC LIMIT N;
Query sample:
SELECT piwik_log_visit.* ,
piwik_goal.`match_attribute`
FROM piwik_log_visit
LEFT JOIN piwik_log_conversion
ON piwik_log_visit.`idvisit` = piwik_log_conversion.`idvisit`
LEFT JOIN piwik_goal
ON piwik_goal.`idgoal` = piwik_log_conversion.`idgoal`
AND piwik_goal.`deleted` = 0
WHERE piwik_log_visit.idsite = '1'
ORDER BY idvisit DESC
LIMIT 1000;
Fix
Live! Widget
Queries now run fast, except the first one that is the same as the one above.
fixing this query should therefore fix performance issues with the Live! widget. I'm not sure whether to limit the Visitor log to the last day, or more. Users might want to access logs from older dates too. Maybe the query for the Live! widget only should restrict to the last 24 hours, when the visitor log LIMIT 1000 would limit to the last 7 days?
The proper solution would be to have the visitor log fetch each day separately automatically when clicking Next or Previous (and have the last date as a parameter).
(In [2097]) Refs #1120
(In [2105]) Refs #1120 by tom
Fixes hover cursor
(In [2115]) refs #1120 - commiting jr-ewing's Live-0-6-rc2.patch
(In [2196]) Refs #1120 Live! plugin i18n
Live Plugin doesn't shown every Pages that a User visits.
It seems that a double visit to the same page aren't shown.
To replecate this Error go to your Page an click the same page twice or more.
The Live Plugin shows only the first Visit of each Page.
May be it's desired to see only the uniqe pages the user visited?! For me it is useful to see the whole path the user is gone, to see on which pages the user may be confused and are not going the path that i prefer for him.
See bug report in http://forum.piwik.org/index.php?showtopic=11001
(In [2787]) Coding style, Refs #1120
(In [2788]) Modification for new Minify-API, Refs #1120
(In [2808]) Refs #1120
Adding missing js to hook + Minor updates
Some great progress has been made on this widget by Peter. Postponing next requests to post 1.0...
(In [2832]) Refs #1120; Show goal details per action; Highlight action field in the row, where conversion happened; + Minor Updates; Must refresh assets;
From email: A very cool UI improvement for the same page could be to display the whole referrer link but only the domain-name in black, the URI in light grey beneath.
(In [2865]) Refs #1120
simplifying Visitor log line for conversions, removing date and some bold.
Reusing same goal icon as common goal icon.
Idea from forum: in visitor log, would be interesting to see a link for returning visitors that would show all previous visits.
I'm working on adding customizable icons to the Visitor Log - basically, if a specified regex matches the URL, use a specified icon instead of the default. This can be set up to display the main types of pages on a site at-a-glance or to highlight key pages.
I'm doing this inside visitorLog.tpl. Couple questions - first, where should I be storing/loading the configuration from? Also, and more importantly for this ticket, what needs to be done to make this something that could be rolled in to the core plugin?
Excuse me, that should be "inside liveVisits.tpl" - oops.
ian, I would propose something around adding a hook that would modify the table of visitor details, at the end of getCleanedVisitorsFromDetails ?
(In [3331]) Fixes #1794, Refs #1120
(In [3332]) Refs #1120
I thought to reopen this ticket by detailing an improvement / optimization that can be done (by moving count() functionality into SQL query):
a) From "SELECT " . Piwik_Common::prefixTable('log_visit') . ".idvisit" to "SELECT count(" . Piwik_Common::prefixTable('log_visit') . ".idvisit) AS count"
b) From "SELECT " . Piwik_Common::prefixTable('log_link_visit_action') . ".idaction_url" to "SELECT count(" . Piwik_Common::prefixTable('log_link_visit_action') . ".idaction_url) AS count"
a) From "return count($visitors_halfhour)" to "return $visitors_halfhour[0]['count']"
b) From "return count($visitors_today)" to "return $visitors_today[0]['count']"
c) From "return count($pis_halfhour)" to "return $pis_halfhour[0]['count']"
d) From "return count($pis_today)" to "return $pis_today[0]['count']"
That's a huge difference, unless I'm missing something and this functionality is used also somewhere else (in that case I'd suggest creating separate functions for counting visits and pageviews and fetching those data).
Can you attach an actual diff (i.e., "svn diff") to #1839?
Replying to eistrati:
Yes, where the view is only displaying the number of visitors, it would be more efficient to use a SQL query that COUNT()s. However, changing that private method in API.php changes the semantics of the Live API.