forked from pingcap/br
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restore: optimize SQL processing speed (pingcap#110)
* restore: add metrics * mydump,restore: `mydumper.read-block-size` to init `ChunkParser` read block buffer * *: limit IO concurrency * *: add apply worker metrics * mydump: set read block buffer size to BlockSize * config.BufferSizeScale * worker: add unit test
- Loading branch information
Showing
9 changed files
with
173 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package worker | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/pingcap/tidb-lightning/lightning/metric" | ||
) | ||
|
||
type RestoreWorkerPool struct { | ||
limit int | ||
workers chan *RestoreWorker | ||
name string | ||
} | ||
|
||
type RestoreWorker struct { | ||
ID int64 | ||
} | ||
|
||
func NewRestoreWorkerPool(ctx context.Context, limit int, name string) *RestoreWorkerPool { | ||
workers := make(chan *RestoreWorker, limit) | ||
for i := 0; i < limit; i++ { | ||
workers <- &RestoreWorker{ID: int64(i + 1)} | ||
} | ||
|
||
metric.IdleWorkersGauge.WithLabelValues(name).Set(float64(limit)) | ||
return &RestoreWorkerPool{ | ||
limit: limit, | ||
workers: workers, | ||
name: name, | ||
} | ||
} | ||
|
||
func (pool *RestoreWorkerPool) Apply() *RestoreWorker { | ||
start := time.Now() | ||
worker := <-pool.workers | ||
metric.IdleWorkersGauge.WithLabelValues(pool.name).Set(float64(len(pool.workers))) | ||
metric.ApplyWorkerSecondsHistogram.WithLabelValues(pool.name).Observe(time.Since(start).Seconds()) | ||
return worker | ||
} | ||
|
||
func (pool *RestoreWorkerPool) Recycle(worker *RestoreWorker) { | ||
pool.workers <- worker | ||
metric.IdleWorkersGauge.WithLabelValues(pool.name).Set(float64(len(pool.workers))) | ||
} | ||
|
||
func (pool *RestoreWorkerPool) HasWorker() bool { | ||
return len(pool.workers) > 0 | ||
} |
Oops, something went wrong.