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

Memory usage #2

Open
tricarte opened this issue Jan 31, 2024 · 0 comments
Open

Memory usage #2

tricarte opened this issue Jan 31, 2024 · 0 comments

Comments

@tricarte
Copy link

Hello. Thanks for this library.

In the example code, you say there is no need to return the connection back as they will be returned when the coroutines are destroyed. I need a clarification here. Here is a sample code. Notice that I have changed the namespace but it is irrelevant at this point:

<?php

require __DIR__ . '/vendor/autoload.php';
(new Database\ConnectionPool\PDOConfig())
    ->withDriver('mysql')
    ->withHost('127.0.0.1')
    ->withDbname('someDatabase')
    ->withUsername('admin')
    ->withPassword('password')
    ->withCharset('utf8mb4')
    ->setConfig('default');

Database\ConnectionPool\PoolManager::addPool(2, 'default');

\Swoole\Runtime::enableCoroutine();
\Swoole\Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);

echo "Benchmark started\n";
for ($i = 0; $i < 15; $i++) {
    $s = microtime(true);
    \Swoole\Coroutine\run(function () {
        for ($i = 0; $i < 10000; $i++) {
            \Swoole\Coroutine::create(function () {
                $builder = Database\ConnectionPool\Adapter\Manager::table('people');
                $people = $builder->get('name');
            });
        }
    });
    echo 'Benchmark time:' . (microtime(true) - $s) . "second[s]\n";
}

sleep(5);

It's just your example with a sleep() added at the end. And I create 10000 coroutines in a loop exactly 15 times. On each iteration of the outer loop, the memory used raises. This is what I found abnormal. So the question is: Is this the normal behaviour?

Actually, I tried to integrate this library into another Swoole based web framework called Fomo. Interestingly when I benchmark the relevant url, on each benchmark, used memory keeps raising and raising.

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