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

Use cache for minion lookups, don't hammer apiserver #1763

Merged
merged 1 commit into from
Oct 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/integration/integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ func startComponents(manifestURL string) (apiServerURL string) {

// Scheduler
schedulerConfigFactory := &factory.ConfigFactory{cl}
schedulerConfig, err := schedulerConfigFactory.Create()
if err != nil {
glog.Fatalf("Unable to construct scheduler config: %v", err)
}
schedulerConfig := schedulerConfigFactory.Create()
scheduler.New(schedulerConfig).Run()

endpoints := service.NewEndpointController(cl)
Expand Down
5 changes: 1 addition & 4 deletions plugin/cmd/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ func main() {
go http.ListenAndServe(net.JoinHostPort(address.String(), strconv.Itoa(*port)), nil)

configFactory := &factory.ConfigFactory{Client: kubeClient}
config, err := configFactory.Create()
if err != nil {
glog.Fatalf("Can't create scheduler config: %v", err)
}
config := configFactory.Create()
s := scheduler.New(config)
s.Run()

Expand Down
18 changes: 14 additions & 4 deletions plugin/pkg/scheduler/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
package factory

import (
"fmt"
"math/rand"
"sync"
"time"
Expand All @@ -42,7 +43,7 @@ type ConfigFactory struct {
}

// Create creates a scheduler and all support functions.
func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
func (factory *ConfigFactory) Create() *scheduler.Config {
// Watch and queue pods that need scheduling.
podQueue := cache.NewFIFO()
cache.NewReflector(factory.createUnassignedPodLW(), &api.Pod{}, podQueue).Run()
Expand All @@ -63,13 +64,14 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
}

r := rand.New(rand.NewSource(time.Now().UnixNano()))
minionLister := &storeToMinionLister{minionCache}

algo := algorithm.NewGenericScheduler(
[]algorithm.FitPredicate{
// Fit is defined based on the absence of port conflicts.
algorithm.PodFitsPorts,
// Fit is determined by resource availability
algorithm.NewResourceFitPredicate(algorithm.ClientNodeInfo{factory.Client}),
algorithm.NewResourceFitPredicate(minionLister),
},
// Prioritize nodes by least requested utilization.
algorithm.LeastRequestedPriority,
Expand All @@ -81,7 +83,7 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
}

return &scheduler.Config{
MinionLister: &storeToMinionLister{minionCache},
MinionLister: minionLister,
Algorithm: algo,
Binder: &binder{factory.Client},
NextPod: func() *api.Pod {
Expand All @@ -93,7 +95,7 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
return pod
},
Error: factory.makeDefaultErrorFunc(&podBackoff, podQueue),
}, nil
}
}

type listWatch struct {
Expand Down Expand Up @@ -204,6 +206,14 @@ func (s *storeToMinionLister) List() (machines api.MinionList, err error) {
return machines, nil
}

// GetNodeInfo returns cached data for the minion 'id'.
func (s *storeToMinionLister) GetNodeInfo(id string) (*api.Minion, error) {
if minion, ok := s.Get(id); ok {
return minion.(*api.Minion), nil
}
return nil, fmt.Errorf("minion '%v' is not in cache")
}

// storeToPodLister turns a store into a pod lister. The store must contain (only) pods.
type storeToPodLister struct {
cache.Store
Expand Down