Esempio n. 1
0
File: main.go Progetto: nkuacac/pat
func main() {
	useServer := false
	flags := config.ConfigAndFlags
	flags.BoolVar(&useServer, "server", false, "true to run the HTTP server interface")

	logs.InitCommandLineFlags(flags)
	cmdline.InitCommandLineFlags(flags)
	server.InitCommandLineFlags(flags)
	err := flags.Parse(os.Args[1:])
	if err != nil {
		fmt.Println(err)
		os.Exit(10)
	}

	if useServer == true {
		logs.NewLogger("main").Info("Starting in server mode")
		server.Serve()
	} else {
		err = cmdline.RunCommandLine()
		if err != nil {
			fmt.Println(err)
			os.Exit(20)
		}
	}
}
Esempio n. 2
0
File: server.go Progetto: Jonty/pat
func bind() {
	port := params.port

	logs.NewLogger("server").Infof("Starting web ui on http://localhost:%s", port)
	if err := ListenAndServe(":" + port); err != nil {
		panic(err)
	}
}
Esempio n. 3
0
File: redis.go Progetto: nkuacac/pat
func (slave slave) Close() error {
	_, err := slave.conn.Do("RPUSH", "stop-"+slave.guid, true)
	if err == nil {
		_, err = slave.conn.Do("BLPOP", "stopped-"+slave.guid, DefaultTimeout)
	}

	logs.NewLogger("redis.slave").Infof("Redis slave shutting down, %v", err)
	return err
}
Esempio n. 4
0
File: conn.go Progetto: nkuacac/pat
func test(conn *conn, err error) (Conn, error) {
	if err == nil {
		_, err = conn.Do("LRANGE", "test", 0, 0)
	}

	if err != nil {
		logs.NewLogger("redis.conn").Error("Redis connection failed")
	}
	return conn, err
}
Esempio n. 5
0
File: redis.go Progetto: nkuacac/pat
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)
		}
	}
}
Esempio n. 6
0
func (client rest) req(token string, method string, url string, contentType string, authUser string, authPassword string, data io.Reader, reply interface{}) Reply {
	req, err := http.NewRequest(method, url, data)
	if err != nil {
		return Reply{0, err.Error(), ""}
	}

	if authUser != "" {
		req.SetBasicAuth(authUser, authPassword)
	} else {
		req.Header.Set("Authorization", "bearer "+token)
	}

	if contentType != "" {
		req.Header.Set("Content-Type", contentType)
	}

	c := &http.Client{}
	resp, err := c.Do(req)
	if err != nil {
		return Reply{0, err.Error(), ""}
	}

	var logger = logs.NewLogger("workloads.rest")

	resp_body, _ := ioutil.ReadAll(resp.Body)

	if TRACE_REST_CALLS {
		body := make(map[string]interface{})
		json.Unmarshal(resp_body, &body)
		logger.Debug1f(">> %s", body)
	}

	json.Unmarshal(resp_body, &reply)
	logger.Debug1f("%s %s %s", method, url, resp.Status)
	return Reply{resp.StatusCode, resp.Status, resp.Header.Get("Location")}
}
Esempio n. 7
0
File: csv.go Progetto: nkuacac/pat
func (self *csvFile) Write(samples <-chan *experiment.Sample) {
	var logger = logs.NewLogger("store.csv")

	f, err := os.Create(self.outputPath)
	if err != nil {
		if os.IsNotExist(err) {
			logger.Infof("Creating directory, %s", filepath.Dir(self.outputPath))
			os.MkdirAll(filepath.Dir(self.outputPath), 0755)
			f, err = os.Create(self.outputPath)
		}

		if err != nil {
			logger.Errorf("Can't write CSV: %v", err)
		}
	}
	defer f.Close()

	var header []string
	var body []string
	w := csv.NewWriter(f)

	header = []string{"Average", "TotalTime", "SystemTime", "Total", "TotalErrors", "LastError", "TotalWorkers", "LastResult", "WorstResult", "NinetyfifthPercentile", "WallTime", "Type"}
	for _, k := range self.commands {
		header = append(header, "Commands|"+k+"|Count",
			"Commands|"+k+"|Throughput",
			"Commands|"+k+"|Average",
			"Commands|"+k+"|TotalTime",
			"Commands|"+k+"|LastTime",
			"Commands|"+k+"|WorstTime")
	}
	w.Write(header)

	for s := range samples {
		if s.Type == experiment.ResultSample {
			body = []string{strconv.Itoa(int(s.Average.Nanoseconds())),
				strconv.Itoa(int(s.TotalTime.Nanoseconds())),
				strconv.Itoa(int(s.Total)),
				s.SystemTime,
				strconv.Itoa(int(s.TotalErrors)),
				s.LastError,
				strconv.Itoa(int(s.TotalWorkers)),
				strconv.Itoa(int(s.LastResult.Nanoseconds())),
				strconv.Itoa(int(s.WorstResult.Nanoseconds())),
				strconv.Itoa(int(s.NinetyfifthPercentile.Nanoseconds())),
				strconv.Itoa(int(s.WallTime)),
				strconv.Itoa(int(s.Type))}

			for _, k := range self.commands {
				if s.Commands[k].Count == 0 {
					body = append(body, "", "", "", "", "", "")
				} else {
					body = append(body, strconv.Itoa(int(s.Commands[k].Count)),
						strconv.FormatFloat(s.Commands[k].Throughput, 'f', 8, 64),
						strconv.Itoa(int(s.Commands[k].Average.Nanoseconds())),
						strconv.Itoa(int(s.Commands[k].TotalTime.Nanoseconds())),
						strconv.Itoa(int(s.Commands[k].LastTime.Nanoseconds())),
						strconv.Itoa(int(s.Commands[k].WorstTime.Nanoseconds())))
				}
			}

			w.Write(body)
			w.Flush()
		}
	}
}
Esempio n. 8
0
File: conn.go Progetto: nkuacac/pat
func Connect(host string, port int, password string) (Conn, error) {
	logs.NewLogger("redis.conn").Debugf("Dialling redis on %s:%d", host, port)
	return test(&conn{redis.NewPool(func() (redis.Conn, error) { return connect(host, port, password) }, MAX_IDLE)}, nil)
}