-
Notifications
You must be signed in to change notification settings - Fork 619
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
Added support for maximum replicas per node #2758
Conversation
9cf49b9
to
b1c85ca
Compare
b1c85ca
to
9563529
Compare
Codecov Report
@@ Coverage Diff @@
## master #2758 +/- ##
=========================================
Coverage ? 61.85%
=========================================
Files ? 134
Lines ? 21874
Branches ? 0
=========================================
Hits ? 13531
Misses ? 6884
Partials ? 1459 |
17745e1
to
d49d639
Compare
Ready for review. Note that I needed switch to Protoc 3.6.1 because it was failing to error:
Same way than example #2757 does |
d49d639
to
51f1d01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The feature looks fine to me.
The code mostly looks good, but has some small issues.
Here's a big question for you, though, that we'll need an answer to before we proceed: If the user is trying to do a rolling update, and they have the update set to Start First, but the maximum number of tasks is already present on every node, then the update will be unable to proceed. The user will have to first scale the service down, then do the rolling update. Is this expected and acceptable behavior?
api/types.proto
Outdated
@@ -862,6 +862,9 @@ message Placement { | |||
// This field is used in the platform filter for scheduling. If empty, | |||
// then the platform filter is off, meaning there are no scheduling restrictions. | |||
repeated Platform platforms = 3; | |||
|
|||
// Max replicas specifies limit for maximum number of replicas running on one node. | |||
uint64 maxreplicas = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: calling this max_replicas
should get it to compile to go as MaxReplicas
Additionally, the comment should then be of the form
// MaxReplicas specifies the limit . . .
manager/scheduler/filter.go
Outdated
|
||
// Check returns true if there is free slots for task in a given node. | ||
func (f *MaxReplicasFilter) Check(n *NodeInfo) bool { | ||
if uint64(n.ActiveTasksCountByService[f.t.ServiceID]) < f.t.Spec.Placement.Maxreplicas { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this concurrency safe? if so, can you explain why it's concurrency safe in a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far I understand swarmkit code then scheduler will process only one task at time?
and code logic on https://github.com/docker/swarmkit/blob/master/manager/scheduler/nodeinfo.go#L114 updates ActiveTasksCountByService counter immediately when task is scheduled to host without waiting that it actually starts. That should make it concurrency safe.
But to be honest I'm not sure how to describe it nicely.
manager/scheduler/scheduler_test.go
Outdated
|
||
assert.Len(t, t1Assignments, 2) | ||
assert.Equal(t, 2, t1Assignments["id1"]) | ||
assert.Equal(t, 2, t1Assignments["id2"]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add a check to the test to see that the Explain
step works correctly.
@dperny My first thought, this should be taken literally with a separate option to override. But I see the dilemma here in that allowing this (more than N-max on a node) to happen may be very bad in some cases, and having a separate option is cumbersome and confusing... and at what level is this option set at considering that you can potentially be updating more than one replica on a node in parallel. |
Good point. I think that correct logic would be that if start first setting is enabled then: I can try look about it. Btw. I also setup voting about it to original issue: moby/moby#26259 (comment) |
9d470c2
to
6673107
Compare
Actually more I think this more sure I came that it is excepted and acceptable behavior as it would very hard to define good logic when scheduler is allowed to exceed that limit. So I would say that it just need to be explained on documentation that user need to make sure that there is always room of update tasks on that combination. Simplest solution is actually have one more nodes than is needed to run application (example 3 nodes with settings @dperny I also made changes you requested. |
f3919d1
to
6bc6b12
Compare
@wk8 I can see that you have been reviewing many PRs here so can you take a look also this one? |
LGTM @anshulpundir and @wk8, can one of y'all sign off and merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpicks :)
manager/scheduler/filter.go
Outdated
// SetTask returns true when max replicas per node filter > 0 for a given task. | ||
func (f *MaxReplicasFilter) SetTask(t *api.Task) bool { | ||
if t.Spec.Placement != nil { | ||
if t.Spec.Placement.MaxReplicas > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the 2 ifs, just use &&
?
manager/scheduler/filter.go
Outdated
return true | ||
} | ||
|
||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe more readable as return uint64(n.ActiveTasksCountByService[f.t.ServiceID]) < f.t.Spec.Placement.MaxReplicas
?
f58495f
to
1c93a4b
Compare
Signed-off-by: Olli Janatuinen <[email protected]>
1c93a4b
to
6553bbe
Compare
@wk8 Changes which you requested are now in-place :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
- What I did
Added support for maximum replicas per node
First step to be able solve moby/moby#26259
- How I did it
Added maxreplicas settings under type Placement and --replicas-max-per-node to cli.
- How to test it
Create test service on one node environment using command: