Esempio n. 1
0
func BenchmarkNewMessageRaw256(b *testing.B) {
	m := NewMessageByData(NewMessageData([]byte(utils.RandString(256))))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		NewMessage(m.underlay, false)
	}
}
Esempio n. 2
0
func BenchmarkNewMessageByData(b *testing.B) {
	source := NewMessageData([]byte(utils.RandString(256)))
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		NewMessageByData(source)
	}
}
Esempio n. 3
0
func BenchmarkTopicPut(b *testing.B) {
	topic, err := New("bench-put", c)
	if err != nil {
		b.Fatal(err)
	}
	msg := mmq.NewMessageByData(mmq.NewMessageData([]byte(utils.RandString(256))))
	reply := make(chan []error)
	var wg sync.WaitGroup
	go func() {
		for _ = range reply {
			wg.Done()
		}
	}()
	b.ResetTimer()
	buffer := []*mmq.Message{}
	for i := 0; i < b.N; i++ {
		m, _ := mmq.NewMessage(msg.Bytes(), true)
		buffer = append(buffer, m)
		if len(buffer) >= MaxPutBenchSize {
			wg.Add(1)
			topic.Put(buffer, reply)
			buffer = nil
		}
	}
	wg.Wait()
}
Esempio n. 4
0
func BenchmarkHttpPut(b *testing.B) {
	var data []byte
	batch := 200
	for i := 0; i < batch; i++ {
		msg := mmq.NewMessageByData(mmq.NewMessageData([]byte(utils.RandString(200))))
		data = append(data, msg.Bytes()...)
	}
	r := bytes.NewReader(data)
	client := &http.Client{}
	buffer := 0
	url := "http://localhost:8611/put?topic=http-test&size=200"
	for i := 0; i < b.N; i++ {
		if buffer < batch {
			buffer++
			continue
		}
		buffer = 0
		r.Seek(0, 0)
		resp, err := client.Post(url, "", r)
		if err != nil {
			b.Fatal(err)
		}
		io.Copy(ioutil.Discard, resp.Body)
		resp.Body.Close()
	}
}
Esempio n. 5
0
func TestFileCon(t *testing.T) {
	n := 100
	dirname := "/data/mmq/test/bitmap.file.con"
	os.RemoveAll(dirname)

	f, err := NewFileEx(dirname, 1)
	if err != nil {
		t.Fatal(err)
	}
	defer f.Close()

	buf := []byte(utils.RandString(3))
	off := int64(0)
	for i := 0; i < n; i++ {
		n, err := f.WriteAt(buf, off)
		if err != nil {
			t.Fatal(err)
		}
		if n != len(buf) {
			t.Fatal("short write", n, len(buf))
		}
		off += int64(n)
	}
}
Esempio n. 6
0
func BenchmarkTopicGet(b *testing.B) {
	n := b.N
	topic, err := New("bench-get", c)
	if err != nil {
		b.Fatal(err)
	}

	var wg2 sync.WaitGroup
	replyErrs := make(chan []error)
	go func() {
		for _ = range replyErrs {
			wg2.Done()
		}
	}()
	msg := mmq.NewMessageByData(mmq.NewMessageData([]byte(utils.RandString(256))))
	var buffer []*mmq.Message
	for i := 0; i < n; i++ {
		buffer = append(buffer, msg)
		if len(buffer) > MaxPutBenchSize {
			wg2.Add(1)
			topic.Put(buffer, replyErrs)
			buffer = nil
		}
	}
	wg2.Wait()
	close(replyErrs)

	b.ResetTimer()
	reply := make(chan []*mmq.Message, 1024)

	size := 0
	off := int64(0)
	var wg sync.WaitGroup
	go func() {
		for msgs := range reply {
			wg.Add(1)
			for _, m := range msgs {
				off += int64(len(m.Bytes()))
				wg.Done()
			}
			size -= len(msgs)
			wg.Done()
			if size == 0 {
				continue
			}
		}
	}()

	for i := 0; i < n; i++ {
		if size < MaxGetBenchSize {
			size++
			continue
		}

		wg.Add(size)
		if err := topic.GetSync(off, size, reply); err != nil {
			b.Fatal(err)
		}
		wg.Wait()
	}
	close(reply)
}