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

This small script leaks memory at a very high rate #2220

Open
akarelas opened this issue Jan 10, 2025 · 3 comments
Open

This small script leaks memory at a very high rate #2220

akarelas opened this issue Jan 10, 2025 · 3 comments
Labels

Comments

@akarelas
Copy link
Contributor

akarelas commented Jan 10, 2025

  • Mojolicious version: 9.39
  • Perl version: VERSION v5.40
  • Operating system: Debian Linux 12 (bookworm)

Steps to reproduce the behavior

Execute this script:

use Mojo::Base -strict, -signatures, -async_await;

use Mojo::Promise;
use Mojo::IOLoop;

async sub foo {
    my $counter = 0;
    while (1) {
        if (++$counter % 1_00 == 0) { say $counter; }
        await sleep_p(0.001);
    }
}

foo();

Mojo::IOLoop->start;

sub sleep_p ($duration) {
    my $p = Mojo::Promise->new;
    Mojo::IOLoop->timer($duration, sub { $p->resolve });
    return $p;
}

Memory usage (as reported by htop) keeps increasing all the time, at a high rate.

Expected behavior

Memory usage should remain stable, constant, not changing.

Actual behavior

Memory usage (as reported by htop) keeps increasing all the time, at a high rate.

@akarelas
Copy link
Contributor Author

PEVANS said here (where I reported the same bug) that when he replaced Mojo with Future::IO, he got no leak. So maybe the problem is here (Mojo).

@christopherraa
Copy link
Member

christopherraa commented Jan 11, 2025

Just to make sure this isn't some kind of regression I ran the script on multiple versions of Mojolicious back to 9.31. My first thought was that maybe the changes to Mojo::Base could be the case. This turned out to be a dead end. Average of a couple of runs on various Mojolicious versions:

Version Memory (kb)
9.39 438912
9.38 437184
9.37 437568
9.36 437760
9.35 437568
9.34 437184
9.33 437760
9.32 437760
9.31 437376

This was done very unscientifically by running the script and dumping memory usage with ps -p $pid -o %mem,rss when the counter reached 50000 -ish. The above numbers are as mentioned averages of multiple runs on each version.

In summary: no real consequential difference between the versions.

@kraih kraih added the bug label Jan 11, 2025
@kraih
Copy link
Member

kraih commented Jan 11, 2025

Probably a bug.

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

No branches or pull requests

3 participants