Exemple #1
0
func handle_client(conn net.Conn, cc core.ClientConstructor) {
	reader := bufio.NewReader(conn)
	dec := json.NewDecoder(reader)
	enc := json.NewEncoder(conn)

	var p core.TestParameters
	if err := dec.Decode(&p); err != nil {
		log.Println(err)
		return
	}
	log.Println("Received test parameters from commander.")
	// log.Printf("Hitting %s at %f reqs/s by %d clients during %v.", p.Addr, p.Rate, p.Clients, p.Duration)

	globalResult, sync := core.SpawnWorkers(cc, p)

	sync.WaitReady() // ready.Wait();
	conn.Write([]byte("DONE\n"))
	log.Println("Sent DONE notification to commander.")
	line, err := reader.ReadString('\n')
	if err != nil || line != "GO\n" {
		log.Print("Did not receive GO command:", line, err, "\n")
		return
	}
	log.Println("Received go command from commander, starting loading")
	sync.Go() // start.Done()

	sync.WaitDone() //wg.Wait()

	summary := result.ResultSummary{p.Clients, globalResult.AverageThroughput(), globalResult.N_errors}
	enc.Encode(summary)
	result.PrintResult(*globalResult, p.Clients)

	if p.SaveSamples {
		result.SaveToFile(globalResult, generateHostDateFileName(p.SampleFile))
	}

	log.Printf("Send result: %v\n", summary)
	conn.Close()
	log.Println("Closed connection to master.\n")
}
Exemple #2
0
func main() {
	flag.Parse()
	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	rand.Seed(time.Now().Unix())
	// numprocs, numprocsdef := 0, 0

	hw_threads := runtime.NumCPU()
	// if *threads < hw_threads {
	//  hw_threads = *threads
	// }
	// numprocsdef =
	runtime.GOMAXPROCS(hw_threads)
	//  numprocsdef = runtime.GOMAXPROCS(4)
	numprocs := runtime.GOMAXPROCS(0)

	if *server {
		distr.StartServer(clientType)
		return
	}

	log.Printf("====================================================\n")
	hostname, _ := os.Hostname()
	log.Printf("Starting go load generator with %d HW threads at %s \n", numprocs, hostname)
	duration, err := time.ParseDuration(*p_duration)
	if err != nil {
		panic(err)
	}
	// log.Printf("Hitting %s at %d reqs/s by %d clients during %v.", *p_addr, *p_rate, *threads, duration)
	parameters := core.TestParameters{Addr: *p_addr, Rate: float64(*p_rate), Duration: duration, Clients: *threads, SaveSamples: (*dataOutput != ""), SampleFile: *dataOutput}

	var globalResult result.Result
	if *commander {
		serverfilecontents, err := ioutil.ReadFile(*serverfile)
		if err != nil {
			panic(err)
		}
		lines := strings.Split(string(serverfilecontents), "\n")
		var servers []string
		for _, line := range lines {
			if strings.TrimSpace(line) != "" {
				servers = append(servers, line)
			}
		}

		log.Printf("Using serverfile %s with contents (%d) %v\n", *serverfile, len(servers), servers)
		globalResult = distr.StartCommander(parameters, servers, clientType)

	} else {
		globalResult = core.StartTest(parameters, clientType)
		result.PrintResult(globalResult, *threads)
		if parameters.SaveSamples {
			result.SaveToFile(&globalResult, parameters.SampleFile)
		}

	}

	// if totalResponses > 0
	// log.Printf("TOTAL %d responses in %v, Rate: %v, avgLatency: %v\n", totalResponses, duration, float64(totalResponses)/duration.Seconds(), time.Duration(avgLatency))

}