Search code examples
laravelswoole

Understanding Swoole Rows, Bytes Limits and Memory Allocation in Laravel Octane


I have a question regarding Laravel Octane's rows, bytes, and tables.

    'cache' => [
        'rows' => 1000,
        'bytes' => 10000,
    ],
  1. Why do we have to limit the number of rows and bytes in the Laravel Octane config file? Can't they be unlimited like other databases, such as MySQL?

  2. How does Swoole determine the byte limit? Is it calculated by strlen under the hood? How can we avoid the "unable to allocate memory" exception? Is this exception related to the byte limitation? Whenever this exception occurs, I have to restart my Docker container to prevent the error from happening again.

    'tables' => [
        'example:1000' => [
            'name' => 'string:1000',
            'votes' => 'int',
        ],
    ],
  1. Why do we need to define an additional Swoole table in the config file? What is the difference between using Cache::store('octane')->put() and the tables key in the config file? In the example provided in the config file (string:1000), what does :1000 mean?

Solution

    1. Because Table is built on top of shared memory, it cannot be dynamically scaled.
    2. Unable to allocate memory is because your data Key and Hash conflict rate is more than 20%, the reserved conflict memory block capacity is insufficient, set new data will report Unable to allocate memory error and return false, storage failure, then you need to increase the $size value and restart the service.

    The total memory occupied by Table is (HashTable structure length + KEY length 64 bytes + $size value) * (1 + $conflict_proportion value as hash conflict) * (column size).

    1. cache for Cache::store('octane'), if not then use OctaneArrayStore https://github.com/laravel/octane/blob/42b9030564b672a38a84dc319c210d25ee410ed6/src/OctaneServiceProvider.php#L151-L153

    tables for Octane::table('example').

    Hope I can help you.