iis - Making async WebApi wrapper over existing code -
we exposing our current logic/business layer using webapi. per understanding, if want keep our self safe thread starvation requests, should make async webapi controller, large number of concurrent request can make up.
i understand underlying service/business layer synchronous, there no performance gain. aiming large number of concurrent requests pass through.
below code using:
public async task<ihttpactionresult> get() { var result = await task.run(() => service.getallcompanies()); //existing business layer return ok(result); }
wrapping underlying layer in task, proceed , achieve goal.
my understanding if await
-ed methods' implementations aren't async, not accomplishing think are. if have cpu-bound service methods, you're releasing thread request-handling pool , spinning new 1 (from same pool, mind you) when task.run();
incur overhead switch, asp.net thread pool still doing work, haven't achieved want.
if service methods can converted pure (or pure) async code, stand benefit working bottom up.
reference: https://msdn.microsoft.com/en-us/magazine/dn802603.aspx
Comments
Post a Comment