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

Swoole\Table::set(): failed to set('161'), unable to allocate memory Due to fixed table size #648

Closed
Alistair-zhong opened this issue Feb 22, 2023 · 4 comments · Fixed by #650
Labels

Comments

@Alistair-zhong
Copy link

  • Octane Version: 1.4.0
  • Laravel Version: 8.83.27
  • PHP Version: 8.1.15
  • Server & Version: Swoole 4.8.12

Description:

I got the exception recently in the php-fpm log:

 PHP Fatal error:  Uncaught ErrorException: Swoole\Table::set(): failed to set('161'), unable to allocate memory in /var/www/vendor/laravel/octane/src/Tables/SwooleTable.php:88

My server still has 10+ GB RAM, so it should not lack memory.
Then I found the tableSize in the vendor/laravel/octane/bin/createSwooleTimerTable.php is a const: 250,

if (($serverState['octaneConfig']['max_execution_time'] ?? 0) > 0) {
    $timerTable = TableFactory::make(250);

    $timerTable->column('worker_pid', Table::TYPE_INT);
    $timerTable->column('time', Table::TYPE_INT);
    $timerTable->column('fd', Table::TYPE_INT);

    $timerTable->create();

    return $timerTable;
}

but I specified the worker number in the octane:start command is 300, php /var/www/artisan octane:start --host=0.0.0.0 --port=9000 --task-workers=600 --workers=300

so I think I got this error because my worker number is larger than the const number 250.

Expected

Can tableSize be configurable or increased by worker number?

Steps To Reproduce:

I've tried these steps on a local machine but I can't reproduce it.

  1. change 250 to 5 in vendor/laravel/octane/bin/createSwooleTimerTable.php
  2. add a web route in the routes/web.php
Route::get('sleep', function(){
    sleep(5);
    return 'good';
});
  1. start octane using command php artisan octane:start --workers=10 --max-requests=5
  2. send concurrent requests to route sleep
Http::pool(function(Illuminate\Http\Client\Pool $pool){                                                                                                              array_map(
    fn($item) => $pool->get('http://127.0.0.1:8000/sleep'), 
    range(1,10));   
})
@sy-records
Copy link
Contributor

You need to set the size of the table to be a bit larger, which can be changed in the config.

octane/config/octane.php

Lines 165 to 170 in f4907e7

'tables' => [
'example:1000' => [
'name' => 'string:1000',
'votes' => 'int',
],
],

@Alistair-zhong
Copy link
Author

Alistair-zhong commented Feb 25, 2023

@sy-records thanks for your reply.

You need to set the size of the table to be a bit larger, which can be changed in the config.

I don't use any octane table or swoole table, but still encounter the error.
I found that Laravel/Octane uses a table to record the execution time of workers at the underlying level. If I change the max_execution_time in config/octane.php to 0, or change 250 to 1000 in the vendor/laravel/octane/bin/createSwooleTimerTable.php file, the problem stops occurring. Therefore, I think the issue is with the table used by Octane at the underlying level to track and record the execution time.

@sy-records
Copy link
Contributor

Can you provide a complete error stack?

@Alistair-zhong
Copy link
Author

Can you provide a complete error stack?

Sure.

PHP Fatal error:  Uncaught ErrorException: Swoole\Table::set(): failed to set('165'), unable to allocate memory in /var/www/vendor/laravel/octane/src/Tables/SwooleTable.php:88
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()
#1 /var/www/vendor/laravel/octane/src/Tables/SwooleTable.php(88): Swoole\Table->set()
#2 /var/www/vendor/laravel/octane/bin/swoole-server(110): Laravel\Octane\Tables\SwooleTable->set()
#3 [internal function]: {closure}()
#4 /var/www/vendor/laravel/octane/bin/swoole-server(164): Swoole\Server->start()
#5 {main}
  thrown in /var/www/vendor/laravel/octane/src/Tables/SwooleTable.php on line 88

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

Successfully merging a pull request may close this issue.

4 participants