Ejemplo n.º 1
0
func finalizeReq(reqDone network.Request) {
	if reqDone.To != "" {
		err := sendMessageToSpecificService(reqDone.ID, reqDone.To)
		if err != nil {
			log.Println("Cannot dispatch message to service", reqDone.To)
			return
		}
		addRequestToHistory(reqDone)
	} else {
		if len(destinations) > 0 {
			errCounter := sendMessageToDestinations(reqDone.ID)
			if errCounter < len(destinations) {
				// This is for requests to multiple destinations
				// because I have to wait till every destination
				// responde me before consider the request complete
				reqCounter := len(destinations) - errCounter
				reqDone.Counter = reqCounter
				addRequestToHistory(reqDone)
			}
			if errCounter > 0 {
				log.Println("Cannot dispatch message to all the destinations")
				if errCounter == len(destinations) {
					respondeToRequest(reqDone.From, reqDone.ID, "done")
				}
				return
			}
		} else {
			respondeToRequest(reqDone.From, reqDone.ID, "done")
		}
	}
}
Ejemplo n.º 2
0
func Work(workload string, req network.Request, ch_done chan network.Request) {
	var load float64

	switch workload {
	case "none":
		load = 0
	case "low":
		load = gen.ExpFloat64() * c_LOW
	case "medium":
		load = gen.ExpFloat64() * c_MEDIUM
	case "heavy":
		load = gen.ExpFloat64() * c_HEAVY
	default:
		log.Println("Undefined workload ", workload)
		return
	}

	timer := time.NewTimer(time.Millisecond * time.Duration(load))
	for {
		select {
		case <-timer.C:
			req.ExecTimeMs = computeExecutionTime(req.Start)
			ch_done <- req
			return
		default:
			cpuTest()
		}
	}
}