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

Enhance the auto event execution #1627

Open
cloudxxx8 opened this issue Sep 20, 2024 · 3 comments
Open

Enhance the auto event execution #1627

cloudxxx8 opened this issue Sep 20, 2024 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@cloudxxx8
Copy link
Member

🚀 Feature Request

Relevant Package [REQUIRED]

This feature request is for device sdk

Description [REQUIRED]

The current issue is described here: https://github.com/orgs/edgexfoundry/discussions/310#discussion-7202203

Describe the solution you'd like

wrapping the execution (read + send event) as an asynchornous function

@cloudxxx8 cloudxxx8 added the enhancement New feature or request label Sep 20, 2024
@github-project-automation github-project-automation bot moved this to New Issues in Technical WG Sep 20, 2024
@cloudxxx8 cloudxxx8 added the help wanted Extra attention is needed label Sep 20, 2024
@edgexfoundry edgexfoundry deleted a comment from SAMBILI Sep 20, 2024
@cloudxxx8 cloudxxx8 assigned jinlinGuan and unassigned jinlinGuan Sep 24, 2024
@cloudxxx8
Copy link
Member Author

Discussed this issue in the Technical Working Group meeting on 24-Sep-2024, this issue will cause the original behavior change, so we won't implement it in v3 to prevent any breaking change.
@eaton-coreymutter please help provide your suggestion in this issue, thanks.

@cloudxxx8 cloudxxx8 moved this from New Issues to Icebox in Technical WG Sep 25, 2024
@eaton-coreymutter
Copy link
Member

Currently the autoevent executor loop is, in simplified pseudocode:

  • sleep for the autoevent duration
  • call the service's read function
  • send the resulting event, on a background thread

and if the "call the service's read function" takes noticeable time relative to the autoevent duration we get the skew described in the issue.

My suggestion:

  • deadline = now + autoevent-duration
  • call the service's read function
  • send the resulting event, on a background thread
  • if now < deadline, sleep for (deadline - now) duration

This way, if the service's read function is fast, this behaves like today. If the read function takes noticeable time, the autoevents will not skew, they will happen at the given interval. If the read function takes longer than the autoevent interval, events will come at the speed of the read function, slower than the autoevent interval but without "piling up" requests.

@syoliver
Copy link

syoliver commented Sep 25, 2024

@eaton-coreymutter

I think the proposal is interesting. However, in the first step of your suggestion

deadline = now + autoevent-duration

you take the time immediately after calling time.After. The time elapsed between the expected wake-up time of time.After and the result of Now() is not negligible. At the end of the day, as this time accumulates, the time lag can add up to minutes. It is worse when the device running the device service has few cores that are running many go routines/threads in many processes (maybe isolated in many docker containers).

As a result, I propose

deadline = deadline + autoevent-duration

On the other hand, in doing so, it is necessary to deal with cases where a read takes longer than the autoevent-duration. It can be explicitly discarded without informing anyone except writing a warning log. Or an event can be sent to keep track on the canceled reads somewhere.

And there's another subject that, although not quite the same, is closely related. Having one go routine per executor prevents reads from being synchronized with each other. Rather than grouping read commands, they are executed concurrently. And in some device services, they may interlock. It would be more efficient to synchronize the deadlines of each autoevent and group the reads as much as possible. This would give the device service more flexibility to optimize its requests, with less risk of interlocking and a better chance of responding within the autoevent-duration whatever it may be.
It can be achieved by removing the "one go routine by executor" behavior and synchronizing all auto events deadlines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Icebox
Development

No branches or pull requests

4 participants