Skip to content

Commit

Permalink
dag: ordered
Browse files Browse the repository at this point in the history
Turns out that the ordered is a bad idea during parallel execution.
It only works well if you are doing serial runs.

I prefer to try something else
  • Loading branch information
DavidGamba committed Oct 16, 2024
1 parent a43128f commit 2a9bdd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
36 changes: 25 additions & 11 deletions dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ func (g *Graph) getNextVertex() (*Vertex, bool, bool) {
return keys[i] < keys[j]
})
}
// Logger.Printf("Keys: %v\n", keys)

if g.serial {
for k := range keys {
Expand All @@ -556,15 +555,26 @@ func (g *Graph) getNextVertex() (*Vertex, bool, bool) {
if vertex.status == runInProgress {
return vertex, false, false
}
for _, child := range vertex.Children {
childKeys := []ID{}
for k := range vertex.Children {
childKeys = append(childKeys, k)
}
if g.Ordered {
sort.Slice(childKeys, func(i, j int) bool {
return childKeys[i] < childKeys[j]
})
}

for _, k := range childKeys {
child := vertex.Children[k]
if child.status == runInProgress {
return child, false, false
}
}
}
}
for k := range keys {
vertex := g.Vertices[keys[k]]
for _, k := range keys {
vertex := g.Vertices[k]
if vertex.status != runPending && vertex.status != runSkip {
if vertex.status == runDone {
doneCount++
Expand All @@ -576,13 +586,17 @@ func (g *Graph) getNextVertex() (*Vertex, bool, bool) {
}
childPending := false

// TODO:
// childKeys := []ID{}
// for k := range vertex.Children {
// keys = append(keys, k)
// }

for _, child := range vertex.Children {
childKeys := []ID{}
for k := range vertex.Children {
childKeys = append(childKeys, k)
}
if g.Ordered {
sort.Slice(childKeys, func(i, j int) bool {
return childKeys[i] < childKeys[j]
})
}
for _, k := range childKeys {
child := vertex.Children[k]
if child.status == runPending {
childPending = true
}
Expand Down
9 changes: 4 additions & 5 deletions dag/dag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func TestDagSorted(t *testing.T) {
results := []int{}
generateFn := func(n int) getoptions.CommandFn {
return func(ctx context.Context, opt *getoptions.GetOpt, args []string) error {
time.Sleep(30 * time.Millisecond)
sm.Lock()
results = append(results, n)
sm.Unlock()
Expand Down Expand Up @@ -255,19 +254,19 @@ func TestDagSorted(t *testing.T) {
t.Errorf("Wrong list %d: %v\n", 3, results)
}
case 4:
if e != 1 {
if e != 2 {
t.Errorf("Wrong list %d: %v\n", 4, results)
}
case 5:
if e != 2 {
if e != 3 {
t.Errorf("Wrong list %d: %v\n", 5, results)
}
case 6:
if e != 3 {
if e != 6 {
t.Errorf("Wrong list %d: %v\n", 6, results)
}
case 7:
if e != 6 {
if e != 1 {
t.Errorf("Wrong list %d: %v\n", 7, results)
}
}
Expand Down

0 comments on commit 2a9bdd3

Please sign in to comment.