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

Large volume of transactions causes memory depletion #54

Open
Nerahikada opened this issue Oct 23, 2022 · 3 comments
Open

Large volume of transactions causes memory depletion #54

Nerahikada opened this issue Oct 23, 2022 · 3 comments
Labels
wontfix This will not be worked on

Comments

@Nerahikada
Copy link
Contributor

Nerahikada commented Oct 23, 2022

If the database server is slow and takes a long time to process transactions, attempting to process a large number of transactions will create a large number of connections and cause the server to crash due to lack of memory.

Using slow database, you can reproduce it with code like this

use SOFe\Capital\{Capital, CapitalException, LabelSet};

Capital::api("0.1.0", function(Capital $api){
    $this->selector = $api->completeConfig(["currency" => "money"]);
});

$this->getScheduler()->scheduleRepeatingTask(new ClosureTask(function(){
    foreach($this->getServer()->getOnlinePlayers() as $player){
        Capital::api("0.1.0", function(Capital $api) use ($player){
            yield from $api->addMoney($this->getName(), $player, $this->selector, 1, new LabelSet([]));
        });
    }
}), 1);
@SOF3 SOF3 added the wontfix This will not be worked on label Oct 23, 2022
@SOF3
Copy link
Owner

SOF3 commented Oct 23, 2022

It doesn't create a large number of connections. It just queues a huge backlog of queries to execute.

This is not exactly a bug, because each addMoney call is supposed to be atomic and has its own failure status, so it would be incorrect if Capital tries to buffer these calls because that would result in confusing failure behavior. If you would like to add money per tick, perhaps you should implement your own buffer.

This is comparable to the real-life scenario where you wouldn't pay an employee their salary every hour even though their wage is measured hourly.

I consider this issue as a wontfix for now, but any suggestions to improve this would be welcome.

@Nerahikada
Copy link
Contributor Author

I don't think there are actually many situations to add money per tick, but the more currency and number of players, the more likely this is to occur.

@SOF3
Copy link
Owner

SOF3 commented Oct 23, 2022

In that case you should increase the number of workers in the libasynql settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants