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

improve auto-select memory for multinode clusters #7928

Merged
merged 5 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add unit tests
  • Loading branch information
sharifelgamal committed Apr 28, 2020
commit de5e493b1052ecdbf67b01ce8918b5310903ffce
4 changes: 2 additions & 2 deletions cmd/minikube/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func memoryLimits(drvName string) (int, int, error) {
}

// suggestMemoryAllocation calculates the default memory footprint in MB
func suggestMemoryAllocation(sysLimit int, containerLimit int) int {
func suggestMemoryAllocation(sysLimit int, containerLimit int, nodes int) int {
if mem := viper.GetInt(memory); mem != 0 {
return mem
}
Expand All @@ -737,7 +737,7 @@ func suggestMemoryAllocation(sysLimit int, containerLimit int) int {
// Suggest 25% of RAM, rounded to nearest 100MB. Hyper-V requires an even number!
suggested := int(float32(sysLimit)/400.0) * 100

if nodes := viper.GetInt(nodes); nodes > 1 {
if nodes > 1 {
suggested /= nodes
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/start_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func generateClusterConfig(cmd *cobra.Command, existing *config.ClusterConfig, k
glog.Warningf("Unable to query memory limits: %v", err)
}

mem := suggestMemoryAllocation(sysLimit, containerLimit)
mem := suggestMemoryAllocation(sysLimit, containerLimit, viper.GetInt(nodes))
if cmd.Flags().Changed(memory) {
mem, err = pkgutil.CalculateSizeInMB(viper.GetString(memory))
if err != nil {
Expand Down
37 changes: 23 additions & 14 deletions cmd/minikube/cmd/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,25 +185,34 @@ func TestSuggestMemoryAllocation(t *testing.T) {
description string
sysLimit int
containerLimit int
nodes int
want int
}{
{"128GB sys", 128000, 0, 6000},
{"64GB sys", 64000, 0, 6000},
{"16GB sys", 16384, 0, 4000},
{"odd sys", 14567, 0, 3600},
{"4GB sys", 4096, 0, 2200},
{"2GB sys", 2048, 0, 2048},
{"Unable to poll sys", 0, 0, 2200},
{"128GB sys, 16GB container", 128000, 16384, 16336},
{"64GB sys, 16GB container", 64000, 16384, 16000},
{"16GB sys, 4GB container", 16384, 4096, 4000},
{"4GB sys, 3.5GB container", 16384, 3500, 3452},
{"2GB sys, 2GB container", 16384, 2048, 2048},
{"2GB sys, unable to poll container", 16384, 0, 4000},
{"128GB sys", 128000, 0, 1, 6000},
{"64GB sys", 64000, 0, 1, 6000},
{"32GB sys", 32768, 0, 1, 6000},
{"16GB sys", 16384, 0, 1, 4000},
{"odd sys", 14567, 0, 1, 3600},
{"4GB sys", 4096, 0, 1, 2200},
{"2GB sys", 2048, 0, 1, 2048},
{"Unable to poll sys", 0, 0, 1, 2200},
{"128GB sys, 16GB container", 128000, 16384, 1, 16336},
{"64GB sys, 16GB container", 64000, 16384, 1, 16000},
{"16GB sys, 4GB container", 16384, 4096, 1, 4000},
{"4GB sys, 3.5GB container", 16384, 3500, 1, 3452},
{"16GB sys, 2GB container", 16384, 2048, 1, 2048},
{"16GB sys, unable to poll container", 16384, 0, 1, 4000},
{"128GB sys 2 nodes", 128000, 0, 2, 6000},
{"8GB sys 3 nodes", 8192, 0, 3, 2200},
{"16GB sys 2 nodes", 16384, 0, 2, 2200},
{"32GB sys 2 nodes", 32768, 0, 2, 4050},
{"odd sys 2 nodes", 14567, 0, 2, 2200},
{"4GB sys 2 nodes", 4096, 0, 2, 2200},
{"2GB sys 3 nodes", 2048, 0, 3, 2048},
}
for _, test := range tests {
t.Run(test.description, func(t *testing.T) {
got := suggestMemoryAllocation(test.sysLimit, test.containerLimit)
got := suggestMemoryAllocation(test.sysLimit, test.containerLimit, test.nodes)
if got != test.want {
t.Errorf("defaultMemorySize(sys=%d, container=%d) = %d, want: %d", test.sysLimit, test.containerLimit, got, test.want)
}
Expand Down