-
Notifications
You must be signed in to change notification settings - Fork 55
Description
Description
I've tried to implement some of my work with asyncSeq.
I have a big job list which I want to process in parallel with some throttling (32 threads maximum for example) and then feed results as stream to other async tasks (saving to disk etc).
Async.Parallel is not good for me because it doesn't have max thread setting
I've also tried slicing job list myself but it was very memory inefficient so that's the moment when I switched to AsyncSeq
Repro steps
Just run the code below
#r @"../../packages/FSharp.Control.AsyncSeq/lib/net45/FSharp.Control.AsyncSeq.dll"
open FSharp.Control
//simulating long IO work
let longWork x = async {
do! Async.Sleep 3000
return x * 2
}
//simulating another async task, saving to HDD for example
let log x = async {
let! x = x
printfn "%A" x
return x
}
let doWorkAndSaveInParallel() =
async {
do! seq {1..100} //original data
|> AsyncSeq.ofSeq
|> AsyncSeq.mapAsync (longWork >> log) //my async workflow
|> AsyncSeq.indexed
|> AsyncSeq.groupBy (fun (i, _) -> i % 32L) //slicing by 32 threads
|> AsyncSeq.mapAsyncParallel
(snd >> AsyncSeq.map snd >> AsyncSeq.iter ignore) //parallel
|> AsyncSeq.iter ignore //iteration
} |> Async.RunSynchronously
Expected behavior
Expected to see numbers 2,4,6...64 after 3 seconds almost simultaneously (in any order), after 3 more seconds there should be numbers 66,68,70..128 etc...
Actual behavior
Number appears one by one with 3 sec interval (no parallel at all)
Known workarounds
Do parallelism myself is only known workaround
Related information
Win10
FSharp.Control.AsyncSeq (2.0.16)