matomo-org / matomo

Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
https://matomo.org/
GNU General Public License v3.0
19.84k stars 2.64k forks source link

Improve performance of tracker by speeding up dependency injection PHP DI #20215

Open tsteur opened 1 year ago

tsteur commented 1 year ago

See profile of a tracker request below.

image

Around 70% (105 out of 150ms in total) of the time is spend in exclusively in the first 5 methods related to DI.

Typically, methods are executed very often are over-reported in Xhprof so it might be more like 30% or so but that would be still quite a lot of time.

Not sure if there's anything we can do ourselves in terms of configuring it, or if we would need to tweak PHP DI (which we could consider paying for if there's anything that can be done).

see https://php-di.org/doc/performances.html

Maybe enabling definition cache and/or compilation is something we can look into. Any solution would need to support https://developer.matomo.org/guides/multi-tenants where a Matomo runs with hundreds or thousands of different config files / instances. Seems we could eg configure a cache directory per account for example.

tsteur commented 1 year ago

Enabling definition cache via apcu locally made the time spent in these methods up to 5 times faster for me (without xhprof might be only 3 times).

rr-it commented 9 months ago

@tsteur Is this performance data from a productive install e.g. composer install -o --no-dev?


Composer optimization

How about using the composer optimization classmap-authoritative to boost the performance?

See: https://getcomposer.org/doc/articles/autoloader-optimization.md#optimization-level-2-a-authoritative-class-maps

Activate on install: composer install --no-dev --classmap-authoritative

Or afterwards via: composer dump-autoload --no-dev --classmap-authoritative

Or add to composer.json

{
    "config": {
        "classmap-authoritative": true
    }
}

Performance in general

System: PHP-FPM with OPCache

Track page view:

grafik

Server response time under 60 ms - thats pretty awesome! :rocket:

For comparison: simple call to php-file

<?php
echo 'test';

grafik

sgiehl commented 9 months ago

@rr-it Thanks for the suggestion. Unfortunately we can't easily use classmap-authoritative. For all classes in core that might not be a problem, but when a new plugin is installed, those classes would be missing in the class map. So we would need autoloading nevertheless.