File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1
1
package nsqd
2
2
3
3
import (
4
+ "context"
4
5
"errors"
5
6
"fmt"
6
7
"io/ioutil"
7
8
"net/http"
8
9
"os"
9
10
"runtime"
10
11
"strconv"
12
+ "sync"
11
13
"testing"
12
14
"time"
13
15
@@ -273,3 +275,42 @@ func BenchmarkTopicToChannelPut(b *testing.B) {
273
275
runtime .Gosched ()
274
276
}
275
277
}
278
+
279
+ func BenchmarkTopicMessagePump (b * testing.B ) {
280
+ b .StopTimer ()
281
+ topicName := "bench_topic_put_throughput" + strconv .Itoa (b .N )
282
+ opts := NewOptions ()
283
+ opts .Logger = test .NewTestLogger (b )
284
+ opts .LogLevel = LOG_WARN
285
+ opts .MemQueueSize = int64 (b .N )
286
+ _ , _ , nsqd := mustStartNSQD (opts )
287
+ defer os .RemoveAll (opts .DataPath )
288
+ defer nsqd .Exit ()
289
+
290
+ topic := nsqd .GetOrCreateTopic (topicName )
291
+ ch := topic .GetOrCreateChannel ("ch" )
292
+ ctx , cancel := context .WithCancel (context .Background ())
293
+
294
+ var wg sync.WaitGroup
295
+ for i := 0 ; i < runtime .GOMAXPROCS (0 ); i ++ {
296
+ wg .Add (1 )
297
+ go func () {
298
+ defer wg .Done ()
299
+ for {
300
+ select {
301
+ case <- ch .memoryMsgChan :
302
+ case <- ctx .Done ():
303
+ return
304
+ }
305
+ }
306
+ }()
307
+ }
308
+
309
+ b .StartTimer ()
310
+ for i := 0 ; i <= b .N ; i ++ {
311
+ msg := NewMessage (topic .GenerateID (), []byte ("aaaaaaaaaaaaaaaaaaaaaaaaaaa" ))
312
+ topic .PutMessage (msg )
313
+ }
314
+ cancel ()
315
+ wg .Wait ()
316
+ }
You can’t perform that action at this time.
0 commit comments