<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx</link><description>In these last days I’ve been busy with the source code of the futures assembly. I’ve already written one post (not published yet) and was planning on writing a couple more of them that showed how to use the asynchronous features introduced by the future</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684873</link><pubDate>Sun, 05 Apr 2009 10:07:52 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684873</guid><dc:creator>luisabreu</dc:creator><description>&lt;p&gt;btw, I thought I&amp;#39;d add this link to the discussion: &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/ericeil/archive/2008/06/20/windows-i-o-threads-vs-managed-i-o-threads.aspx"&gt;blogs.msdn.com/.../windows-i-o-threads-vs-managed-i-o-threads.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It seems like managed IO threads aren&amp;#39;t really equivalent to unmanaged IO threads. I think this discussion has just made me realize that I need to really start studying multithreading (which was one of my objectives to this year)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684873" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684870</link><pubDate>Sun, 05 Apr 2009 09:55:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684870</guid><dc:creator>luisabreu</dc:creator><description>&lt;p&gt;Guys, thanks for the great discussion. Levi, I believe that Israel has a point: it would be probably a good idea to add a note saying that you shouldn&amp;#39;t be delegating work to the threading pool during an async action (I believe that an additional note to the doc would be all that is needed to warn people about it)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684870" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684701</link><pubDate>Sat, 04 Apr 2009 18:19:15 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684701</guid><dc:creator>Levi</dc:creator><description>&lt;p&gt;Hi Israel -&lt;/p&gt;
&lt;p&gt;Code that spawns off a worker thread and calls Thread.Sleep() is fairly common in writing sample code for Async patterns, but you wouldn&amp;#39;t actually go off and do this in the real world. :) &amp;nbsp;It&amp;#39;s just a sample showing that everything works; it&amp;#39;s not best practice. &amp;nbsp;The other samples (the ones that use RegisterTask) are what you should be focusing on, as they don&amp;#39;t use the ThreadPool.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684701" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684655</link><pubDate>Sat, 04 Apr 2009 14:41:21 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684655</guid><dc:creator>Israel Aece</dc:creator><description>&lt;p&gt;Hello Luis,&lt;/p&gt;
&lt;p&gt;You can use ADO.NET 2.0 async methods, or invoke WebServices via BeginXXX/EndXXX methods inside of async controller method. These operations already use IO thread to process.&lt;/p&gt;
&lt;p&gt;LINQ To SQL doesn&amp;#39;t support async execution so, envolve this execution via delegates, don&amp;#39;t provide any benefits.&lt;/p&gt;
&lt;p&gt;The problem is that the sample is using the ThreadPool, &amp;quot;stealing&amp;quot; threads from ThreadPool.&lt;/p&gt;
&lt;p&gt;Bye&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684655" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684639</link><pubDate>Sat, 04 Apr 2009 13:25:56 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684639</guid><dc:creator>luisabreu</dc:creator><description>&lt;p&gt;Hello Israel. To be honest, I&amp;#39;ve just given a quick glance at the async doc, so I&amp;#39;ll have to go back to it again and see the code that they&amp;#39;re showing.&lt;/p&gt;
&lt;p&gt;I&amp;#39;m still unsure on why you&amp;#39;d want to use IO threads for doing the work *if* it&amp;#39;s not IO related...btw, you can use PLINQ for making your sync actions async...god, only 30 secs looking at multithreading and my head is already hurting :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684639" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684638</link><pubDate>Sat, 04 Apr 2009 13:20:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684638</guid><dc:creator>luisabreu</dc:creator><description>&lt;p&gt;Hello again Levi. Thanks for the feedback!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684638" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684626</link><pubDate>Sat, 04 Apr 2009 12:24:29 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684626</guid><dc:creator>Israel Aece</dc:creator><description>&lt;p&gt;Hi Luis,&lt;/p&gt;
&lt;p&gt;I think that MVC uses the thread from the ThreadPool to process request and, in sample that exists in document of the Async Controller, it uses the ThreadPool again. IMHO, I believe that there are no benefits in this case. The main purpose of async pages of WebForm is to leave threads to process &amp;quot;light&amp;quot; request, where IO work isn&amp;#39;t involved.&lt;/p&gt;
&lt;p&gt;Maybe, you can combine AsyncController with Wintellect&amp;#39;s CallbackThreadPool to use IO Threads, like I showed here: &lt;a rel="nofollow" target="_new" href="http://weblogs.pontonetpt.com/israelaece/posts/28605.aspx"&gt;weblogs.pontonetpt.com/.../28605.aspx&lt;/a&gt;, leaving thread to serve another request while you executes IO task.&lt;/p&gt;
&lt;p&gt;Best Regards.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684626" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684507</link><pubDate>Fri, 03 Apr 2009 21:55:46 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684507</guid><dc:creator>Levi</dc:creator><description>&lt;p&gt;We designed the AsyncController with the intent that action method authors would delegate work to components that internally used I/O completion ports, as you mentioned. &amp;nbsp;There probably won&amp;#39;t be any benefit to using the AsyncController if all of your work is performed on ThreadPool threads, since you&amp;#39;ll be pegging the CPU anyway and IIRC you&amp;#39;ll be using the same ThreadPool that ASP.NET uses to respond to requests.&lt;/p&gt;
&lt;p&gt;Now, if you were a power user and really knew what you were doing, I suppose you could maintain your own ThreadPool (separate from ASP.NET&amp;#39;s and the CLR&amp;#39;s) and have your async methods delegate into *that*. &amp;nbsp;In general I&amp;#39;d not recommend this, but if you were careful about what kind of work you posted to that ThreadPool then you could probably make some fairly strong performance guarantees. &amp;nbsp;But I try not to play around too much in black magic territory. :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684507" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684501</link><pubDate>Fri, 03 Apr 2009 20:33:20 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684501</guid><dc:creator>luisabreu</dc:creator><description>&lt;p&gt;Ah, the old IO/worker thread issues...Ok, I recall that IIS 6 introduced some changes to this and all ASP.NET requests are now handled by worker threads (instead of IO threads, like happened with IIS 5). If this is correct, then I&amp;#39;d go as far as saying that async actions will only be useful when you&amp;#39;re doing a long action which involves delegating to IO threads (ex.: web service calls, async database access - I&amp;#39;m under the impression that completion ports are used for async db access introduced by .NET 2.0 - etc.). what do you guys think? are there any benefits in doing any async work if IO is not involved?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684501" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684497</link><pubDate>Fri, 03 Apr 2009 19:36:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684497</guid><dc:creator>Levi</dc:creator><description>&lt;p&gt;All ASP.NET requests begin on a thread pulled from the ThreadPool. &amp;nbsp;WebForms and MVC are not exceptional in this regard. &amp;nbsp;Because of this, you should never call a blocking method from your code. &amp;nbsp;If you do, then using async will actually hurt performance rather than help it because of the overhead involved with processing async requests.&lt;/p&gt;
&lt;p&gt;The trick is that you&amp;#39;re supposed to keep the logic that&amp;#39;s executing on this thread very short. &amp;nbsp;From within your action method, kick off a request to an async operation that uses an I/O completion port for its work. &amp;nbsp;Then the thread servicing the action method returns back to the ThreadPool very quickly, and it&amp;#39;s free to service another request.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684497" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684301</link><pubDate>Thu, 02 Apr 2009 18:52:29 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684301</guid><dc:creator>Israel Aece</dc:creator><description>&lt;p&gt;Hi Luis,&lt;/p&gt;
&lt;p&gt;ASP.NET WebForms uses ThreadPool threads to serve requests. When we have a request that makes a heavy IO task (like databases, web services, etc.), it blocks this thread until finalize the task.&lt;/p&gt;
&lt;p&gt;So, the main benefit of the Async Pages (in WebForms), is that the async process will run in an IO thread, leaving ThreadPool to serve another requests.&lt;/p&gt;
&lt;p&gt;But, in a quickly read in this paper, I saw that AsyncController uses the ThreadPool, not an IO thread.&lt;/p&gt;
&lt;p&gt;Att,&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684301" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684264</link><pubDate>Thu, 02 Apr 2009 17:39:20 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684264</guid><dc:creator>luisabreu</dc:creator><description>&lt;p&gt;hum...not following...can you give more details on what you&amp;#39;re saying?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684264" width="1" height="1"&gt;</description></item><item><title>re: Asynchronous controllers in MVC</title><link>http://msmvps.com/blogs/luisabreu/archive/2009/04/02/asynchronous-controllers-in-mvc.aspx#1684122</link><pubDate>Thu, 02 Apr 2009 11:16:17 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1684122</guid><dc:creator>Israel Aece</dc:creator><description>&lt;p&gt;Hi Luis,&lt;/p&gt;
&lt;p&gt;Nice stuff. But, in a quickly read in this paper, I saw that AsyncController uses the ThreadPool. So, you can combine the controller with Wintellect CallbackThreadPool to use IO Threads.&lt;/p&gt;
&lt;p&gt;Att,&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1684122" width="1" height="1"&gt;</description></item></channel></rss>