func SystemCapacity(rw http.ResponseWriter, r *http.Request) *httperr.Error { capacity, err := provider.CapacityGet() if err != nil { return httperr.Server(err) } return RenderJson(rw, capacity) }
// Update Process Parameters for Count and Memory // Expects -1 for count or memory to indicate no change, since count=0 is valid func SetFormation(app, process string, count, memory int64) error { a, err := GetApp(app) if err != nil { return err } rel, err := GetRelease(a.Name, a.Release) if err != nil { return err } m, err := LoadManifest(rel.Manifest, a) if err != nil { return err } me := m.Entry(process) if me == nil { return fmt.Errorf("no such process: %s", process) } capacity, err := provider.CapacityGet() if err != nil { return err } params := map[string]string{} // if not -1, set new parameter values if count >= 0 { params[fmt.Sprintf("%sDesiredCount", UpperName(process))] = fmt.Sprintf("%d", count) } if memory > 0 { if memory > capacity.InstanceMemory { return fmt.Errorf("requested memory %d greater than instance size %d", memory, capacity.InstanceMemory) } params[fmt.Sprintf("%sMemory", UpperName(process))] = fmt.Sprintf("%d", memory) } NotifySuccess("release:scale", map[string]string{ "app": rel.App, "id": rel.Id, }) return a.UpdateParams(params) }
func autoscaleRack() { log := logger.New("ns=workers.autoscale at=autoscaleRack") capacity, err := provider.CapacityGet() if err != nil { log.Log("fn=models.GetSystemCapacity err=%q", err) return } log.Log("autoscale=%t", autoscale) if !autoscale { return } system, err := provider.SystemGet() if err != nil { log.Log("fn=models.GetSystem err=%q", err) return } // calaculate instance requirements based on total process memory needed divided by the memory // on an individual instance instances := int(math.Ceil(float64(capacity.ProcessMemory) / float64(capacity.InstanceMemory))) // instance count cant be less than 2 if instances < 2 { instances = 2 } // instance count must be at least maxconcurrency+1 if instances < (int(capacity.ProcessWidth) + 1) { instances = int(capacity.ProcessWidth) + 1 } log.Log("process.memory=%d instance.memory=%d instances=%d change=%d", capacity.ProcessMemory, capacity.InstanceMemory, instances, (instances - system.Count)) // if no change then exit if system.Count == instances { return } system.Count = instances err = provider.SystemSave(*system) if err != nil { log.Log("fn=system.Save err=%q", err) return } }