Пример #1
0
func (rw rw) Time(workload string, workloadCtx context.Context) (result IterationResult) {
	guid, _ := uuid.NewV4()
	redisMsg := redisMessage{
		Workload:        workload,
		Reply:           "replies-" + guid.String(),
		WorkloadContext: workloadCtx,
	}

	var jsonRedisMsg []byte
	var err error
	jsonRedisMsg, err = json.Marshal(redisMsg)

	if err != nil {
		return IterationResult{0, []StepResult{}, encodeError(err)}
	}

	rw.conn.Do("RPUSH", "tasks", string(jsonRedisMsg))

	reply, err := redis.Strings(rw.conn.Do("BLPOP", "replies-"+guid.String(), rw.timeoutInSeconds))

	if err != nil {
		return IterationResult{0, []StepResult{}, encodeError(err)}
	} else {
		json.Unmarshal([]byte(reply[1]), &result)
		return
	}
}
Пример #2
0
func (r *redisStore) LoadAll() ([]experiment.Experiment, error) {
	c := r.c
	members, err := redis.Strings(c.Do("LRANGE", "experiments", 0, MAX_RESULTS))
	if err != nil {
		return nil, err
	}

	experiments := make([]experiment.Experiment, len(members))
	for i := 0; i < len(members); i++ {
		experiments[i] = &redisExperiment{r, members[i]}
	}

	return experiments, nil
}
Пример #3
0
func (r redisExperiment) GetData() ([]*experiment.Sample, error) {
	members, err := redis.Strings(r.redisStore.c.Do("LRANGE", "experiment."+r.guid, 0, MAX_RESULTS))
	if err != nil {
		return nil, err
	}

	samples := make([]*experiment.Sample, len(members))
	for i := 0; i < len(samples); i++ {
		m := members[i]
		b := []byte(m)
		json.Unmarshal(b, &samples[i])
	}

	return samples, nil
}
Пример #4
0
func slaveLoop(conn redis.Conn, delegate Worker, handle string) {
	var redisMsg redisMessage

	logger := logs.NewLogger("redis.slave")
	logger.Info("Started slave")

	for {
		reply, err := redis.Strings(conn.Do("BLPOP", "stop-"+handle, "tasks", 0))

		if len(reply) == 0 {
			panic("Empty task, usually means connection lost, shutting down")
		}

		if reply[0] == "stop-"+handle {
			conn.Do("RPUSH", "stopped-"+handle, true)
			break
		}

		if err == nil {

			redisMsg.WorkloadContext = context.New()

			json.Unmarshal([]byte(reply[1]), &redisMsg)

			go func(experiment string, replyTo string, workloadCtx context.Context) {
				result := delegate.Time(experiment, workloadCtx)
				var encoded []byte
				encoded, err = json.Marshal(result)
				logger.Debug("Completed slave task, replying")
				conn.Do("RPUSH", replyTo, string(encoded))
			}(redisMsg.Workload, redisMsg.Reply, redisMsg.WorkloadContext)
		}

		if err != nil {
			logger.Warnf("ERROR: slave encountered error: %v", err)
		}
	}
}