Skip to content

Commit

Permalink
fix up for time setting (Hyperledger-TWGC#191)
Browse files Browse the repository at this point in the history
* fix up

Signed-off-by: Sam Yuan <[email protected]>

* fix up

Signed-off-by: Sam Yuan <[email protected]>
  • Loading branch information
SamYuan1990 committed Aug 24, 2021
1 parent 1bb697c commit b4a9262
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
5 changes: 2 additions & 3 deletions pkg/infra/cmdImpl/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ func Process(configPath string, num int, burst int, rate float64, logger *log.Lo
finishCh := make(chan struct{})
errorCh := make(chan error, burst)
ctx, cancel := context.WithCancel(context.Background())
ctx = context.WithValue(ctx, "start", time.Now())
defer cancel()
for i := 0; i < len(config.Endorsers); i++ {
signed[i] = make(chan *basic.Elements, burst)
}
/*** workers ***/
observer_workers, err := observer.CreateObserverWorkers(config, crypto, blockCh, logger, ctx, finishCh, num, errorCh)
observer_workers, observers, err := observer.CreateObserverWorkers(config, crypto, blockCh, logger, ctx, finishCh, num, errorCh)
if err != nil {
return err
}
Expand All @@ -60,7 +59,7 @@ func Process(configPath string, num int, burst int, rate float64, logger *log.Lo
case err = <-errorCh:
return err
case <-finishCh:
duration := time.Since(ctx.Value("start").(time.Time))
duration := time.Since(observers.GetTime())
logger.Infof("Completed processing transactions.")
fmt.Printf("tx: %d, duration: %+v, tps: %f\n", num, duration, float64(num)/duration.Seconds())
return nil
Expand Down
5 changes: 5 additions & 0 deletions pkg/infra/observer/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,16 @@ func CreateObservers(ctx context.Context, crypto infra.Crypto, errorCh chan erro

func (o *Observers) Start() {
//o.StartTime = time.Now()
o.ctx = context.WithValue(o.ctx, "start", time.Now())
for i := 0; i < len(o.workers); i++ {
go o.workers[i].Start(o.errorCh, o.blockCh, o.ctx.Value("start").(time.Time))
}
}

func (o *Observers) GetTime() time.Time {
return o.ctx.Value("start").(time.Time)
}

func CreateObserver(ctx context.Context, channel string, node basic.Node, crypto infra.Crypto, logger *log.Logger) (*Observer, error) {
seek, err := trafficGenerator.CreateSignedDeliverNewestEnv(channel, crypto)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions pkg/infra/observer/observerFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import (
log "github.com/sirupsen/logrus"
)

func CreateObserverWorkers(config basic.Config, crypto infra.Crypto, blockCh chan *AddressedBlock, logger *log.Logger, ctx context.Context, finishCh chan struct{}, num int, errorCh chan error) ([]infra.Worker, error) {
func CreateObserverWorkers(config basic.Config, crypto infra.Crypto, blockCh chan *AddressedBlock, logger *log.Logger, ctx context.Context, finishCh chan struct{}, num int, errorCh chan error) ([]infra.Worker, *Observers, error) {
observer_workers := make([]infra.Worker, 0)
blockCollector, err := NewBlockCollector(config.CommitThreshold, len(config.Committers), ctx, blockCh, finishCh, num, true)
if err != nil {
return observer_workers, errors.Wrap(err, "failed to create block collector")
return observer_workers, nil, errors.Wrap(err, "failed to create block collector")
}
observer_workers = append(observer_workers, blockCollector)
observers, err := CreateObservers(ctx, crypto, errorCh, blockCh, config, logger)
if err != nil {
return observer_workers, err
return observer_workers, observers, err
}
observer_workers = append(observer_workers, observers)
return observer_workers, nil
return observer_workers, observers, nil
}

0 comments on commit b4a9262

Please sign in to comment.