Skip to content

Make the task termination order deterministic#2265

Merged
anshulpundir merged 1 commit into
moby:masterfrom
sungwonh:deterministic-scale-down
Dec 7, 2017
Merged

Make the task termination order deterministic#2265
anshulpundir merged 1 commit into
moby:masterfrom
sungwonh:deterministic-scale-down

Conversation

@sungwonh
Copy link
Copy Markdown
Contributor

This PR adds support for making the task termination order deterministic when scaling down.
Please refer to #2264 for more details. (closes #2264)

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 16, 2017

Codecov Report

Merging #2265 into master will decrease coverage by 0.41%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #2265      +/-   ##
==========================================
- Coverage   62.08%   61.66%   -0.42%     
==========================================
  Files          49      128      +79     
  Lines        6842    21080   +14238     
==========================================
+ Hits         4248    13000    +8752     
- Misses       2163     6682    +4519     
- Partials      431     1398     +967

// First sort tasks in an ascending order of slot number. This will
// make the task termination order deterministic.

sort.Sort(slotsBySlotNumber(slotsSlice))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

golang's Sort function is not a stable sort, so I don't think this accomplishes anything. The same slice is immediately re-sorted afterwards using slotsByRunningState. I think the right way to do this is to change slotsByRunningState so that slot number is used as a tie-breaker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback. According to your feedback, this PR is updated to use slot number as a tie-breaker in slotByRunningState.

@sungwonh sungwonh force-pushed the deterministic-scale-down branch 2 times, most recently from 77391de to ad203db Compare June 19, 2017 02:10
Copy link
Copy Markdown
Collaborator

@aaronlehmann aaronlehmann left a comment

Choose a reason for hiding this comment

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

This looks much better, thanks. I've added some comments. Also, can you please add a unit test for this comparator, now that it is becoming a little more complicated?

Comment thread manager/orchestrator/replicated/slot.go Outdated
// Use Slot number as a tie-breaker. This will make the order
// of task termination deterministic when scaling down.
iSlot := is[i]
jSlot := is[j]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We use is[i] and is[j] above, so it seems strange to assign shorthands to them here. For consistency, we should either define these at the beginning of the function, or use is[i] and is[j] directly. My preference would be the latter, since is[i] and is[j] are short and assigning them to a variable does not make the code clearer.

Comment thread manager/orchestrator/replicated/slot.go Outdated
// of task termination deterministic when scaling down.
iSlot := is[i]
jSlot := is[j]
if (iRunning && jRunning) || (!iRunning && !jRunning) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

As a small cosmetic tweak, could you move this check above as:

if !iRunning && jRunning {
        return false
}

This feels a little more symmetric with the if iRunning && !jRunning check.

Then as the tie-breaker, we can have return is[i][0].Slot < is[j][0].Slot.

@sungwonh sungwonh force-pushed the deterministic-scale-down branch from ad203db to 986a1aa Compare June 20, 2017 00:29
@sungwonh
Copy link
Copy Markdown
Contributor Author

@aaronlehmann Thank you for your feedback. PR is updated!

@aaronlehmann
Copy link
Copy Markdown
Collaborator

LGTM

Thank you for making the changes!

@sebastianbinder
Copy link
Copy Markdown

What's the current state of this PR? Would love to see this feature implemented.

@sungwonh
Copy link
Copy Markdown
Contributor Author

sungwonh commented Dec 1, 2017

@nishanttotla
Who else do I need approval from / what is the process left to get this PR merged?

@sebastianbinder
Copy link
Copy Markdown

@sungwonh I think first of all you need to rebase as there are conflicting files.

@sungwonh sungwonh force-pushed the deterministic-scale-down branch 5 times, most recently from e70aeee to 0237a28 Compare December 1, 2017 12:29
@sungwonh
Copy link
Copy Markdown
Contributor Author

sungwonh commented Dec 1, 2017

Rebased!

Copy link
Copy Markdown
Contributor

@anshulpundir anshulpundir left a comment

Choose a reason for hiding this comment

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

Minor comments. I'll merge the change once they are addressed @sungwonh

Comment thread manager/orchestrator/replicated/slot.go Outdated
return false
}

// Use Slot number as a tie-breaker. This will make the order
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please add a comment on why doing this in increasing slot ids is better.

}

return iRunning && !jRunning
if iRunning && !jRunning {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can I also request you to add a high level comment for the Less() function ? thx!

@sungwonh sungwonh force-pushed the deterministic-scale-down branch from 0237a28 to 1aecc00 Compare December 5, 2017 06:07
Use Slot number as a tie-breaker

Signed-off-by: Sungwon Han <sungwon.han@navercorp.com>
@sungwonh sungwonh force-pushed the deterministic-scale-down branch from 1aecc00 to dfee0c4 Compare December 5, 2017 06:12
@sungwonh
Copy link
Copy Markdown
Contributor Author

sungwonh commented Dec 5, 2017

@anshulpundir updated according to your comments.

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.

Deterministic task termination order when scaling down

5 participants