Skip to content

Conversation

@jkasten2
Copy link
Member

@jkasten2 jkasten2 commented Apr 18, 2024

Description

One Line Summary

Further improve batching by restarting OperationRepo's delay on every enqueue call.

Details

Motivation

We want to prevent a misbehaving app stuck in a loop from continuously sending updates every opRepoExecutionInterval (5 seconds currently). We also want to save more network calls for legitimate use-cases as well. Both of which are accomplished in this PR

Scope

Only affects OperationRepo's batching delay.

History

This "wait for the dust to settle" delay strategy was used for player update in 4.x.x.

Testing

Unit testing

Manual testing

Tested on an Android 13 emulator. Ensured login, sendTags, and toggle permission all works. Also ensured quickly toggling optIn() / optOut() we don't make a network call until after 5 seconds of the last toggle.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@jkasten2 jkasten2 changed the title [WIP][Improvement] Further improve batching by restarting OperationRepo delay on every enqueue call [WIP][Improvement] Further improve batching by restarting OperationRepo's delay on every enqueue call Apr 18, 2024
@jkasten2 jkasten2 changed the title [WIP][Improvement] Further improve batching by restarting OperationRepo's delay on every enqueue call [Improvement] Further improve batching by restarting OperationRepo's delay on every enqueue call Apr 18, 2024
@jkasten2 jkasten2 force-pushed the improve/op_repo_restart_wait_on_every_enqueue branch from c21cf48 to 1a77f1b Compare April 19, 2024 21:12
@jkasten2 jkasten2 force-pushed the improve/handle_incorrect_404 branch from a8adb55 to 1c2bf82 Compare April 19, 2024 21:13
We want to prevent a misbehaving app stuck in a loop from continuously
sending updates every opRepoExecutionInterval (5 seconds currently).
By waiting for the dust to settle we ensure the app is done making
updates.
Every time something new is enqueued we will not restart waiting for
batches timer. The motivation is to prevent a misbehaving app from
continuously making network calls.
We are basically saying wait for the "the dust to settle" or
"the water is calm" to ensure the app is done making updates.

FUTURE: Highly recommend not removing this "the dust to settle" logic,
as it ensures any app stuck in a loop can't cause continuous network
requests. If the delay is too long for legitimate use-cases then allow
tweaking the opRepoExecutionInterval value or allow commitNow() with a
budget.
@jkasten2 jkasten2 force-pushed the improve/op_repo_restart_wait_on_every_enqueue branch from 1a77f1b to b6b60c6 Compare April 19, 2024 21:26
Copy link
Contributor

@jinliu9508 jinliu9508 left a comment

Choose a reason for hiding this comment

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

LGTM!

Great to have a new unit test for this improvement too!

Base automatically changed from improve/handle_incorrect_404 to main April 22, 2024 16:54
@jkasten2 jkasten2 merged commit 88b60a3 into main Apr 22, 2024
@jkasten2 jkasten2 deleted the improve/op_repo_restart_wait_on_every_enqueue branch April 22, 2024 16:55
@jkasten2 jkasten2 mentioned this pull request May 1, 2024
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.

3 participants