asp.net mvc - Why isn't async await improving performance? -


i watched video : https://channel9.msdn.com/events/techdays/techdays-2012-the-netherlands/2287. tried implement usage of async/await in controller. basicaly did :

 public class homecontroller : controller     {         private static webclient _webclient = new webclient();         public async task<actionresult> indexasync()         {             var data = await _webclient.downloadstringtaskasync("http://stackoverflow.com/");             return view("index", (object)data);         }         public actionresult index()         {             var data = _webclient.downloadstring("http://stackoverflow.com/");             return view("index", (object)data);         }     } 

then used apache benchmark , did 2 following tests :

ab -n 100 -c 100 http://localhost:53446/home/index 

and

ab -n 100 -c 100 http://localhost:53446/home/indexasync 

and got exact same performance (i have 8 cpu core). why ?

async not performance. that's categorically incorrect. in fact, async request less performant sync, because there's additional overhead involved async.

the reason use async efficient resource-management , scale. typical web server process have around 1000 threads. called "max requests", 1 thread general equals 1 request. if have 8 core cpu, should ideally have process per core (in iis called "web workers"). so, theoretically, you'd have around 8000 threads total work with.

that's quite lot actually, though modern web page consumes more requests people think. page 1 request, page have images , external js , css files, of generate request, , utilize ajax, further requests. point while 8000+ threads still quite lot have in pool, still run out if server under significant load.

async merely gives breathing room above limit. in situations thread enters wait-state, can returned pool field other requests while whatever external action being completed. alternative thread sit there idle (sync). that's there it. it's entirely tasking otherwise idle threads other bit of work, mean difference between requests queuing , timing out or being handled, if slowly.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -