Use cache for minion lookups, don't hammer apiserver

This commit is contained in:
Daniel Smith 2014-10-13 14:46:31 -07:00
parent 13acb63fb3
commit 0431f2430d
3 changed files with 16 additions and 12 deletions

View File

@ -137,10 +137,7 @@ func startComponents(manifestURL string) (apiServerURL string) {
// Scheduler // Scheduler
schedulerConfigFactory := &factory.ConfigFactory{cl} schedulerConfigFactory := &factory.ConfigFactory{cl}
schedulerConfig, err := schedulerConfigFactory.Create() schedulerConfig := schedulerConfigFactory.Create()
if err != nil {
glog.Fatalf("Unable to construct scheduler config: %v", err)
}
scheduler.New(schedulerConfig).Run() scheduler.New(schedulerConfig).Run()
endpoints := service.NewEndpointController(cl) endpoints := service.NewEndpointController(cl)

View File

@ -58,10 +58,7 @@ func main() {
go http.ListenAndServe(net.JoinHostPort(address.String(), strconv.Itoa(*port)), nil) go http.ListenAndServe(net.JoinHostPort(address.String(), strconv.Itoa(*port)), nil)
configFactory := &factory.ConfigFactory{Client: kubeClient} configFactory := &factory.ConfigFactory{Client: kubeClient}
config, err := configFactory.Create() config := configFactory.Create()
if err != nil {
glog.Fatalf("Can't create scheduler config: %v", err)
}
s := scheduler.New(config) s := scheduler.New(config)
s.Run() s.Run()

View File

@ -19,6 +19,7 @@ limitations under the License.
package factory package factory
import ( import (
"fmt"
"math/rand" "math/rand"
"sync" "sync"
"time" "time"
@ -42,7 +43,7 @@ type ConfigFactory struct {
} }
// Create creates a scheduler and all support functions. // 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. // Watch and queue pods that need scheduling.
podQueue := cache.NewFIFO() podQueue := cache.NewFIFO()
cache.NewReflector(factory.createUnassignedPodLW(), &api.Pod{}, podQueue).Run() cache.NewReflector(factory.createUnassignedPodLW(), &api.Pod{}, podQueue).Run()
@ -63,13 +64,14 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
} }
r := rand.New(rand.NewSource(time.Now().UnixNano())) r := rand.New(rand.NewSource(time.Now().UnixNano()))
minionLister := &storeToMinionLister{minionCache}
algo := algorithm.NewGenericScheduler( algo := algorithm.NewGenericScheduler(
[]algorithm.FitPredicate{ []algorithm.FitPredicate{
// Fit is defined based on the absence of port conflicts. // Fit is defined based on the absence of port conflicts.
algorithm.PodFitsPorts, algorithm.PodFitsPorts,
// Fit is determined by resource availability // Fit is determined by resource availability
algorithm.NewResourceFitPredicate(algorithm.ClientNodeInfo{factory.Client}), algorithm.NewResourceFitPredicate(minionLister),
}, },
// Prioritize nodes by least requested utilization. // Prioritize nodes by least requested utilization.
algorithm.LeastRequestedPriority, algorithm.LeastRequestedPriority,
@ -81,7 +83,7 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
} }
return &scheduler.Config{ return &scheduler.Config{
MinionLister: &storeToMinionLister{minionCache}, MinionLister: minionLister,
Algorithm: algo, Algorithm: algo,
Binder: &binder{factory.Client}, Binder: &binder{factory.Client},
NextPod: func() *api.Pod { NextPod: func() *api.Pod {
@ -93,7 +95,7 @@ func (factory *ConfigFactory) Create() (*scheduler.Config, error) {
return pod return pod
}, },
Error: factory.makeDefaultErrorFunc(&podBackoff, podQueue), Error: factory.makeDefaultErrorFunc(&podBackoff, podQueue),
}, nil }
} }
type listWatch struct { type listWatch struct {
@ -204,6 +206,14 @@ func (s *storeToMinionLister) List() (machines api.MinionList, err error) {
return machines, nil 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. // storeToPodLister turns a store into a pod lister. The store must contain (only) pods.
type storeToPodLister struct { type storeToPodLister struct {
cache.Store cache.Store