amazon-web-servicesamazon-cloudwatchamazon-cloudwatch-metrics

Why is ActiveConnectionCount doubled in Amazon CloudWatch metrics when using WebSockets?


If we run a WebSocket load test with a max of 10K open connections we always get double the ActiveConnectionCount, the included image is a screenshot of a CloudWatch metric of the Application Load Balancer of our wss://endpoint. If we run a HTTP load test the ActiveConnectionCount is correct. Why is this?

Pseudo Load test code:

const WebSocket = require('ws');

for (let i = 0; i < 10000; i++) {
const client = new WebSocket('wss://endpoint');

client.on('open', () => {
  setInterval(() => {
    client.send('random message');
  }, 15000);
});

}

Screenshot of ActiveConnectionCount in Amazon CloudWatch Metrics:

ActiveConnectionCount Amazon CloudWatch


Solution

  • According to the AWS docs, ActiveConnectionCount is "The total number of concurrent TCP connections active from clients to the load balancer and from the load balancer to targets."

    So if you have 10 connections through a load balancer to a target, this metric should show 20 connections (10 from clients, and 10 to targets).