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

Rate limiting for micro:bit using TaskQueue #2024

Merged
merged 19 commits into from
Mar 14, 2019
Merged

Rate limiting for micro:bit using TaskQueue #2024

merged 19 commits into from
Mar 14, 2019

Conversation

evhan55
Copy link
Contributor

@evhan55 evhan55 commented Mar 1, 2019

Resolves

Proposed Changes

Use the new TaskQueue utility to rate limit the hardware command sent over the Scratch Link socket to the microbit, to prevent trying to send too many commands at once and potentially lock up the peripheral or the browser, etc.

Test Coverage

Should test stacks that send many commands in a short period of time (e.g. broadcast > when I receive > forever display symbol)

* A task queue to track communication tasks sent over the socket.
* The bucket in this task queue holds 1 task at a time, and refills
* at a rate of 10 tasks per second, from a queue that holds at maximum
* 30 tasks. If more than 30 tasks are added to the task queue in a short
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"from a queue that holds tasks with a maximum total cost of 30. Since most tasks have a cost of 1 this means the queue will generally have at most 30 tasks."

@thisandagain thisandagain added this to the March 2019 milestone Mar 4, 2019
Copy link
Contributor

@ericrosenbaum ericrosenbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! tested it in a few different ways (forever broadcast triggering a display random, multiple parallel forever stacks, doing that simultaneous with reading sensor values) and everything behaves as expected.

The max total cost of 30 makes it so you can get into a situation where queued messages will send for three seconds, but that seems fine- it's a reasonable compromise, and definitely an edge case (only occurs if you use the broadcast trick to send messages very fast and stop the stack by clicking it rather than using the stop button).

@evhan55 evhan55 merged commit 94ca11f into scratchfoundation:develop Mar 14, 2019
@evhan55 evhan55 deleted the extensions/microbit-rate-limiting branch March 14, 2019 15:00
@evhan55 evhan55 restored the extensions/microbit-rate-limiting branch March 18, 2019 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants