Saturday 15 May 2010

asp.net - How bad is it to run an entire HTTP action method in separate thread using Task::Run()? -



asp.net - How bad is it to run an entire HTTP action method in separate thread using Task::Run()? -

i'm writing web services in c++/cli (not choice) using microsoft's web api. lot of functions in web api async, because i'm using c++/cli, don't async/await back upwards of c# or vb. fallback position utilize continuewith() schedule continuation delegate reading async task's result safely.

however, because c++/cli doesn't back upwards inline anonymous delegates or managed lambdas, every delegate continuation must written separate function somewhere. turns spaghetti number of async functions in web api.

so, avoid deadlock issues of task<t>::result, i've been trying this:

[httpget, route( "get/some/dto" )] task< somedto ^ > ^ myactionmethod() { homecoming task::run( gcnew func< somedto ^ >( this, &mycontroller::myactionmethod2 ) ); } somedto ^ myactionmethod2() { // execute code , utilize task->result calls need without deadlocking }

okay, know isn't great, how bad it? don't yet understand plenty of guts of web api or asp.net comprehend performance or scaling ramifications have.

also, other consequences may have aren't related performance? example, exceptions wrapped in aggregateexception, represents additional complexity , work handling exceptions.

your memory usage increment application's parallelism. every concurrent phone call myactionmethod need separate thread own stack. cost 1 mb of ram each concurrent call. if myactionmethod runs long plenty 10000 instances run @ once, you're looking @ 10 gb of ram. there cpu overhead in setting each thread.

if concurrency low, dropping async back upwards won't problem. in case, don't bother task::run. alter myactionmethod homecoming somedto^ (no task wrapper).

another potential concern lose easy utilize of cancellation tokens. however, web api it's fine allow exception propagate web api, ends cancelling synchronous phone call anyway.

finally, if planning on performing operation within action method in parallel, you'll still need utilize continuewith accomplish that. going non-async default means you'll perform 1 operation @ time. fortunately, it's fine so.

asp.net .net asynchronous asp.net-web-api c++-cli

No comments:

Post a Comment