dynamically compute number of workers for parallel chain walk

This commit is contained in:
vyzo 2022-01-25 19:47:58 +02:00
parent 7c8edf5632
commit 8e01e73de4

View File

@ -694,11 +694,6 @@ func (s *SplitStore) walkChain(ts *types.TipSet, inclState, inclMsgs abi.ChainEp
return nil return nil
} }
workers := runtime.NumCPU() / 2
if workers < 2 {
workers = 2
}
for len(toWalk) > 0 { for len(toWalk) > 0 {
// walking can take a while, so check this with every opportunity // walking can take a while, so check this with every opportunity
if err := s.checkClosing(); err != nil { if err := s.checkClosing(); err != nil {
@ -712,6 +707,11 @@ func (s *SplitStore) walkChain(ts *types.TipSet, inclState, inclMsgs abi.ChainEp
walking := toWalk walking := toWalk
toWalk = nil toWalk = nil
workers := len(walking)
if workers > runtime.NumCPU()/2 {
workers = runtime.NumCPU() / 2
}
workch := make(chan cid.Cid, len(walking)) workch := make(chan cid.Cid, len(walking))
for _, c := range walking { for _, c := range walking {
workch <- c workch <- c