Memory leak
Noticed a minor memory leak in my project, after some debugging I was able to trace it back to DiscordPHP-Http
Executing API calls keeps taking up more memory. It doesn't appear to plateau at some point.
I verified this with the following code
<?php
use ByteUnits\Metric;
use Discord\Http\Drivers\React;
use Discord\Http\Endpoint;
use Discord\Http\Http;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use React\EventLoop\Loop;
require './vendor/autoload.php';
$log = new Logger('stability-bot');
$log->pushHandler(new StreamHandler('dhttp.log'));
$http = new Http(
'Bot <TOKEN>',
Loop::get(),
$log,
new React(
Loop::get(),
)
);
Loop::get()->addPeriodicTimer(3, function () use ($http) {
$http->post(
Endpoint::bind(
Endpoint::CHANNEL_MESSAGES,
'577119668448526359'
),
[
'content' =>
'Memory usage: '
. Metric::bytes(memory_get_usage())->format()
]
);
});
{
"require": {
"discord-php/http": "^10.1",
"monolog/monolog": "^3.3",
"gabrielelana/byte-units": "^0.5.0"
}
}
It starts out like this:
Memory usage: 590.26kB
Memory usage: 937.66kB
Memory usage: 940.10kB
Memory usage: 942.45kB
It has an initial hike after the first message, probably because it creates a bucket for this request.
After that it consistently creeps up, ended up stopping it after about 20-30 minutes
Memory usage: 2.75MB
Memory usage: 2.76MB
Memory usage: 2.76MB
Memory usage: 2.76MB
Memory usage: 2.76MB
Memory usage: 2.77MB
Profiling output:
Won't attach the complete profile as this may also contain information like my discord token
Re-tested with Guzzle driver instead of React, problem persists.
Retested some more, issues not present when using React HTTP or Guzzle HTTP without this lib memleak-testing.zip
https://github.com/discord-php/DiscordPHP-Http/pull/20
@Exanlv I believe I found the issue.
#20
@Exanlv I believe I found the issue.
Thank you, that is one of it, but there's probably more so issue still open