I have been using F# Async workflow for awhile and really enjoying it. Recently, I'm working on a project involving many independent computation on separate Deedle Frame which I make use of Async.Parallel. And in those asyncs, many other asyncs are also computed in parallel fashion (nested Async?). My code is something like this
let processRoomAsync room =
async{
let x = do_something room
return x
}
let processCompressorAsync compressor =
async{
let rooms = get_rooms_from_compressor compressor
let! y =
Array.map processRoomAsync rooms
|> Async.Parallel
return do_something_with_y y
}
let processBuilding building =
let compressors = get_compressors_for_building building
let processResult =
Array.map processCompressorAsync compressors
|> Async.Parallel
|> Async.RunSynchronously
do_something_with_result processResult
The idea of the above code is that I have a building, e.g. a hotel, with many AC compressors, each compressor serves many rooms. I need to process all the rooms data that connect to one compressor in-order to model that compressor power. Then all compressors data is aggregated to give overall result of the building.
When the number of Async is small, the result is expected when compared with single async execution time.
However, when the number of async is more than 100, I notice significant degradation of computational time.
I read some document about maxDegreeOfParallelism but I don't quite get which number I should use. Should it be the number of vCPU in my computer? If so, what's about those nested Async.Parallel? I have tried several values and the improvement is quite minimal.
I read somewhere that I should use MailboxProcessor but don't quite understand that. Also, some documentation says async is for I/O bound not for computation and this post seems to suggest to use Hopac but I wonder is it worth to spend time study about it?
Thanks and sorry for the long question.