-
Originally opened by @svend in cuelang/cue#640 cue version: I using a custom cue command to start a large number (100s) of independent tasks using exec.Run. The number of process tasks is too large to run them all in parallel, so I am trying to find a way to limit how many tasks are run at a time. My current attempt involves grouping tasks, and making each group depend on the previous group completing. However, adding the Here's an simplfied example of what I am trying:
This should start four groups of tasks serially. The tasks in a group run in parallel. I would expect the tasks to take about four seconds, but it takes over a minute on my computer, and causes high CPU.
If I comment out the
Is there a reason adding these dependencies is so expensive? Is there a better way to control how many tasks run at once? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 1 reply
-
Original reply by @svend in cuelang/cue#640 (comment) Diving up the work into
|
Beta Was this translation helpful? Give feedback.
-
Original reply by @mpvl in cuelang/cue#640 (comment) It would not be an unreasonable feature for I've thought about doing this when writing |
Beta Was this translation helpful? Give feedback.
-
Original reply by @mpvl in cuelang/cue#640 (comment) |
Beta Was this translation helpful? Give feedback.
-
Original reply by @myitcv in cuelang/cue#640 (comment) On the basis this seems like a good idea (per @mpvl) I've just created cuelang/cue#709 on the back of this discussion. |
Beta Was this translation helpful? Give feedback.
-
I think the reason using I switched from
Here's the code: $ cat serial-1/test_tool.cue
package test
import (
"tool/exec"
)
let numTasks = 30
let tasks = [ for i, _ in numTasks * [0] {"task-\(i)"}]
let duration = 1 // each task takes N seconds
command: test: {
for i, t in tasks {
let shellCommand = """
echo $(date +%s): group:\( i ) task:\( t ) starting
/bin/sleep \( duration )
echo $(date +%s): group:\( i ) task:\( t ) finished
"""
task: "\( i )": exec.Run & {
// Run each task serially
if i > 0 {
$after: task["\( i-1 )"]
}
cmd: ["sh", "-e", "-c", shellCommand]
}
}
}
$ cat serial-2/test_tool.cue
package test
import (
"tool/exec"
)
let numTasks = 30
let tasks = [ for i, _ in numTasks * [0] {"task-\(i)"}]
let duration = 1 // each task takes N seconds
command: test: {
for i, t in tasks {
let shellCommand = """
echo $(date +%s): group:\( i ) task:\( t ) starting
/bin/sleep \( duration )
echo $(date +%s): group:\( i ) task:\( t ) finished
"""
task: "\( i )": exec.Run & {
// Run each task serially
if i > 0 {
_after: task["\( i-1 )"].success
}
cmd: ["sh", "-e", "-c", shellCommand]
}
}
}
$ diff serial-{1,2}/test_tool.cue
23c23
< $after: task["\( i-1 )"]
---
> _after: task["\( i-1 )"].success There is a comment in the
|
Beta Was this translation helpful? Give feedback.
Original reply by @myitcv in cuelang/cue#640 (comment)
On the basis this seems like a good idea (per @mpvl) I've just created cuelang/cue#709 on the back of this discussion.