Example #1
0
func (c *Client) handleAcked(req server.ReqID, r *bufio.Reader) (res Response,
	err error) {

	q, err := r.ReadString(' ')
	if err != nil {
		return
	}
	q = q[:len(q)-1]

	s, err := r.ReadString(' ')
	if err != nil {
		return
	}

	tid, err := strconv.Atoi(string(s[:len(s)-1]))
	if err != nil {
		return
	}

	res = Response{
		ID: req,
		Data: server.Task{
			Queue: server.Queue(q),
			ID:    server.TaskID(tid),
		},
	}
	return
}
Example #2
0
func genWorkload(workers, queues, tasks, size int, shared, enq bool) (
	workloads []workload) {

	b := make([]byte, size)
	for i := 0; i < size; i++ {
		b[i] = 'b'
	}

	q := 0
	for w := 0; w < workers; w++ {
		var wl workload
		if shared {
			q = 0
		}
		for t := 0; t < tasks; t++ {
			if shared {
				q = (q + t) % queues
			}
			task := server.Task{
				Queue: server.Queue(fmt.Sprintf("benchq-%v", q)),
				Body:  b,
			}
			wl.enqs = append(wl.enqs, task)
			if !enq {
				wl.deqs = append(wl.deqs, task.Queue)
			}
		}
		if !shared {
			q = (q + 1) % queues
		}
		workloads = append(workloads, wl)
	}

	return
}
Example #3
0
func (c *Client) handleDeQed(req server.ReqID, r *bufio.Reader) (res Response,
	err error) {

	q, err := r.ReadString(' ')
	if err != nil {
		return
	}
	q = q[:len(q)-1]

	s, err := r.ReadString(' ')
	if err != nil {
		return
	}

	tid, err := strconv.Atoi(string(s[:len(s)-1]))
	if err != nil {
		return
	}

	s, err = r.ReadString(' ')
	if err != nil {
		return
	}

	l, err := strconv.Atoi(string(s[:len(s)-1]))
	if err != nil {
		return
	}

	var d []byte
	d = make([]byte, l)
	n, err := io.ReadAtLeast(r, d, l)
	if err != nil {
		return
	}
	if n != l {
		err = ErrInvalidResponse
		return
	}

	b, err := r.ReadByte()
	if err != nil {
		return
	}
	if b != '\n' {
		err = ErrInvalidResponse
		return
	}

	res = Response{
		ID: req,
		Data: server.Task{
			Queue: server.Queue(q),
			ID:    server.TaskID(tid),
			Body:  d,
		},
	}
	return
}