Hi
André,
I have made a few changes, and tried to understand better what's happening.
I updated the version we're using to a build of 1.12.0 vernemq, compiled on erlang 23.3.4 alpine; same configuration as before, but with override to the new default :
- name: DOCKER_VERNEMQ_METADATA_PLUGIN
value: vmq_plumtree
(to preserve the setup as it was)
We still have 7 nodes in the cluster, with about 470k connections, and about 900k subscriptions.
We see the same memory usage pattern :
Checking the logs, I see (seriously) heavy metadata broadcast work :
08:09:46.169 [warning] Broadcast overloaded, 3322ms mailbox traversal, schedule next lazy broadcast in 75925ms, the min interval is 10000ms
08:12:19.678 [warning] Broadcast overloaded, 2688059ms mailbox traversal, schedule next lazy broadcast in 404911ms, the min interval is 10000ms
08:19:19.558 [warning] Broadcast overloaded, 2535665ms mailbox traversal, schedule next lazy broadcast in 399046ms, the min interval is 10000ms
08:26:33.382 [warning] Broadcast overloaded, 785ms mailbox traversal, schedule next lazy broadcast in 52949ms, the min interval is 10000ms
08:34:12.297 [warning] Broadcast overloaded, 2969ms mailbox traversal, schedule next lazy broadcast in 73823ms, the min interval is 10000ms
08:36:41.694 [warning] Broadcast overloaded, 4612748ms mailbox traversal, schedule next lazy broadcast in 463436ms, the min interval is 10000ms
08:44:39.201 [warning] Broadcast overloaded, 4754ms mailbox traversal, schedule next lazy broadcast in 83040ms, the min interval is 10000ms
08:46:22.659 [warning] Broadcast overloaded, 416ms mailbox traversal, schedule next lazy broadcast in 45189ms, the min interval is 10000ms
08:47:08.565 [warning] Broadcast overloaded, 724ms mailbox traversal, schedule next lazy broadcast in 51890ms, the min interval is 10000ms
etc..
I check the metrics/connections, and I see that for each cluster member, we had a fairly stable number of connections, but a huge turnover of queues/subscriptions :
This is the metric change in 30 minutes on vernemq with about 110k devices attached :
counter.queue_setup counter.queue_teardown
2 116 077
2 022 929
3 107 549
3 014 491
The connectivity from device -> broker is :
Device -> Firewall -> loadbalancer (ip # persistence) ->
k8s NodePorts (externalTrafficPolicy=Local) -> vernemq k8s pods
I noticed that some devices seemed to be constantly reconnecting :
bash-4.4$ vmq-admin session show --peer_host=18.17.16.15
+------------------+-----------+------------+-----------------+-----------+--------+
| client_id | is_online | mountpoint | peer_host | peer_port | user |
+------------------+-----------+------------+-----------------+-----------+--------+
| 1000B*********** | true | | 18.17.16.15 | 3216 | xxxxxx |
+------------------+-----------+------------+-----------------+-----------+--------+
bash-4.4$ vmq-admin session show --peer_host=18.17.16.15
+------------------+-----------+------------+-----------------+-----------+--------+
| client_id | is_online | mountpoint | peer_host | peer_port | user |
+------------------+-----------+------------+-----------------+-----------+--------+
| 1000B*********** | true | | 18.17.16.15 | 48484 | xxxxxx |
+------------------+-----------+------------+-----------------+-----------+--------+
A trace confirmed this :
2021-06-23T09:29:40Z Starting trace for 1 existing sessions for client "1000B**" with PIDs
[<9465.18698.1>]
2021-06-23T09:29:42Z New session with PID <9465.18715.1> found for client "1000B**"
2021-06-23T09:29:42Z <9465.18715.1> MQTT RECV: CID: "1000B**" CONNECT(c: 1000B**, v: 4, u: **, p: **, cs: 1, ka: 60)
2021-06-23T09:29:42Z <9465.18715.1> Calling auth_on_register(...)
2021-06-23T09:29:42Z <9465.18715.1> Hook returned "ok"
2021-06-23T09:29:42Z <9465.18698.1> Trace session for 1000B** stopped
2021-06-23T09:29:42Z <9465.18715.1> MQTT SEND: CID: "1000B**" CONNACK(sp: 0, rc: 0)
2021-06-23T09:29:43Z New session with PID <9465.18736.1> found for client "
1000B** "
2021-06-23T09:29:43Z <9465.18736.1> MQTT RECV: CID: "1000B**" CONNECT(c: 1000B**, v: 4, u: **, p: **, cs: 1, ka: 60)
2021-06-23T09:29:43Z <9465.18736.1> Calling auth_on_register(...)
2021-06-23T09:29:43Z <9465.18736.1> Hook returned "ok"
2021-06-23T09:29:43Z <9465.18715.1> Trace session for 1000B** stopped
2021-06-23T09:29:43Z <9465.18736.1> MQTT SEND: CID: "1000B**" CONNACK(sp: 0, rc: 0)
2021-06-23T09:29:44Z New session with PID <9465.18748.1> found for client "
1000B** "
2021-06-23T09:29:44Z <9465.18748.1> MQTT RECV: CID: "1000B**" CONNECT(c: 1000B**, v: 4, u: **, p: **, cs: 1, ka: 60)
2021-06-23T09:29:44Z <9465.18748.1> Calling auth_on_register(...)
2021-06-23T09:29:44Z <9465.18748.1> Hook returned "ok"
So, at a glance, it looks like the device has (clearly our problem!!) for some reason got at least two MQTT connections, with the same client ID.
- Connect requested / made <9465.18715.1> (in most cases, but not this one, subscriptions are also added)
- Then, Connect requested / made <
9465.18736.1> (in most cases, but not this one, subscriptions are also added)
- ...which disconnects <9465.18715.1> (as both old and new sessions are cs:1 clean_session, and we have allow_multiple_sessions = off set)
- and the device starts again with another connection attempt : <9465.18748.1>
From the point of view of vernemq, I assume that :
- the high queue/subscription turnover is overloading plumtree/metadata broadcast, and is probably causing our high CPU usage (tearing down and establishing new queues at a rate of 2 million per hour)
So my question is, is this also causing the really high memory usage? My guess was something like (although here I have no knowledge) :
- Each subscription/queue takes Erlang memory
- Erlang only releases 'blocks' when they are completely free of all queues/subscriptions
- Therefore, as we have a combination of 'stable long term' connections, and 'really fast churning' connections - we are causing allocation of loads of erlang memory blocks that cannot be released?
Does that sound like the issue?
Kind Regards,
Martin