amphp / http-server

An advanced async HTTP server library for PHP, perfect for real-time apps and APIs with high concurrency demands.

Home Page:https://amphp.org/http-server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose number of active connections as a public API

rcjsuen opened this issue · comments

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?

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?

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?