forked from nuweba/httpbench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
concurrentsync.go
41 lines (33 loc) · 1.09 KB
/
concurrentsync.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package engine
import (
"github.com/nuweba/counter"
"github.com/nropatas/httpbench/concurrency"
"github.com/nropatas/httpbench/syncedtrace"
"time"
)
type SyncConcurrent struct {
syncs []*SyncConfig
reqCounter *counter.Counter
concurrency *concurrency.Manager
}
func NewSyncConcurrent() *SyncConcurrent {
return &SyncConcurrent{reqCounter: new(counter.Counter), concurrency: concurrency.New(0)}
}
func (syncC *SyncConcurrent) NewSyncConfig(hook syncedtrace.TraceHookType, concurrencyLimit uint64, duration time.Duration, waitReq bool, result chan *TraceResult) *SyncConfig {
sc := NewSyncConfig(hook, concurrencyLimit, duration, waitReq, result)
sc.reqCounter = syncC.reqCounter
sc.Concurrency.ConcurrentCount = syncC.concurrency.ConcurrentCount
syncC.syncs = append(syncC.syncs, sc)
return sc
}
func (syncC *SyncConcurrent) MaxConcurrent() uint64 {
return syncC.concurrency.ConcurrentCount.Max()
}
func (syncC *SyncConcurrent) WaitAll() {
for _, sync := range syncC.syncs {
sync.done.Wait()
}
}
func (syncC *SyncConcurrent) ReqCounter() uint64 {
return syncC.reqCounter.Counter()
}