laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.74k stars 291 forks source link

Fix Swoole in-memory table size #818

Closed miguilimzero closed 7 months ago

miguilimzero commented 7 months ago

Octane considers that the Swoole table size parameter is the number of rows it can store. But this is not true; calculating the number of rows a table can store is hard as it contains the table header, key size, and conflict proportion. Their wiki page does not explain exactly how it works: https://wiki.swoole.com/#/memory/table?id=__construct.

The current Octane implementation is not working as expected. By trying to insert 1000 rows in the example table provided, which sets 1000 as the table size, Swoole was only able to store 596 rows.

This PR adds a test to check if octane can use all available table rows and sets the table conflict proportion to 1 to ensure that the table has allocated memory to at least the defined row counts.

The conflict proportion default value for the original Swoole is 0.2. OpenSwoole uses 1 as a default according to their documentation (https://openswoole.com/docs/modules/swoole-table-construct). So this issue is only happening on the original swoole. I added 1 as the conflict parameter to both to ensure both implementations use the same value.