Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
43c2bd72
Commit
43c2bd72
authored
Aug 14, 2015
by
dinghaiyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use resource request instead of resource limit to deal with resource
requirement in priority functions.
parent
2f0ace20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
42 deletions
+43
-42
priorities.go
plugin/pkg/scheduler/algorithm/priorities/priorities.go
+17
-16
priorities_test.go
plugin/pkg/scheduler/algorithm/priorities/priorities_test.go
+26
-26
No files found.
plugin/pkg/scheduler/algorithm/priorities/priorities.go
View file @
43c2bd72
...
@@ -43,29 +43,30 @@ func calculateScore(requested int64, capacity int64, node string) int {
...
@@ -43,29 +43,30 @@ func calculateScore(requested int64, capacity int64, node string) int {
// For each of these resources, a pod that doesn't request the resource explicitly
// For each of these resources, a pod that doesn't request the resource explicitly
// will be treated as having requested the amount indicated below, for the purpose
// will be treated as having requested the amount indicated below, for the purpose
// of computing priority only. This ensures that when scheduling zero-
limi
t pods, such
// of computing priority only. This ensures that when scheduling zero-
reques
t pods, such
// pods will not all be scheduled to the machine with the smallest in-use
limi
t,
// pods will not all be scheduled to the machine with the smallest in-use
reques
t,
// and that when scheduling regular pods, such pods will not see zero-
limi
t pods as
// and that when scheduling regular pods, such pods will not see zero-
reques
t pods as
// consuming no resources whatsoever. We chose these values to be similar to the
// consuming no resources whatsoever. We chose these values to be similar to the
// resources that we give to cluster addon pods (#10653). But they are pretty arbitrary.
// resources that we give to cluster addon pods (#10653). But they are pretty arbitrary.
const
defaultMilliCpuLimit
int64
=
100
// 0.1 core
// As described in #11713, we use request instead of limit to deal with resource requirements.
const
defaultMemoryLimit
int64
=
200
*
1024
*
1024
// 200 MB
const
defaultMilliCpuRequest
int64
=
100
// 0.1 core
const
defaultMemoryRequest
int64
=
200
*
1024
*
1024
// 200 MB
// TODO: Consider setting default as a fixed fraction of machine capacity (take "capacity api.ResourceList"
// TODO: Consider setting default as a fixed fraction of machine capacity (take "capacity api.ResourceList"
// as an additional argument here) rather than using constants
// as an additional argument here) rather than using constants
func
getNonzero
Limits
(
limi
ts
*
api
.
ResourceList
)
(
int64
,
int64
)
{
func
getNonzero
Requests
(
reques
ts
*
api
.
ResourceList
)
(
int64
,
int64
)
{
var
out_millicpu
,
out_memory
int64
var
out_millicpu
,
out_memory
int64
// Override if un-set, but not if explicitly set to zero
// Override if un-set, but not if explicitly set to zero
if
(
*
limi
ts
.
Cpu
()
==
resource
.
Quantity
{})
{
if
(
*
reques
ts
.
Cpu
()
==
resource
.
Quantity
{})
{
out_millicpu
=
defaultMilliCpu
Limi
t
out_millicpu
=
defaultMilliCpu
Reques
t
}
else
{
}
else
{
out_millicpu
=
limi
ts
.
Cpu
()
.
MilliValue
()
out_millicpu
=
reques
ts
.
Cpu
()
.
MilliValue
()
}
}
// Override if un-set, but not if explicitly set to zero
// Override if un-set, but not if explicitly set to zero
if
(
*
limi
ts
.
Memory
()
==
resource
.
Quantity
{})
{
if
(
*
reques
ts
.
Memory
()
==
resource
.
Quantity
{})
{
out_memory
=
defaultMemory
Limi
t
out_memory
=
defaultMemory
Reques
t
}
else
{
}
else
{
out_memory
=
limi
ts
.
Memory
()
.
Value
()
out_memory
=
reques
ts
.
Memory
()
.
Value
()
}
}
return
out_millicpu
,
out_memory
return
out_millicpu
,
out_memory
}
}
...
@@ -80,7 +81,7 @@ func calculateResourceOccupancy(pod *api.Pod, node api.Node, pods []*api.Pod) al
...
@@ -80,7 +81,7 @@ func calculateResourceOccupancy(pod *api.Pod, node api.Node, pods []*api.Pod) al
for
_
,
existingPod
:=
range
pods
{
for
_
,
existingPod
:=
range
pods
{
for
_
,
container
:=
range
existingPod
.
Spec
.
Containers
{
for
_
,
container
:=
range
existingPod
.
Spec
.
Containers
{
cpu
,
memory
:=
getNonzero
Limits
(
&
container
.
Resources
.
Limi
ts
)
cpu
,
memory
:=
getNonzero
Requests
(
&
container
.
Resources
.
Reques
ts
)
totalMilliCPU
+=
cpu
totalMilliCPU
+=
cpu
totalMemory
+=
memory
totalMemory
+=
memory
}
}
...
@@ -88,7 +89,7 @@ func calculateResourceOccupancy(pod *api.Pod, node api.Node, pods []*api.Pod) al
...
@@ -88,7 +89,7 @@ func calculateResourceOccupancy(pod *api.Pod, node api.Node, pods []*api.Pod) al
// Add the resources requested by the current pod being scheduled.
// Add the resources requested by the current pod being scheduled.
// This also helps differentiate between differently sized, but empty, minions.
// This also helps differentiate between differently sized, but empty, minions.
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
cpu
,
memory
:=
getNonzero
Limits
(
&
container
.
Resources
.
Limi
ts
)
cpu
,
memory
:=
getNonzero
Requests
(
&
container
.
Resources
.
Reques
ts
)
totalMilliCPU
+=
cpu
totalMilliCPU
+=
cpu
totalMemory
+=
memory
totalMemory
+=
memory
}
}
...
@@ -196,7 +197,7 @@ func calculateBalancedResourceAllocation(pod *api.Pod, node api.Node, pods []*ap
...
@@ -196,7 +197,7 @@ func calculateBalancedResourceAllocation(pod *api.Pod, node api.Node, pods []*ap
score
:=
int
(
0
)
score
:=
int
(
0
)
for
_
,
existingPod
:=
range
pods
{
for
_
,
existingPod
:=
range
pods
{
for
_
,
container
:=
range
existingPod
.
Spec
.
Containers
{
for
_
,
container
:=
range
existingPod
.
Spec
.
Containers
{
cpu
,
memory
:=
getNonzero
Limits
(
&
container
.
Resources
.
Limi
ts
)
cpu
,
memory
:=
getNonzero
Requests
(
&
container
.
Resources
.
Reques
ts
)
totalMilliCPU
+=
cpu
totalMilliCPU
+=
cpu
totalMemory
+=
memory
totalMemory
+=
memory
}
}
...
@@ -204,7 +205,7 @@ func calculateBalancedResourceAllocation(pod *api.Pod, node api.Node, pods []*ap
...
@@ -204,7 +205,7 @@ func calculateBalancedResourceAllocation(pod *api.Pod, node api.Node, pods []*ap
// Add the resources requested by the current pod being scheduled.
// Add the resources requested by the current pod being scheduled.
// This also helps differentiate between differently sized, but empty, minions.
// This also helps differentiate between differently sized, but empty, minions.
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
cpu
,
memory
:=
getNonzero
Limits
(
&
container
.
Resources
.
Limi
ts
)
cpu
,
memory
:=
getNonzero
Requests
(
&
container
.
Resources
.
Reques
ts
)
totalMilliCPU
+=
cpu
totalMilliCPU
+=
cpu
totalMemory
+=
memory
totalMemory
+=
memory
}
}
...
...
plugin/pkg/scheduler/algorithm/priorities/priorities_test.go
View file @
43c2bd72
...
@@ -40,7 +40,7 @@ func makeMinion(node string, milliCPU, memory int64) api.Node {
...
@@ -40,7 +40,7 @@ func makeMinion(node string, milliCPU, memory int64) api.Node {
}
}
}
}
func
TestZero
Limi
t
(
t
*
testing
.
T
)
{
func
TestZero
Reques
t
(
t
*
testing
.
T
)
{
// A pod with no resources. We expect spreading to count it as having the default resources.
// A pod with no resources. We expect spreading to count it as having the default resources.
noResources
:=
api
.
PodSpec
{
noResources
:=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
...
@@ -49,16 +49,16 @@ func TestZeroLimit(t *testing.T) {
...
@@ -49,16 +49,16 @@ func TestZeroLimit(t *testing.T) {
}
}
noResources1
:=
noResources
noResources1
:=
noResources
noResources1
.
NodeName
=
"machine1"
noResources1
.
NodeName
=
"machine1"
// A pod with the same resources as a 0-
limi
t pod gets by default as its resources (for spreading).
// A pod with the same resources as a 0-
reques
t pod gets by default as its resources (for spreading).
small
:=
api
.
PodSpec
{
small
:=
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"cpu"
:
resource
.
MustParse
(
strconv
.
FormatInt
(
defaultMilliCpu
Limi
t
,
10
)
+
"m"
),
strconv
.
FormatInt
(
defaultMilliCpu
Reques
t
,
10
)
+
"m"
),
"memory"
:
resource
.
MustParse
(
"memory"
:
resource
.
MustParse
(
strconv
.
FormatInt
(
defaultMemory
Limi
t
,
10
)),
strconv
.
FormatInt
(
defaultMemory
Reques
t
,
10
)),
},
},
},
},
},
},
...
@@ -71,11 +71,11 @@ func TestZeroLimit(t *testing.T) {
...
@@ -71,11 +71,11 @@ func TestZeroLimit(t *testing.T) {
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"cpu"
:
resource
.
MustParse
(
strconv
.
FormatInt
(
defaultMilliCpu
Limi
t
*
3
,
10
)
+
"m"
),
strconv
.
FormatInt
(
defaultMilliCpu
Reques
t
*
3
,
10
)
+
"m"
),
"memory"
:
resource
.
MustParse
(
"memory"
:
resource
.
MustParse
(
strconv
.
FormatInt
(
defaultMemory
Limi
t
*
3
,
10
)),
strconv
.
FormatInt
(
defaultMemory
Reques
t
*
3
,
10
)),
},
},
},
},
},
},
...
@@ -91,13 +91,13 @@ func TestZeroLimit(t *testing.T) {
...
@@ -91,13 +91,13 @@ func TestZeroLimit(t *testing.T) {
nodes
[]
api
.
Node
nodes
[]
api
.
Node
test
string
test
string
}{
}{
// The point of these next two tests is to show you get the same priority for a zero-
limi
t pod
// The point of these next two tests is to show you get the same priority for a zero-
reques
t pod
// as for a pod with the defaults
limits, both when the zero-limi
t pod is already on the machine
// as for a pod with the defaults
requests, both when the zero-reques
t pod is already on the machine
// and when the zero-
limi
t pod is the one being scheduled.
// and when the zero-
reques
t pod is the one being scheduled.
{
{
pod
:
&
api
.
Pod
{
Spec
:
noResources
},
pod
:
&
api
.
Pod
{
Spec
:
noResources
},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
1000
,
defaultMemory
Limit
*
10
),
makeMinion
(
"machine2"
,
1000
,
defaultMemoryLimi
t
*
10
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
1000
,
defaultMemory
Request
*
10
),
makeMinion
(
"machine2"
,
1000
,
defaultMemoryReques
t
*
10
)},
test
:
"test priority of zero-
limit pod with machine with zero-limi
t pod"
,
test
:
"test priority of zero-
request pod with machine with zero-reques
t pod"
,
pods
:
[]
*
api
.
Pod
{
pods
:
[]
*
api
.
Pod
{
{
Spec
:
large1
},
{
Spec
:
noResources1
},
{
Spec
:
large1
},
{
Spec
:
noResources1
},
{
Spec
:
large2
},
{
Spec
:
small2
},
{
Spec
:
large2
},
{
Spec
:
small2
},
...
@@ -105,8 +105,8 @@ func TestZeroLimit(t *testing.T) {
...
@@ -105,8 +105,8 @@ func TestZeroLimit(t *testing.T) {
},
},
{
{
pod
:
&
api
.
Pod
{
Spec
:
small
},
pod
:
&
api
.
Pod
{
Spec
:
small
},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
1000
,
defaultMemory
Limit
*
10
),
makeMinion
(
"machine2"
,
1000
,
defaultMemoryLimi
t
*
10
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
1000
,
defaultMemory
Request
*
10
),
makeMinion
(
"machine2"
,
1000
,
defaultMemoryReques
t
*
10
)},
test
:
"test priority of nonzero-
limit pod with machine with zero-limi
t pod"
,
test
:
"test priority of nonzero-
request pod with machine with zero-reques
t pod"
,
pods
:
[]
*
api
.
Pod
{
pods
:
[]
*
api
.
Pod
{
{
Spec
:
large1
},
{
Spec
:
noResources1
},
{
Spec
:
large1
},
{
Spec
:
noResources1
},
{
Spec
:
large2
},
{
Spec
:
small2
},
{
Spec
:
large2
},
{
Spec
:
small2
},
...
@@ -115,8 +115,8 @@ func TestZeroLimit(t *testing.T) {
...
@@ -115,8 +115,8 @@ func TestZeroLimit(t *testing.T) {
// The point of this test is to verify that we're not just getting the same score no matter what we schedule.
// The point of this test is to verify that we're not just getting the same score no matter what we schedule.
{
{
pod
:
&
api
.
Pod
{
Spec
:
large
},
pod
:
&
api
.
Pod
{
Spec
:
large
},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
1000
,
defaultMemory
Limit
*
10
),
makeMinion
(
"machine2"
,
1000
,
defaultMemoryLimi
t
*
10
)},
nodes
:
[]
api
.
Node
{
makeMinion
(
"machine1"
,
1000
,
defaultMemory
Request
*
10
),
makeMinion
(
"machine2"
,
1000
,
defaultMemoryReques
t
*
10
)},
test
:
"test priority of larger pod with machine with zero-
limi
t pod"
,
test
:
"test priority of larger pod with machine with zero-
reques
t pod"
,
pods
:
[]
*
api
.
Pod
{
pods
:
[]
*
api
.
Pod
{
{
Spec
:
large1
},
{
Spec
:
noResources1
},
{
Spec
:
large1
},
{
Spec
:
noResources1
},
{
Spec
:
large2
},
{
Spec
:
small2
},
{
Spec
:
large2
},
{
Spec
:
small2
},
...
@@ -138,7 +138,7 @@ func TestZeroLimit(t *testing.T) {
...
@@ -138,7 +138,7 @@ func TestZeroLimit(t *testing.T) {
t
.
Errorf
(
"unexpected error: %v"
,
err
)
t
.
Errorf
(
"unexpected error: %v"
,
err
)
}
}
for
_
,
hp
:=
range
list
{
for
_
,
hp
:=
range
list
{
if
test
.
test
==
"test priority of larger pod with machine with zero-
limi
t pod"
{
if
test
.
test
==
"test priority of larger pod with machine with zero-
reques
t pod"
{
if
hp
.
Score
==
expectedPriority
{
if
hp
.
Score
==
expectedPriority
{
t
.
Errorf
(
"%s: expected non-%d for all priorities, got list %#v"
,
test
.
test
,
expectedPriority
,
list
)
t
.
Errorf
(
"%s: expected non-%d for all priorities, got list %#v"
,
test
.
test
,
expectedPriority
,
list
)
}
}
...
@@ -174,7 +174,7 @@ func TestLeastRequested(t *testing.T) {
...
@@ -174,7 +174,7 @@ func TestLeastRequested(t *testing.T) {
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"memory"
:
resource
.
MustParse
(
"0"
),
"memory"
:
resource
.
MustParse
(
"0"
),
},
},
...
@@ -182,7 +182,7 @@ func TestLeastRequested(t *testing.T) {
...
@@ -182,7 +182,7 @@ func TestLeastRequested(t *testing.T) {
},
},
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"memory"
:
resource
.
MustParse
(
"0"
),
"memory"
:
resource
.
MustParse
(
"0"
),
},
},
...
@@ -197,7 +197,7 @@ func TestLeastRequested(t *testing.T) {
...
@@ -197,7 +197,7 @@ func TestLeastRequested(t *testing.T) {
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"memory"
:
resource
.
MustParse
(
"2000"
),
"memory"
:
resource
.
MustParse
(
"2000"
),
},
},
...
@@ -205,7 +205,7 @@ func TestLeastRequested(t *testing.T) {
...
@@ -205,7 +205,7 @@ func TestLeastRequested(t *testing.T) {
},
},
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"memory"
:
resource
.
MustParse
(
"3000"
),
"memory"
:
resource
.
MustParse
(
"3000"
),
},
},
...
@@ -506,7 +506,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
...
@@ -506,7 +506,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"memory"
:
resource
.
MustParse
(
"0"
),
"memory"
:
resource
.
MustParse
(
"0"
),
},
},
...
@@ -514,7 +514,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
...
@@ -514,7 +514,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
},
},
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"memory"
:
resource
.
MustParse
(
"0"
),
"memory"
:
resource
.
MustParse
(
"0"
),
},
},
...
@@ -529,7 +529,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
...
@@ -529,7 +529,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
Containers
:
[]
api
.
Container
{
Containers
:
[]
api
.
Container
{
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"cpu"
:
resource
.
MustParse
(
"1000m"
),
"memory"
:
resource
.
MustParse
(
"2000"
),
"memory"
:
resource
.
MustParse
(
"2000"
),
},
},
...
@@ -537,7 +537,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
...
@@ -537,7 +537,7 @@ func TestBalancedResourceAllocation(t *testing.T) {
},
},
{
{
Resources
:
api
.
ResourceRequirements
{
Resources
:
api
.
ResourceRequirements
{
Limi
ts
:
api
.
ResourceList
{
Reques
ts
:
api
.
ResourceList
{
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"cpu"
:
resource
.
MustParse
(
"2000m"
),
"memory"
:
resource
.
MustParse
(
"3000"
),
"memory"
:
resource
.
MustParse
(
"3000"
),
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment