Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Huge speed boost compared to monolog #9

Open
8ctopus opened this issue Jul 28, 2022 · 1 comment
Open

Huge speed boost compared to monolog #9

8ctopus opened this issue Jul 28, 2022 · 1 comment

Comments

@8ctopus
Copy link
Contributor

8ctopus commented Jul 28, 2022

Hey Franck,

Did some speed tests comparing Apix vs. Monolog, it turns out in deferred mode, the speed gains are huge.

-----------------------------------
platform           :      WINNT x64
php version        :          8.1.4
xdebug             :             on
memory limit       :           512M
max execution      :              0
time per iteration :           20ms
iterations         :            250
-----------------------------------
---------------------------------------------------------------
0                  : logger_monolog   logger_apix
mean               :             25          1430      +5564.1%
median             :             18          1756      +9934.3%
mode               :              3          2013     +67000.0%
minimum            :              1            28      +2700.0%
maximum            :             73          2183      +2890.4%
quartile 1         :              5           750     +14900.0%
quartile 3         :             51          1979      +3780.4%
IQ range           :             46          1229      +2571.7%
std deviation      :             21           654      +2941.1%
normality          :          30.7%         30.7%
---------------------------------------------------------------

And respective code

$file = new Apix\Log\Logger\File('log_apix.log');
$file
    // intercept logs that are >= `warning`
    ->setMinLevel('warning')
    // don't propagate to further buckets
    ->setCascading(true)
    // postpone/accumulate logs processing
    ->setDeferred(true);

$log = new Apix\Log\Logger([$file]);

$stdout = new Apix\Log\Logger\Stream('php://stdout', 'a');
$stdout
    // intercept logs that are >= `warning`
    ->setMinLevel('warning')
    // don't propagate to further buckets
    ->setCascading(true)
    // postpone/accumulate logs processing
    ->setDeferred(true);

$log->add($stdout);

while (microtime(true) < $time_limit) {
    $log->warning('test');
    ++$iterations;
}
$log = new Monolog\Logger('test');
$log->pushHandler(new Monolog\Handler\StreamHandler('log_monolog.log', Monolog\Level::Warning));

// log to stdout
$log->pushHandler(new Monolog\Handler\StreamHandler('php://stdout', Monolog\Level::Warning));

while (microtime(true) < $time_limit) {
    $log->warning('test');
    ++$iterations;
}
@8ctopus
Copy link
Contributor Author

8ctopus commented Aug 12, 2022

Slightly updated the test with regular flushing intervals for apix (every 200 logs). It decreases the advantage of apix over monolog, but it's still very present:

-----------------------------------
platform           :      WINNT x64
php version        :          8.1.9
xdebug             :             on
memory limit       :           512M
max execution      :              0
time per iteration :           50ms
iterations         :            250
-----------------------------------
---------------------------------------------------------------
0                  : logger_monolog   logger_apix
mean               :            107          2373      +2108.6%
median             :            111          2496      +2148.2%
mode               :             82          2600      +3070.7%
minimum            :              3           499     +16533.3%
maximum            :            175          3000      +1614.3%
quartile 1         :             82          2203      +2586.6%
quartile 3         :            136          2694      +1880.9%
IQ range           :             54           491       +809.3%
std deviation      :             36           476      +1234.2%
normality          :           3.2%          3.2%
---------------------------------------------------------------

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant