Skip to content

Commit

Permalink
fix sched_test
Browse files Browse the repository at this point in the history
  • Loading branch information
magik6k committed Nov 28, 2022
1 parent 73fbc4b commit dee3de9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion storage/sealer/sched.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type Scheduler struct {

type WorkerHandle struct {
workerRpc Worker

Info storiface.WorkerInfo

preparing *ActiveResources // use with WorkerHandle.lk
Expand Down
2 changes: 1 addition & 1 deletion storage/sealer/sched_assigner_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package sealer

import (
"context"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
"math/rand"
"sort"
"sync"

"go.opencensus.io/stats"

"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
Expand Down
3 changes: 2 additions & 1 deletion storage/sealer/sched_resources.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package sealer

import (
"sync"

"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
"github.com/filecoin-project/lotus/storage/sealer/storiface"
"sync"
)

type ActiveResources struct {
Expand Down
28 changes: 23 additions & 5 deletions storage/sealer/sched_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/filecoin-project/go-state-types/abi"
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/sealer/fsutil"
"github.com/filecoin-project/lotus/storage/sealer/sealtasks"
Expand Down Expand Up @@ -587,18 +588,24 @@ func TestSched(t *testing.T) {

type slowishSelector bool

func (s slowishSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, a *WorkerHandle) (bool, bool, error) {
time.Sleep(200 * time.Microsecond)
func (s slowishSelector) Ok(ctx context.Context, task sealtasks.TaskType, spt abi.RegisteredSealProof, a SchedWorker) (bool, bool, error) {
_, _ = a.Paths(ctx)
_, _ = a.TaskTypes(ctx)
return bool(s), false, nil
}

func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b *WorkerHandle) (bool, error) {
time.Sleep(100 * time.Microsecond)
func (s slowishSelector) Cmp(ctx context.Context, task sealtasks.TaskType, a, b SchedWorker) (bool, error) {
_, _ = a.Paths(ctx)
return true, nil
}

var _ WorkerSelector = slowishSelector(true)

type tw struct {
api.Worker
io.Closer
}

func BenchmarkTrySched(b *testing.B) {
logging.SetAllLoggers(logging.LevelInfo)
defer logging.SetAllLoggers(logging.LevelDebug)
Expand All @@ -609,14 +616,25 @@ func BenchmarkTrySched(b *testing.B) {
for i := 0; i < b.N; i++ {
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, "")
require.NoError(b, err)
sched.Workers[storiface.WorkerID{}] = &WorkerHandle{
workerRpc: nil,
workerRpc: &tw{Worker: &whnd},
Info: storiface.WorkerInfo{
Hostname: "t",
Resources: decentWorkerResources,
},
Enabled: true,
preparing: NewActiveResources(),
active: NewActiveResources(),
}
Expand Down

0 comments on commit dee3de9

Please sign in to comment.