laravel / octane

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

Failed to open stream: Too many open files in /vendor/composer/ClassLoader.php:478 #127

Closed jlibx closed 3 years ago

jlibx commented 3 years ago

Description:

wrk -c20 -d5s http://127.0.0.1:8000/api/companies

  200    GET /api/companies ......................................................................................................... 14.77 ms
  200    GET /api/companies ......................................................................................................... 10.31 ms
  200    GET /api/companies ......................................................................................................... 21.90 ms

   ERROR  PHP Fatal error:  Uncaught ErrorException: include(/Users/jonathan/Laravel/m-api/vendor/laravel/octane/src/Events/WorkerErrorOccurred.php): Failed to open stream: Too many open files in /Users/jonathan/Laravel/m-api/vendor/composer/ClassLoader.php:478

  ↑   72 similar errors were reported.

   ERROR  Stack trace:

  ↑   74 similar errors were reported.

   ERROR  #0 /Users/jonathan/Laravel/m-api/vendor/composer/ClassLoader.php(478): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'include(/Users/...', '/Users/jonathan...', 478)

  ↑   74 similar errors were reported.

log is

[2021-04-07 22:28:33 $5548.0]   WARNING check_worker_exit_status: worker#2[pid=6016] abnormal exit, status=0, signal=9
[2021-04-07 22:28:33 $5548.0]   WARNING check_worker_exit_status: worker#1[pid=6017] abnormal exit, status=0, signal=9
[2021-04-07 22:28:33 $5548.0]   WARNING check_worker_exit_status: worker#3[pid=6015] abnormal exit, status=0, signal=9
[2021-04-07 22:28:33 $5548.0]   WARNING check_worker_exit_status: worker#0[pid=6014] abnormal exit, status=0, signal=9

Steps To Reproduce:

albertcht commented 3 years ago

Hi @z-golly ,

I think it's related to number limit of file descriptors on your system kernel.

Try to run ulimit -n to see the number. You can run sudo ulimit -n 10240 to change the config temporarily to see if it works.

jlibx commented 3 years ago

@albertcht I have tried to set it, but the error still occurs

aftabnaveed commented 3 years ago

@z-golly may be give this a try

Increase the limit by editing /etc/sysctl.conf and add this line to the end of the file: fs.inotify.max_user_watches=524288

And then run sudo sysctl -p

jlibx commented 3 years ago

@taylorotwell @aftabnaveed @albertcht I didn't find this problem when I used it in the Windows Docker environment.

jlibx commented 3 years ago

When there is a database query, there is no performance improvement. This makes me feel very puzzled.

laravel version

code

    /**
     * @return JsonResponse
     */
    public function version()
    {
       return response()->json(['version' => app()->version()]);
    }

nginx+fpm

1617845426(1)

octane

1617845383(1)

query

code

      /**
     * @param Request $request
     * @param $id
     * @return JsonResponse
     */
    public function show(Request $request, $id)
    {
        $request->query->set(
            'with',
            'jds.addresses.province,jds.addresses.city,jds.educationName,typeName,scaleName,industries,province,city'
        );
        $company = (new Company())->filter($request->query())->findOrFail($id);

        return (new CompanyShowResource($company))->response();
    }

nginx+fpm

1617845556(1)

octane

1617845706(1)

aftabnaveed commented 3 years ago

Database queries won't by default start executing asynchronsuly you need to execute it through Octane::concurrently

use App\User;
use App\Server;
use Laravel\Octane\Facades\Octane;

[$users, $servers] = Octane::concurrently([
    fn () => User::all(),
    fn () => Server::all(),
]);
albertcht commented 3 years ago

All I/O operations in Laravel Octane now should still be blocking I/O. Octane::concurrently seems using SwooleTaskDispatcher by default. That means concurrently now can only help you decrease total waiting time of multiple I/O operations. These I/O operations still block Swoole's task workers. It won't help boost your qps significantly.

Unless coroutine feature is fully supported in Laravel, otherwise contexts between different coroutines may lead unexpected results.

aftabnaveed commented 3 years ago

@albertcht does that mean we won't be able to use go functions with octane ? I am thinking if Laravel does not provide it then why not use Swoole's utility functions directly?

Namoshek commented 3 years ago

Swoole::concurrently(...) uses go() (or actually the long version of it, see #100) under the hood. It allows you to execute multiple commands in parallel, but not in a fully asynchronous style we know from other languages like C#.

Whether Octane has an impact on request times depends on the tasks performed on the server. The more I/O is involved, the less noticeable it will be in the end. But for high traffic sites with content that can be cached easily, Octane is a great plus nonetheless.

What I'm not sure about is the Coroutine MySql Extension provided by Swoole. The documentation is lacking in my opinion, but maybe it can improve performance of queries further.

themsaid commented 3 years ago

Coroutines are currently disabled when using Octane. We're planning to work on adapting the framework and first party packages for it first.