HyperLogLog is an algorithm that provides 97% accuracy on cardinality counts (ie, unique visitors), while using a very small memory footprint. We could add support for this algorithm within Piwik to not only provide fast cardinality for large numbers of visits, but also we can use it to provide a unique visitor count for any period. HyperLogLog results can themselves be aggregated, so they can be stored in archive tables as blobs.
I also heard of Bloom filters doing good job: https://en.wikipedia.org/wiki/Bloom_filter
According to the second article, bloom filters will take up more space (though provide more accuracy) and the results cannot be merged so the process cannot be done in parallel across several machines.
btw there is now HyperLogLog data structure in Redis http://antirez.com/news/75
simple explanation of how it works https://stackoverflow.com/a/12734343/3759928
MySQL has UDFs (user defined functions) that we could use for this, but we use MySQL on AWS, and from my research, there doesn’t seem to be a way to use UDFs on Aurora, or RDS.
PostgreSQL on the other hand, has an extension called postgresql-hll, which is available on PostgresSQL RDS.
Apparently possible to implement hyperloglog in pure SQL: https://www.periscope.io/blog/hyperloglog-in-pure-sql.html
We recently ran some tests with hyperloglog in matomo to use instead of
COUNT(DISTINCT idvisitor) and noticed in every case it was far more efficient.
Details about the test:
COUNT(DISTINCT idvisitor)on periods that ranged from having 700 distinct visitors to 50,000,000 distinct visitors. Tests were run on day periods and month periods only.
All of this depends on whether large users would want exact numbers or a close enough estimate, but it might make Matomo usable for very high traffic websites.
Great findings @diosmosis 💯
From UI perspective when enabling this the biggest challenge will be making it clear to users when accurate numbers are used and when estimates. So if someone was to enable these estimates, then we'd need to change the metric/column name to "Estimated Unique Visitors" and update the description to mention the estimate and it's error rate etc to prevent users getting confused or reporting errors that aggregating the unique visitors from lower periods isn't the same etc.