cpu and memory optimizations

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-08-27 02:24:43 +03:00
parent fe6d7d340e
commit 54ecafc4b1
4 changed files with 131 additions and 97 deletions

View File

@@ -2,6 +2,7 @@ package kgo_test
import (
"context"
"fmt"
"os"
"strings"
"sync/atomic"
@@ -56,7 +57,7 @@ func TestPubSub(t *testing.T) {
}
}()
/*
/*
msgs := make([]*broker.Message, 0, 600000)
for i := 0; i < 600000; i++ {
msgs = append(msgs, bm)
@@ -66,7 +67,7 @@ func TestPubSub(t *testing.T) {
t.Fatal(err)
}
t.Skip()
*/
*/
done := make(chan bool, 1)
idx := int64(0)
fn := func(msg broker.Event) error {
@@ -77,7 +78,7 @@ func TestPubSub(t *testing.T) {
sub, err := b.Subscribe(ctx, "test", fn,
broker.SubscribeAutoAck(true),
broker.SubscribeGroup("test23"),
broker.SubscribeGroup("test29"),
broker.SubscribeBodyOnly(true))
if err != nil {
t.Fatal(err)
@@ -91,9 +92,13 @@ func TestPubSub(t *testing.T) {
ticker := time.NewTicker(2 * time.Minute)
defer ticker.Stop()
pticker := time.NewTicker(1 * time.Second)
defer pticker.Stop()
go func() {
for {
select {
case <-pticker.C:
fmt.Printf("processed %v\n", atomic.LoadInt64(&idx))
case <-ticker.C:
close(done)
}