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

Convert periodic dial update to asynchronous function #32

Open
SasaKaranovic opened this issue Mar 1, 2024 · 5 comments
Open

Convert periodic dial update to asynchronous function #32

SasaKaranovic opened this issue Mar 1, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@SasaKaranovic
Copy link
Owner

SasaKaranovic commented Mar 1, 2024

Currently dials values are being updated periodically inside PeriodicCallback function

pc = PeriodicCallback(self.dial_handler.periodic_dial_update, dial_update_period)

def periodic_dial_update(self):
updated = 0
ret=0
ret = self._periodic_update_dial_values()
updated = updated + ret
ret = self._periodic_update_dial_backlight()
updated = updated + ret
ret = self._periodic_update_dial_images()
updated = updated + ret
if updated <=0:
self._periodic_keep_alive()

This function is synchronous which could prevent/delay the server from handling new requests.
The server should not have to wait for the dial update to be completed in order to handle new request since all requests are buffered and then periodically sent to dials.

Related to #31

Copy link

github-actions bot commented May 6, 2024

This issue is stale because it has been open 15 days with no activity. Remove stale label or comment or this will be closed in 3 days.

@github-actions github-actions bot added the Stale label May 6, 2024
@PlasticGhoul
Copy link

PlasticGhoul commented May 8, 2024

@SasaKaranovic
I currently have a case which could correspond to this issue.
With Java I do 6 API calls nearly simultaneously (setting value, image and color on two dials).
The values are set, but color and image not.

To "unfreeze" the dials, I do one manual API call and then all dials are updating again.

Edit: Just re-looked at my code and saw that there are WAY more than 6 API calls. More like 20-ish.... But still, the Dials are freezing.

@SasaKaranovic
Copy link
Owner Author

@PlasticGhoul thanks for bringing this up.
I don't think these two are directly related although it might look like it.
The periodic update mentioned in this issue is different/separate from the HTTP request handler.

Regardless if you use this code with VU1 or some other service, I would highly recommend that you refactor your code for two reasons.
You should not make ~20 API calls "instantaneously" unless that is absolutely necessary for some reason (don't know your use-case but doubt that is the case).
For each request you make, server will provide a response. You should process that response to figure out if the request was accepted, rejected, invalid/malformed etc. Otherwise you risk getting your app and the server "out-of-sync".

@PlasticGhoul
Copy link

PlasticGhoul commented May 10, 2024

@SasaKaranovic
Yes, I did refactor the code now.
It is now kind of working.

I noticed one thing though.
I was processing the JSON that returns and even though I was blindly firing 20+ requests nearly at the same time, every request returned with HTTP 200 and the message that it was added to the queue.
That's why I thought that it was related to this issue

Edit: Just wanted to make it clear that 20+ calls at the same time weren't my intention. There was a bug that tripled each of my calls :D

@SasaKaranovic
Copy link
Owner Author

The VU server will accept as many requests as it can and updates the "internal" dial state.
But only every ~500ms (configurable) it will update the physical dials to match that state.

For posterity sake; This issue refers to the situation that occur where server is updating the dials and it receives another request at the exact same time. Because of this the request would still be processed but the server would have the delay (~ie 100ms) before it sends back the response. Changing the dial update to be asynchronous would potentially avoid this and make request-response timing more consistent.

@SasaKaranovic SasaKaranovic added the enhancement New feature or request label May 11, 2024
@github-actions github-actions bot removed the Stale label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants