예제 #1
0
func TestEngine(t *testing.T) {
	rawInstructions := "(sleep 1) (start 2700 100) (sleep 700) (stop-all)"
	def, err := definition.BenchmarkDefByRawInstructions(rawInstructions, 3)
	engine, err2 := NewEngine(def, false)

	if err2 != nil {
		log.Fatalf("unable to create the new engine: %v", err)
	}

	if engine.InstanceGroupSize() != 3 {
		log.Fatalf("wrong instance group size expected '3' got: %s", engine.InstanceGroupSize())
	}
}
예제 #2
0
파일: run.go 프로젝트: giantswarm/nomi
func runRun(cmd *cobra.Command, args []string) {
	runFlags.Validate()
	fleetPool := fleet.NewFleetPool(20)

	if runFlags.listenAddr == "" {
		// We extract the public CoreOS ip of the host machine
		ip, err := fleet.CoreosHostPublicIP()
		if ip == "" || err != nil {
			runFlags.listenAddr = listenerDefaultIP + ":" + listenerDefaultPort
		} else {
			runFlags.listenAddr = ip + ":" + listenerDefaultPort
		}
	}

	existingUnits, err := fleetPool.ListUnits()
	if err != nil {
		log.Logger().Fatal(err)
	}

	var benchmark definition.BenchmarkDef
	if runFlags.benchmarkFile == "" {
		benchmark, err = definition.BenchmarkDefByRawInstructions(runFlags.rawInstructions, runFlags.igSize)
		if err != nil {
			log.Logger().Fatal("unable to parse the introduced raw instructions")
		}
	} else {
		benchmark, err = definition.BenchmarkDefByFile(runFlags.benchmarkFile)
	}

	if err != nil {
		log.Logger().Fatal(err)
	}

	unitEngine, err := unit.NewEngine(benchmark, runFlags.verbose)
	if err != nil {
		log.Logger().Fatal(err)
	}

	builder, err := unit.NewBuilder(benchmark.Application, unitEngine.InstanceGroupSize(), runFlags.listenAddr)
	if err != nil {
		log.Logger().Fatal(err)
	}

	if benchmark.Application.Type == "unitfiles" {
		err = builder.UseCustomUnitFileService(benchmark.Application.UnitFilePath)
		if err != nil {
			log.Logger().Fatal("unable to parse unit file from your application definition")
		}
	}

	observer := unit.NewUnitObserver(unitEngine)
	observer.StartHTTPService(runFlags.listenAddr)

	fleetPool.StartUnit(builder.MakeStatsDumper("etcd", "echo `hostname` `docker run --rm --pid=host ragnarb/toolbox pidstat -h -r -u -C etcd 10 1 | tail -n 1 | awk \\'{print $7 \" \" $12}\\'`", "etcd"))
	fleetPool.StartUnit(builder.MakeStatsDumper("fleetd", "echo `hostname` `docker run --rm --pid=host ragnarb/toolbox pidstat -h -r -u -C fleetd 10 1 | tail -n 1 | awk \\'{print $7 \" \" $12}\\'`", "fleetd"))
	fleetPool.StartUnit(builder.MakeStatsDumper("systemd", "echo `hostname` `docker run --rm --pid=host ragnarb/toolbox pidstat -h -r -u -p 1 10 1 | tail -n 1 | awk \\'{print $7 \" \" $12}\\'`", "systemd"))

	unitEngine.SpawnFunc = func(id string) error {
		if runFlags.verbose {
			log.Logger().Infof("spawning unit with id %s\n", id)
		}
		return fleetPool.StartUnitGroup(builder.MakeUnitChain(id))
	}

	unitEngine.StopFunc = func(id string) error {
		if runFlags.verbose {
			log.Logger().Infof("stopping unit with id %s\n", id)
		}
		return fleetPool.Stop(builder.GetUnitPrefix() + "-0@" + id + ".service")
	}

	unitEngine.Run()

	existingUnits, err = fleetPool.ListUnits()
	if err != nil {
		log.Logger().Errorf("error listing units %v", err)
	}

	wg := new(sync.WaitGroup)
	for _, unit := range existingUnits {
		if strings.HasPrefix(unit.Name, builder.GetUnitPrefix()) {
			wg.Add(1)
			go func(unitName string) {
				if runFlags.verbose {
					log.Logger().Infof("destroying old unit: %s", unitName)
				}
				fleetPool.Destroy(unitName)
				wg.Done()
			}(unit.Name)
		}
	}
	wg.Wait()

	generateBenchmarkReport(runFlags.dumpJSONFlag, runFlags.dumpHTMLTarFlag, runFlags.generatePlots, unitEngine)
}