From 217bf0ab0fd26868940059f92e0f231a11d73d1a Mon Sep 17 00:00:00 2001 From: M09Ic Date: Thu, 10 Nov 2022 15:48:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=A3=85--offset=E4=B8=8E--limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pool.go | 16 +++++++++++++--- internal/runner.go | 4 +++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/pool.go b/internal/pool.go index 1ac906a..96b5ba2 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -116,7 +116,6 @@ func NewPool(ctx context.Context, config *pkg.Config, outputCh chan *baseline) ( case WordSource: // 异步进行性能消耗较大的深度对比 - pool.reqCount++ pool.tempCh <- bl if pool.reqCount%pool.checkPeriod == 0 { @@ -187,8 +186,8 @@ func (p *Pool) Init() error { return nil } -func (p *Pool) Run(ctx context.Context) { - +func (p *Pool) Run(ctx context.Context, offset, limit int) { + maxreq := offset + limit Loop: for { select { @@ -196,12 +195,23 @@ Loop: if !ok { break Loop } + + if p.reqCount < offset { + p.reqCount++ + continue + } + + if p.reqCount > maxreq { + break Loop + } + for _, fn := range p.Fns { u = fn(u) } if u == "" { continue } + p.reqCount++ p.wg.Add(1) _ = p.pool.Invoke(newUnit(u, WordSource)) case <-ctx.Done(): diff --git a/internal/runner.go b/internal/runner.go index cb9f051..1d28afe 100644 --- a/internal/runner.go +++ b/internal/runner.go @@ -28,6 +28,8 @@ type Runner struct { Probes []string OutputCh chan *baseline Progress *uiprogress.Progress + Offset int + Limit int } func (r *Runner) Prepare() error { @@ -74,7 +76,7 @@ func (r *Runner) Prepare() error { return } // todo pool 总超时时间 - pool.Run(ctx) + pool.Run(ctx, r.Offset, r.Limit) r.poolwg.Done() })