@@ -17,6 +17,7 @@ import (
17
17
"time"
18
18
19
19
"github.com/dgryski/go-farm"
20
+ "github.com/dustin/go-humanize"
20
21
"github.com/dustin/go-humanize/english"
21
22
"google.golang.org/grpc"
22
23
"google.golang.org/grpc/codes"
@@ -70,6 +71,9 @@ type loader struct {
70
71
// To get time elapsed
71
72
start time.Time
72
73
74
+ inflight int32
75
+ conc int32
76
+
73
77
conflicts map [uint64 ]struct {}
74
78
uidsLock sync.RWMutex
75
79
@@ -156,6 +160,7 @@ func (l *loader) infinitelyRetry(req *request) {
156
160
}
157
161
158
162
func (l * loader ) mutate (req * request ) error {
163
+ atomic .AddInt32 (& l .inflight , 1 )
159
164
txn := l .dc .NewTxn ()
160
165
req .CommitNow = true
161
166
request := & api.Request {
@@ -168,6 +173,7 @@ func (l *loader) mutate(req *request) error {
168
173
169
174
func (l * loader ) request (req * request ) {
170
175
atomic .AddUint64 (& l .reqNum , 1 )
176
+ defer atomic .AddInt32 (& l .inflight , - 1 )
171
177
err := l .mutate (req )
172
178
if err == nil {
173
179
atomic .AddUint64 (& l .nquads , uint64 (len (req .Set )))
@@ -390,23 +396,52 @@ func (l *loader) deregister(req *request) {
390
396
// caller functions.
391
397
func (l * loader ) makeRequests () {
392
398
defer l .requestsWg .Done ()
399
+ atomic .AddInt32 (& l .conc , 1 )
400
+ defer atomic .AddInt32 (& l .conc , - 1 )
393
401
394
402
buffer := make ([]* request , 0 , l .opts .bufferSize )
395
- drain := func (maxSize int ) {
396
- for len (buffer ) > maxSize {
397
- i := 0
398
- for _ , req := range buffer {
399
- // If there is no conflict in req, we will use it
400
- // and then it would shift all the other reqs in buffer
401
- if ! l .addConflictKeys (req ) {
402
- buffer [i ] = req
403
- i ++
404
- continue
405
- }
406
- // Req will no longer be part of a buffer
403
+ var loops int
404
+ drain := func () {
405
+ i := 0
406
+ for _ , req := range buffer {
407
+ loops ++
408
+ // If there is no conflict in req, we will use it
409
+ // and then it would shift all the other reqs in buffer
410
+ if ! l .addConflictKeys (req ) {
411
+ buffer [i ] = req
412
+ i ++
413
+ continue
414
+ }
415
+ // Req will no longer be part of a buffer
416
+ l .request (req )
417
+ }
418
+ buffer = buffer [:i ]
419
+ }
420
+
421
+ t := time .NewTicker (5 * time .Second )
422
+ defer t .Stop ()
423
+
424
+ loop:
425
+ for {
426
+ select {
427
+ case req , ok := <- l .reqs :
428
+ if ! ok {
429
+ break loop
430
+ }
431
+ req .conflicts = l .conflictKeysForReq (req )
432
+ if l .addConflictKeys (req ) {
407
433
l .request (req )
434
+ } else {
435
+ buffer = append (buffer , req )
436
+ }
437
+
438
+ case <- t .C :
439
+ for {
440
+ drain ()
441
+ if len (buffer ) < l .opts .bufferSize {
442
+ break
443
+ }
408
444
}
409
- buffer = buffer [:i ]
410
445
}
411
446
}
412
447
@@ -417,10 +452,13 @@ func (l *loader) makeRequests() {
417
452
} else {
418
453
buffer = append (buffer , req )
419
454
}
420
- drain (l .opts .bufferSize - 1 )
455
+
456
+ drain ()
457
+ time .Sleep (100 * time .Millisecond )
421
458
}
459
+ fmt .Printf ("Looped %d times over buffered requests.\n " , loops )
422
460
423
- drain (0 )
461
+ drain ()
424
462
}
425
463
426
464
func (l * loader ) printCounters () {
@@ -434,8 +472,11 @@ func (l *loader) printCounters() {
434
472
rate := float64 (counter .Nquads - last .Nquads ) / period .Seconds ()
435
473
elapsed := time .Since (start ).Round (time .Second )
436
474
timestamp := time .Now ().Format ("15:04:05Z0700" )
437
- fmt .Printf ("[%s] Elapsed: %s Txns: %d N-Quads: %d N-Quads/s [last 5s]: %5.0f Aborts: %d\n " ,
438
- timestamp , x .FixedDuration (elapsed ), counter .TxnsDone , counter .Nquads , rate , counter .Aborts )
475
+ fmt .Printf ("[%s] Elapsed: %s Txns: %d N-Quads: %s N-Quads/s: %s" +
476
+ " Inflight: %2d/%2d Aborts: %d\n " ,
477
+ timestamp , x .FixedDuration (elapsed ), counter .TxnsDone ,
478
+ humanize .Comma (int64 (counter .Nquads )), humanize .Comma (int64 (rate )),
479
+ atomic .LoadInt32 (& l .inflight ), atomic .LoadInt32 (& l .conc ), counter .Aborts )
439
480
last = counter
440
481
}
441
482
}
0 commit comments