# Websocket scaling configuration issues

**URL:** <https://community.fly.io/t/websocket-scaling-configuration-issues/22748>\
**Category:** Django\
**Tags:** metrics, machines, streams, autoscaling, login-only\
**Created:** [November 21, 2024, 10:31pm UTC](https://community.fly.io/t/websocket-scaling-configuration-issues/22748 "2024-11-21T22:31:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![giulianopenido](https://avatars.discourse-cdn.com/v4/letter/g/b5e925/32.png) [@giulianopenido](https://community.fly.io/u/giulianopenido)\
**Post date:** [November 21, 2024, 10:31pm UTC](https://community.fly.io/t/websocket-scaling-configuration-issues/22748/1 "2024-11-21T22:31:39Z")

</div>

Hi everyone,

I’m having some issues with my Django Channels WebSocket application scaling configuration. I’ve set up connection-based scaling with a softlimit of 20 and hardlimit of 25 connections. However, the limits don’t seem to be working as expected, and I’m noticing some strange behavior.

The main issues I’m experiencing are:

1. Connections are being dropped from one machine and redirected to another periodically, even when the limits haven’t been reached
2. One of the machines appears to shut down unexpectedly
3. The soft and hard limits don’t seem to be enforced properly

Look at some metrics from grafana:

 ![image](https://global.discourse-cdn.com/fly1/original/3X/c/f/cfc8046d252a58333b88fc0236088fbb004a3e2f.png)

Here is my fly.toml file:

```auto
primary_region = 'gru'
console_command = 'python manage.py shell'

[build]
  dockerfile = "./infra/Dockerfile"

[deploy]
  strategy = "bluegreen"

[[services]]
  internal_port = 8000
  protocol = "tcp"
  auto_stop_machines = "stop"
  auto_start_machines = true
  min_machines_running = 0

  [services.concurrency]
    type = "connections"
    hard_limit = 25
    soft_limit = 20

  [[services.ports]]
    handlers = ["http"]
    port = "80"

  [[services.ports]]
    handlers = ["tls", "http"]
    port = "443"

  [[services.tcp_checks]]
    interval = 10000
    timeout = 2000

[[vm]]
  memory = '2gb'
  cpu_kind = 'shared'
  cpus = 2

[[statics]]
  guest_path = '/src/output/staticfiles'
  url_prefix = '/static/'

```

I have another monitoring interface and it showed that at this time there was 60 connections with the websocket

 ![image](https://global.discourse-cdn.com/fly1/original/3X/c/f/cf3aa21131be38e13cff0e547d7d18d6e122782a.png)

---

<div class="post-metadata">

**Author:** ![dudz](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/dudz/32/38894_2.png) [@dudz](https://community.fly.io/u/dudz)\
**Post date:** [November 21, 2024, 11:26pm UTC](https://community.fly.io/t/websocket-scaling-configuration-issues/22748/4 "2024-11-21T23:26:19Z")

</div>

![chrome_2024-11-21_20-24-08](https://global.discourse-cdn.com/fly1/original/3X/9/e/9e69a5b7bf42edc91be33974eb53968c13ca964d.png)

 ![chrome_2024-11-21_20-25-05](https://global.discourse-cdn.com/fly1/original/3X/c/1/c1902b315ca29dc82fbefb06e650d1af40d0a0e2.png)

Just adding more information on the case. For instance, there is 12-15 people using the websocket on the last minutes and suddenly the “Concurrency” drops to 0. We know the machine is still running by looking on the other metrics and we also know that Websocket users are connected because we are monitoring via our own monitoring system, so what is going on?

---

<div class="post-metadata">

**Author:** ![dudz](https://sea1.discourse-cdn.com/fly1/user_avatar/community.fly.io/dudz/32/38894_2.png) [@dudz](https://community.fly.io/u/dudz)\
**Post date:** [November 25, 2024, 5:29pm UTC](https://community.fly.io/t/websocket-scaling-configuration-issues/22748/5 "2024-11-25T17:29:50Z")

</div>

This looks like an issue on Flys end. I don’t whether its on the metrics side or on the auto balancing part, but definetely on the infrastructure management part.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/fly1/original/3X/6/e/6e8955d00cb218e186ebbe3a6ab06fefdce15290.svg) [@system](https://community.fly.io/u/system)\
**Post date:** [December 2, 2024, 5:30pm UTC](https://community.fly.io/t/websocket-scaling-configuration-issues/22748/6 "2024-12-02T17:30:37Z")

</div>

Closed on December 2, 2024, 5:30pm UTC

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
