Permalink
Browse files

Starting containers only if the least host exceeded half of the maxim…

…um limit
  • Loading branch information...
MohamedBassem committed Jul 30, 2015
1 parent 241b74f commit 165474e8c5aa96f50b923077c4973de0945746de
Showing with 20 additions and 14 deletions.
  1. +2 −0 config.yml
  2. +11 −10 context.go
  3. +6 −3 jobs.go
  4. +1 −1 scheduler.go
View
@@ -32,3 +32,5 @@ maxInstanceTime: 12
# Maximum number of instances per IP
maxInstancesPerIP: 6
# Maximum number of containers per Host
maxContainersPerHost: 40
View
@@ -17,16 +17,17 @@ import (
)
type configuration struct {
Database map[string]string `yaml:"database"`
Docker map[string]string `yaml:"docker"`
RedisAddress string `yaml:"redisAddress"`
RedisPassword string `yaml:"redisPassword"`
DigitalOceanToken string `yaml:"digitalOceanToken"`
DropletSSHKeyID int `yaml:"dropletSSHKeyID"`
MaxInstanceSize int `yaml:"maxInstanceSize"`
MaxInstanceTime int `yaml:"maxInstanceTime"`
MaxInstancesPerIP int `yaml:"maxInstancesPerIP"`
MaxRedisConnections int `yaml:"maxRedisConnections"`
Database map[string]string `yaml:"database"`
Docker map[string]string `yaml:"docker"`
RedisAddress string `yaml:"redisAddress"`
RedisPassword string `yaml:"redisPassword"`
DigitalOceanToken string `yaml:"digitalOceanToken"`
DropletSSHKeyID int `yaml:"dropletSSHKeyID"`
MaxInstanceSize int `yaml:"maxInstanceSize"`
MaxInstanceTime int `yaml:"maxInstanceTime"`
MaxInstancesPerIP int `yaml:"maxInstancesPerIP"`
MaxRedisConnections int `yaml:"maxRedisConnections"`
MaxContainersPerHost int `yaml:"maxContainersPerHost"`
}
type context struct {
View
@@ -21,21 +21,24 @@ func MonitorHosts(ctx *context) (startedHosts bool, deletedHosts []string, err e
hosts := ctx.ListHosts()
deletedHosts = make([]string, 0)
zeros := 0
mini := 1000000
for _, host := range hosts {
if host.NumberOfContainers == 0 {
zeros++
} else if host.NumberOfContainers < mini {
mini = host.NumberOfContainers
}
}
if zeros == 0 {
if zeros == 0 && mini > ctx.config.MaxContainersPerHost/2 {
err = ctx.NewHostFromImage()
if err != nil {
return
}
startedHosts = true
return
} else if zeros > 1 {
} else if zeros > 0 {
for _, host := range hosts {
if zeros == 1 {
if mini > ctx.config.MaxContainersPerHost/2 && zeros == 1 {
break
}
if host.NumberOfContainers == 0 {
View
@@ -5,7 +5,7 @@ import "errors"
// Returns the ip for the host which can hold this container
func (ctx *context) scheduleNewContainer() (publicIP, privateIP string, err error) {
hosts := ctx.ListHosts()
maximumNumberOfContainers := 40
maximumNumberOfContainers := ctx.config.MaxContainersPerHost
maximumNumber := -1
chosenHost := -1
for i, host := range hosts {

0 comments on commit 165474e

Please sign in to comment.