Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose number of active connections as a public API #349

Open
rcjsuen opened this issue Jun 21, 2023 · 2 comments
Open

Expose number of active connections as a public API #349

rcjsuen opened this issue Jun 21, 2023 · 2 comments
Labels

Comments

@rcjsuen
Copy link

rcjsuen commented Jun 21, 2023

if ($this->clientsPerIp[$bytes] >= $this->connectionsPerIpLimit) {
if (isset($bytes[4])) {
$ip .= "/56";
}
$this->logger->warning(
"Client denied: too many existing connections from {$ip}",
['local' => $socket->getLocalAddress()->toString(), 'remote' => $address->toString()],
);
return null;
}

We're using amphp to create a WebSocket server. We are intermittently seeing Client denied messages in our logs. We would like to expose the current number of active connections as a Prometheus gauge and then have Kubernetes evaluate that number to automatically scale up the number of pods so we can handle more connections.

Is this currently possible or would we first need a way to collect the number of active connections from ConnectionLimitingClientFactory first? Alternatively, can we implement this ourselves via some kind of counter++ and counter-- logic in some handler that guarantees our numbers will not get out of sync due to exceptions and miscellaneous networking errors?

@kelunik
Copy link
Member

kelunik commented Jul 8, 2023

Hey @rcjsuen, the code you linked is a limit per IP, not an overall limit for the server. If you reach the limits per IP, you probably don't want to scale up, but rather if you hit the overall limit of connections per server instance?

@rcjsuen
Copy link
Author

rcjsuen commented Aug 9, 2023

If you reach the limits per IP, you probably don't want to scale up, but rather if you hit the overall limit of connections per server instance?

And how should I determine that I've hit the overall limit assuming I just have this one WebSocket server?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants