Hello,
I'm building a simple chat application and I discovered that dispatch(new ChatMessage)->toOthers() (even without the toOthers part) slows my request by approximatively 160ms. I'm using the database driver for queues but the same problem occurs in production where I'm using redis.
My app is quite simple and my NewChatMessage only contains:
<?php
namespace App\Events;
use App\Models\ChatMessage;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;
class NewChatMessage implements ShouldBroadcastNow, ShouldBeUnique
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message;
public function __construct(ChatMessage $message)
{
$this->message = $message;
}
public function handle()
{
}
public function broadcastOn()
{
return new PresenceChannel('chat.'.$this->message->room_id);
}
}
I tried removing the data from the events (the $message instance) and nothing changed.
Broadcasting happens through pusher on development stage for dev and production paid plan for production.
Tried with and without caching events, no difference.
Any idea on this? Anyone encountered this problem?
Edit: BroadcastNow uses sync, whenever I remove the Now part, the request is faster, but my server configuration/project can't handle so much jobs in the queue (everything gets delayed easily).
King regards.