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

Randomise reconnect timing #315

Merged
merged 4 commits into from
Sep 13, 2024
Merged

Randomise reconnect timing #315

merged 4 commits into from
Sep 13, 2024

Conversation

Steve-Mcl
Copy link
Contributor

closes #314

Description

To alleviate stresses on broker, a variation in the reconnect timing is introduced

The exact value may wish to be tweaked but I went with upto 2 seconds sooner and no more than 10s later than the original 15s fixed time

Related Issue(s)

#314

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass
  • Documentation has been updated
    • Upgrade instructions
    • Configuration details
    • Concepts
  • Changes flowforge.yml?
    • Issue/PR raised on FlowFuse/helm to update ConfigMap Template
    • Issue/PR raised on FlowFuse/CloudProject to update values for Staging/Production

Labels

  • Includes a DB migration? -> add the area:migration label

@knolleary
Copy link
Member

I think we should also include a similar randomised delay on startup. Perhaps not as extreme as 15secs, but between 2-10 secs for eg.

@Steve-Mcl
Copy link
Contributor Author

I think we should also include a similar randomised delay on startup. Perhaps not as extreme as 15secs, but between 2-10 secs for eg.

As the mqtt.connect call is synchronous and following events rely on their being a client object created, the straightforward solution to this is to add a random await before the call to agent.start

There is only 1 reference to the agent.start function (and it is already an async fn), so a simple awaited delay:

await new Promise(r => setTimeout(r, randomInt(20, 5000)));

before line 138:

this.mqttClient.start()

would be feasible.

@Steve-Mcl
Copy link
Contributor Author

a simple awaited delay:

await new Promise(r => setTimeout(r, randomInt(20, 5000)));

before line 138:

this.mqttClient.start()

would be feasible.

Added in commit add randomised start call delay

As this affects the start up time, I have kept is small enough to be less bothersome (20ms ~ 5s)

@knolleary
Copy link
Member

@Steve-Mcl looks good - but a failing lint check in the tests

@Steve-Mcl
Copy link
Contributor Author

@Steve-Mcl looks good - but a failing lint check in the tests

🤦‍♂️ Thats what I get for doing it in GH

fixed in 691eae7 🤞

@Steve-Mcl
Copy link
Contributor Author

and of course, tests now timeout

Timeout of 2000ms exceeded

fix incoming.

@knolleary knolleary merged commit e7e78d1 into main Sep 13, 2024
4 checks passed
@knolleary knolleary deleted the 314-reconnect-delay branch September 13, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Device Agent reconnect delay
2 participants