c# - Nested Async/Await Doesn't Appear To Be Scaling -
i have following (simplified) code:
public async task getdata(domainobject domainobject, int depth) { // async operation quick, , there's five. ienumerable<tierone> tierones = await domainobject.gettieronesasync(); var tieronetasks = tierones.select(async tierone => { // async operation quick , there's three. ienumerable<tiertwo> tiertwos = await tierone.gettiertwosasync(); if (depth <= tiertwodepth) return; var tiertwotasks = tiertwos.select(async tiertwo => { // async operation fast, , there's >= 100. ienumerable<tierthree> tierthrees = await tiertwo.gettierthreesasync(); if (depth <= tierthreedepth) return; var tierthreetasks = tierthrees.select(async tierthree => { // async operation slow, , there's usually.. 50? await tierthree.gettierfoursasync(); }); await task.whenall(tierthreetasks.toarray()); }); await task.whenall(tiertwotasks.toarray()); }); await task.whenall(tieronetasks.toarray()); } based off of have seen, not seem scaling well. of async operations "true async" operations meaning i/o.
am using async/await incorrectly scenario? based off of current observations, isn't scaling expect. tpl dataflow solution?
for single call getdata, nested async/await calls won't introduce concurrency. retrieve tierones, tiertwos tierone-#1, tierthrees tiertwo-#1, , on, run in sequence (though there may concurrency inside gettier*async methods).
if want concurrent requests, tpl dataflow indeed better solution.
Comments
Post a Comment