Skip to content

Performance degradation over time #11

@progmancod

Description

@progmancod

Hi, first of all, congrats for your amazing project!

I noticed that every connection on the hub register a callback:

public function subscribe(callable $callback): void
{
    $this->init();
    $this->subscriber->on('message', function (string $channel, string $payload) use ($callback) {
        $callback($this->serializer->deserialize($payload));
    });
}

After the client close the connection, the callback remains there.

So, after few hours and hundreds of thousands of subscribes, the performance gets terrible, since every publish has to call hundreds of thousands functions, mostly unecessary (subscriber has long gone).

The solution is to listen connection e close events, register an array of subscribers (address => $callback()), and then remove them on connection close.

That's how the original implementation works: https://github.com/dunglas/mercure/blob/main/subscribe.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions