fix sched_test
This commit is contained in:
parent
5881edb75e
commit
5a458a60c2
@ -87,7 +87,7 @@ type Scheduler struct {
|
|||||||
|
|
||||||
type WorkerHandle struct {
|
type WorkerHandle struct {
|
||||||
workerRpc Worker
|
workerRpc Worker
|
||||||
|
|
||||||
Info storiface.WorkerInfo
|
Info storiface.WorkerInfo
|
||||||
|
|
||||||
preparing *ActiveResources // use with WorkerHandle.lk
|
preparing *ActiveResources // use with WorkerHandle.lk
|
||||||
|
@ -2,7 +2,6 @@ package sealer
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
@ -10,6 +9,7 @@ import (
|
|||||||
"go.opencensus.io/stats"
|
"go.opencensus.io/stats"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/metrics"
|
"github.com/filecoin-project/lotus/metrics"
|
||||||
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WindowSelector func(sh *Scheduler, queueLen int, acceptableWindows [][]int, windows []SchedWindow) int
|
type WindowSelector func(sh *Scheduler, queueLen int, acceptableWindows [][]int, windows []SchedWindow) int
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package sealer
|
package sealer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
||||||
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
"github.com/filecoin-project/lotus/storage/sealer/storiface"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ActiveResources struct {
|
type ActiveResources struct {
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/filecoin-project/go-state-types/abi"
|
"github.com/filecoin-project/go-state-types/abi"
|
||||||
prooftypes "github.com/filecoin-project/go-state-types/proof"
|
prooftypes "github.com/filecoin-project/go-state-types/proof"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/api"
|
||||||
"github.com/filecoin-project/lotus/storage/paths"
|
"github.com/filecoin-project/lotus/storage/paths"
|
||||||
"github.com/filecoin-project/lotus/storage/sealer/fsutil"
|
"github.com/filecoin-project/lotus/storage/sealer/fsutil"
|
||||||
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
|
||||||
@ -587,18 +588,24 @@ func TestSched(t *testing.T) {
|
|||||||
|
|
||||||
type slowishSelector bool
|
type slowishSelector bool
|
||||||
|
|
||||||
func (s slowishSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, a *WorkerHandle) (bool, bool, error) {
|
func (s slowishSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, a SchedWorker) (bool, bool, error) {
|
||||||
time.Sleep(200 * time.Microsecond)
|
_, _ = a.Paths(ctx)
|
||||||
|
_, _ = a.TaskTypes(ctx)
|
||||||
return bool(s), false, nil
|
return bool(s), false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *WorkerHandle) (bool, error) {
|
func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b SchedWorker) (bool, error) {
|
||||||
time.Sleep(100 * time.Microsecond)
|
_, _ = a.Paths(ctx)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ WorkerSelector = slowishSelector(true)
|
var _ WorkerSelector = slowishSelector(true)
|
||||||
|
|
||||||
|
type tw struct {
|
||||||
|
api.Worker
|
||||||
|
io.Closer
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkTrySched(b *testing.B) {
|
func BenchmarkTrySched(b *testing.B) {
|
||||||
logging.SetAllLoggers(logging.LevelInfo)
|
logging.SetAllLoggers(logging.LevelInfo)
|
||||||
defer logging.SetAllLoggers(logging.LevelDebug)
|
defer logging.SetAllLoggers(logging.LevelDebug)
|
||||||
@ -609,14 +616,25 @@ func BenchmarkTrySched(b *testing.B) {
|
|||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
||||||
|
var whnd api.WorkerStruct
|
||||||
|
whnd.Internal.TaskTypes = func(p0 context.Context) (map[sealtasks.TaskType]struct{}, error) {
|
||||||
|
time.Sleep(100 * time.Microsecond)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
whnd.Internal.Paths = func(p0 context.Context) ([]storiface.StoragePath, error) {
|
||||||
|
time.Sleep(100 * time.Microsecond)
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
sched, err := newScheduler(ctx, "")
|
sched, err := newScheduler(ctx, "")
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
sched.Workers[storiface.WorkerID{}] = &WorkerHandle{
|
sched.Workers[storiface.WorkerID{}] = &WorkerHandle{
|
||||||
workerRpc: nil,
|
workerRpc: &tw{Worker: &whnd},
|
||||||
Info: storiface.WorkerInfo{
|
Info: storiface.WorkerInfo{
|
||||||
Hostname: "t",
|
Hostname: "t",
|
||||||
Resources: decentWorkerResources,
|
Resources: decentWorkerResources,
|
||||||
},
|
},
|
||||||
|
Enabled: true,
|
||||||
preparing: NewActiveResources(),
|
preparing: NewActiveResources(),
|
||||||
active: NewActiveResources(),
|
active: NewActiveResources(),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user