laravel / reverb

Laravel Reverb provides a real-time WebSocket communication backend for Laravel applications.
https://reverb.laravel.com
MIT License
942 stars 63 forks source link

When activated for more than a day, it connects very slowly #201

Closed rawezhcode closed 1 month ago

rawezhcode commented 1 month ago

Reverb Version

1.0.0-beta10

Laravel Version

11

PHP Version

8.3

Description

When activated for more than a day, it connects very slowly as shown in the video, And be connected Redis server(https://www.digitalocean.com)

Steps To Reproduce

https://github.com/laravel/reverb/assets/53620168/8ef61170-9408-41e3-9dee-595670d35cb1

But when I restart it, the problem disappears

joedixon commented 1 month ago

@rawezhcode how much memory and CPU is in use when you notice the connections start to slow?

rawezhcode commented 1 month ago

SCR-20240520-muvz

CPU is less than 5% used, The slowdown only occurs when I enable REVERB_SCALING_ENABLED and connect it to Redis server(https://www.digitalocean.com)

joedixon commented 1 month ago

What is happening in your network tab when you reload the page?

rawezhcode commented 1 month ago

image

Just showing connections in the page.

and join the presence channel.

rawezhcode commented 1 month ago

` SESSION_DRIVER=database SESSION_LIFETIME=120 SESSION_ENCRYPT=false SESSION_PATH=/ SESSION_DOMAIN=null

BROADCAST_CONNECTION=reverb FILESYSTEM_DISK=local QUEUE_CONNECTION=redis

CACHE_STORE=redis CACHE_PREFIX=

`

`

'servers' => [

    'reverb' => [
        'host' => env('REVERB_SERVER_HOST', '0.0.0.0'),
        'port' => env('REVERB_SERVER_PORT', 8080),
        'hostname' => env('REVERB_HOST'),
        'options' => [
            'tls' => [],
        ],
        'max_request_size' => env('REVERB_MAX_REQUEST_SIZE', 10_000),
        'scaling' => [
            'enabled' => env('REVERB_SCALING_ENABLED', false),
            'channel' => env('REVERB_SCALING_CHANNEL', 'reverb'),
            'server' => [
                'url' => env('REDIS_URL'),
                'host' => env('REDIS_HOST', '127.0.0.1'),
                'port' => env('REDIS_PORT', '6379'),
                'username' => env('REDIS_USERNAME'),
                'password' => env('REDIS_PASSWORD'),
                'database' => env('REDIS_DB', '0'),
            ],
        ],
        'pulse_ingest_interval' => env('REVERB_PULSE_INGEST_INTERVAL', 15),
        'telescope_ingest_interval' => env('REVERB_TELESCOPE_INGEST_INTERVAL', 15),
    ],

],

/*
|--------------------------------------------------------------------------
| Reverb Applications
|--------------------------------------------------------------------------
|
| Here you may define how Reverb applications are managed. If you choose
| to use the "config" provider, you may define an array of apps which
| your server will support, including their connection credentials.
|
*/

'apps' => [

    'provider' => 'config',

    'apps' => [
        [
            'key' => env('REVERB_APP_KEY'),
            'secret' => env('REVERB_APP_SECRET'),
            'app_id' => env('REVERB_APP_ID'),
            'options' => [
                'host' => env('REVERB_HOST'),
                'port' => env('REVERB_PORT', 443),
                'scheme' => env('REVERB_SCHEME', 'https'),
                'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
            ],
            'allowed_origins' => ['*'],
            'ping_interval' => env('REVERB_APP_PING_INTERVAL', 60),
            'max_message_size' => env('REVERB_APP_MAX_MESSAGE_SIZE', 10_000),
        ],
    ],

],

`

rawezhcode commented 1 month ago

image

rawezhcode commented 1 month ago

my VPS Ubuntu 22.04 LTS Server 64-Bit CPU: 6 vCPU RAM: 16 GB Disk: 320 GB

And another thing I noticed when I use redis, it doesn't save any data and it's empty? So I don't know if that caused the problem.

image

joedixon commented 1 month ago

Hey @rawezhcode I wanted to see what was happening in the network tab to determine if it's definitely the connection to the WebSocket server which is delayed. It's likely there will be some more latency as there is a connection to an additional resource to handle, but it shouldn't make such a difference.

Also, if you are on a single server setup, there really isn't a need to use Redis - it's only for scenarios where you wish to horizontally scale across servers.

Finally, it's expected there are no keys in Redis as Reverb users the pubsub functionality of Redis and not the key/value storage.

rawezhcode commented 1 month ago

https://github.com/laravel/reverb/assets/53620168/3f7ab509-7301-435c-8490-d2497c06bd70

First: I have 3 VPS servers One for my database and app, one for Reverb, and one for Redis VPS 1: database and app (in Atlantic) / CPU: 6 vCPU, RAM: 16 GB VPS 2: Laravel Reverb (in Atlantic) / CPU: 6 vCPU, RAM: 16 GB VPS 3: Redis Server ( in Digital ocean ) / CPU: 4 vCPU, RAM: 8 GB

Note : And so I use Redis to avoid problems, (Because I have an app that more than 800 to 1500 participants join at night, at a certain time, and do question and answer games together). And last night, as a test I used Reverb that 701 participants joined And only 8% of the CPU is used without problems 😍🎉.

SCR-20240520-taun SCR-20240521-mpkr

*But the only problem is that I mentioned above that it is sometimes very slow.

And after a lot of testing, this slowdown is when you want to get the total number of connections. or send event (Broadcast) to participants. Otherwise, the WebSocket connection is seamless.

joedixon commented 1 month ago

You still don't need to use Redis if Reverb is only running on a single server. It's only useful if scaling connections across multiple servers running Reverb.

rawezhcode commented 1 month ago

I have no problem now, after I moved the redis server to another location as a test. Although I don't need to use redis with the same server, I wanted to try it as an experiment.

But I had another problem, after I removed the redis server. I wanted to increase the ( numprocs ) to 2 or more, but the problem occurred while I haven't had that problem with the socket.

[program:laravel-websocket] process_name=%(programname)s%(process_num)02d directory=/var/www/soketimanage_usr/data/www/soketimanager.soketimanager.xxxxx command=php artisan reverb:start autostart=true autorestart=true stopasgroup=true killasgroup=true user=soketimanage_usr numprocs=2 redirect_stderr=true stdout_logfile=/var/www/soketimanage_usr/data/www/soketimanager.xxxxx/soketi-supervisor.log stopwaitsecs=60 stopsignal=sigint minfds=10000

SCR-20240522-qprl

image

joedixon commented 1 month ago

It's not possible to run multipled processes on the same port.