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

Limit inProgress using maxItems #11

Merged
merged 1 commit into from
Jul 16, 2018

Conversation

fathyb
Copy link
Contributor

@fathyb fathyb commented Jun 22, 2018

Blocked by #10


If the done callback is never called inProgress can grow infinitely when addItem is called. This PR checks that inProgress < maxItems before adding items to it.


Ref: https://segment.atlassian.net/browse/LIB-359
cc @f2prateek

@f2prateek f2prateek requested review from tsholmes and sperand-io June 22, 2018 05:41
@f2prateek
Copy link
Contributor

This looks good to me.

But what do you think about making it so that (inProgress + queue.Length < max). I think that maybe a better guarantee to provide.

while (queue.length && queue[0].time <= now) {
var inProgressSize = Object.keys(inProgress).length;

while (queue.length && queue[0].time <= now && inProgressSize++ < self.maxItems) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why the ++ in inProgressSize++?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh it's because the loop adds to the inProgress map - makes sense!

Copy link
Contributor Author

@fathyb fathyb Jun 22, 2018

Choose a reason for hiding this comment

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

Because we add an item to inProgress inside of the loop, so the length grows. It's a slightly faster version of Well, looks like I don't have real-time comments 😅

@fathyb
Copy link
Contributor Author

fathyb commented Jun 22, 2018

@f2prateek not really sure. To enforce it dynamically (based on the sum of the two queue sizes) you would need to drop new items, while the current behaviour is to drop the oldest item when maxItems is exceeded.

Using a fixed size for both makes queue behave as a back-pressure buffer for inProgress. Not sure if that makes sense so here is an example using each extremes (for maxItems=100):

  • fixed queue size: push item to queue, drop first queue item if queue > maxItems

    • queue=99,inProgress=100: item queued
    • queue=0,inProgress=100: item queued
    • queue=100,inProgress=100: oldest queue item dropped, new item queued
    • queue=100,inProgress=0: oldest queue item dropped, new item queued
  • dynamic queue size: if queue + inProgress < maxItems add item to queue

    • queue=49,inProgress=50: item queued
    • queue=0,inProgress=100: item ignored, we can't pop queue nor add an item
    • queue=50,inProgress=50: item ignored, you can workaround this on by poping queue
    • queue=100,inProgress=0: item queued

Copy link
Contributor

@f2prateek f2prateek left a comment

Choose a reason for hiding this comment

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

LGTM! Pending CI passes

@fathyb fathyb force-pushed the fix/limit-inprogress branch from ccfcd63 to b894ec4 Compare June 28, 2018 08:39
@codecov-io
Copy link

codecov-io commented Jun 28, 2018

Codecov Report

Merging #11 into master will decrease coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #11      +/-   ##
==========================================
- Coverage    94.4%   94.38%   -0.03%     
==========================================
  Files           4        4              
  Lines         268      267       -1     
==========================================
- Hits          253      252       -1     
  Misses         15       15
Impacted Files Coverage Δ
lib/index.js 95.27% <100%> (-0.04%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9eebb5e...78c309d. Read the comment docs.

@fathyb
Copy link
Contributor Author

fathyb commented Jun 28, 2018

#10 needs to be merged first to fix the tests

@fathyb fathyb force-pushed the fix/limit-inprogress branch from b894ec4 to fd1419d Compare July 4, 2018 07:27
@f2prateek
Copy link
Contributor

@fathyb could you rebase this now that #11 is released?

@fathyb fathyb force-pushed the fix/limit-inprogress branch from fd1419d to 78c309d Compare July 12, 2018 04:12
@fathyb
Copy link
Contributor Author

fathyb commented Jul 12, 2018

@f2prateek rebased, CI now passes 💯

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