<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - More Advanced ThreadPool</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - More Advanced ThreadPool</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Tue, 21 May 2013 14:53:04 GMT</pubDate>
	<lastBuildDate>Tue, 21 May 2013 14:53:04 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>9</c9:totalResults>
	<c9:pageCount>-9</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p>I started using .NET 2.0 a couple of months ago and I knew I had this problem coming up soon and I was hoping the threadpool was enhanced.&nbsp; It doesn't look like it was.<br /><br />Or, am I wrong and is there a more advanced threadpool or one already well written out there?<br /><br />Basically, I&nbsp;don't want to throw a million items into the threadpool uncontrolled.<br /><br />Here is going to be the flow:<br /><br />1) Pick up all of the unprocessed records in the queue from the database.&nbsp;I'd probably limit it to 10000 or so at a time.<br /><br />2) Limit it to processing 20 or so at a time.<br /><br />3) After they are all completed, go back to the database and get the next 10000.<br /><br />4) If a request comes in to stop, I want it to gracefully shut down and finish the 20 remaining items, rather than calling the join method or whatever it is to stop all threads immediately.<br /><br />The main problem is when you use the .net threadpool and call adduserworkitem it will internally queue up all of the items and there is no way to see how many are completed, or to stop them gracefully.<br /><br />The main thing is I don't want items processing while I perform the call to get the next 1000 records, that is why I want to make sure all are fully completed before going back to step 1.<br /><br />I actually wrote a threadpool manager that did this but it had some problems where it would stop processing.&nbsp; I wanted to see if there is an elegant solution built-in, or anyone had any suggestions.<br /><br />Thanks<br /><br /><br /><br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/256994#256994</link>
		<pubDate>Tue, 14 Aug 2007 17:53:53 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/256994#256994</guid>
		<dc:creator>MetaGunny</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/MetaGunny/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p>I think you would be better off using regular Threads instead of threadpool.&nbsp; Just create 20 Threads and put them in a generic list to manage them.&nbsp;&nbsp;&nbsp; Then you can do whatever you want with the threads.<br /><br />From experience, you can't rely on threadpool if you want pure performance.&nbsp; Thread pool will only do the work if there are resources.&nbsp; The more resources the more threads are running, the less system resources, the less threads are running.&nbsp;&nbsp;
<br /><br />I've seen thread pool go from 100 threads to 2 threads in a matter of minutes and never get back up in number again.&nbsp; With regular threads you are guaranteed that all 100 are running always.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/3746dd428f9b4a6eafa99dfa00af7fb8#3746dd428f9b4a6eafa99dfa00af7fb8</link>
		<pubDate>Tue, 14 Aug 2007 19:07:43 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/3746dd428f9b4a6eafa99dfa00af7fb8#3746dd428f9b4a6eafa99dfa00af7fb8</guid>
		<dc:creator>pathfinder</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/pathfinder/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">pathfinder wrote:</div>
<div class="quoteBody">&#65279;I think you would be better off using regular Threads instead of threadpool.&nbsp; Just create 20 Threads and put them in a generic list to manage them.&nbsp;&nbsp;&nbsp; Then you can do whatever you want with the threads.<br /><br />From experience, you can't rely on threadpool if you want pure performance.&nbsp; Thread pool will only do the work if there are resources.&nbsp; The more resources the more threads are running, the less system resources, the less threads are running.&nbsp;&nbsp;
<br /><br />I've seen thread pool go from 100 threads to 2 threads in a matter of minutes and never get back up in number again.&nbsp; With regular threads you are guaranteed that all 100 are running always.</div>
</blockquote>
<br /><br />Ditto.<br /><br />You are going to have to manually handle the part where you want any busy running threads to complete, anyway.<br /><br />BTW, if your threading code was locking up, you're going to have to figure that part out.&nbsp; Usually, it's when multiple threads are accessing a non-thread-safe object without a lock on that object.<br /><br />If you have questions about it, we might be able to help.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/f56624c7c2da4728ab049dfa00af8040#f56624c7c2da4728ab049dfa00af8040</link>
		<pubDate>Tue, 14 Aug 2007 19:30:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/f56624c7c2da4728ab049dfa00af8040#f56624c7c2da4728ab049dfa00af8040</guid>
		<dc:creator>ScanIAm</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ScanIAm/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">pathfinder wrote:</div>
<div class="quoteBody"><br />I've seen thread pool go from 100 threads to 2 threads in a matter of minutes and never get back up in number again.&nbsp; With regular threads you are guaranteed that all 100 are running always.</div>
</blockquote>
<br /><br />100 running threads is a perf nightmare. Ideally you want the number of running threads to equal the number of logical processors and for those threads never to block. A certain amount of blocking is probably inevitable (unless you write hardcore fiber code)
 so in those cases you want to aim to have just enough threads to keep processor utilisation near 100% .</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/68e348d8c01c4409bd949dfa00af8088#68e348d8c01c4409bd949dfa00af8088</link>
		<pubDate>Tue, 14 Aug 2007 20:10:20 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/68e348d8c01c4409bd949dfa00af8088#68e348d8c01c4409bd949dfa00af8088</guid>
		<dc:creator>AndyC</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/AndyC/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p>Thanks guys.&nbsp; I actually don't remember having any perf problems.&nbsp; I just thought .net 2.0 might have added support for this.<br /><br />The only problem I remember with my old code was the service stopped processing.&nbsp; However, I late found that was a bug in one of the .net classes and I rewrote my service base class using another method for other services and now they never stop.<br /><br />You're right though I'll probably go the threading route rather than the threadpool.&nbsp; I've never had a problem with it dropping but it will be running on a server so that very well could happen.<br /><br />However, when you say logic processes what do you mean?&nbsp; Let's say I have a quad core, is that 4 logical processors?</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/f0cea6e8a9ad493eaea29dfa00af810a#f0cea6e8a9ad493eaea29dfa00af810a</link>
		<pubDate>Tue, 14 Aug 2007 21:34:39 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/f0cea6e8a9ad493eaea29dfa00af810a#f0cea6e8a9ad493eaea29dfa00af810a</guid>
		<dc:creator>MetaGunny</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/MetaGunny/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">MetaGunny wrote:</div>
<div class="quoteBody">However, when you say logic processes what do you mean?&nbsp; Let's say I have a quad core, is that 4 logical processors?</div>
</blockquote>
<br /><br />Yes. To over-simplify: if you have 4 CPU-intensive tasks that don't sleep or block on I/O, aren't being swapped out for other threads,&nbsp;and whose working set fits in the core's cache(s), you stand a better chance of keeping the 4 cores busy. Many real-life tasks
 don't quite fit within those boundaries.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/543719d8fe2441b686a69dfa00af818e#543719d8fe2441b686a69dfa00af818e</link>
		<pubDate>Wed, 15 Aug 2007 02:28:26 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/543719d8fe2441b686a69dfa00af818e#543719d8fe2441b686a69dfa00af818e</guid>
		<dc:creator>amotif</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/amotif/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">amotif wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>MetaGunny wrote:</strong>
<hr size="1">
<i>However, when you say logic processes what do you mean?&nbsp; Let's say I have a quad core, is that 4 logical processors?</i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />Yes. To over-simplify: if you have 4 CPU-intensive tasks that don't sleep or block on I/O, aren't being swapped out for other threads,&nbsp;and whose working set fits in the core's cache(s), you stand a better chance of keeping the 4 cores busy. Many real-life tasks
 don't quite fit within those boundaries.<br /></div>
</blockquote>
<br /><br />This problem isn't really a performance issue though, its more to do with behaviour that the developer wants.&nbsp; He needs 10000 records processed and the performance of that processing really doesn't matter (of course it does, but not for this problem), its the
 ability to stop the operation but let all the threads finish.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/10c216444b35477089089dfa00af821e#10c216444b35477089089dfa00af821e</link>
		<pubDate>Wed, 15 Aug 2007 15:04:50 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/10c216444b35477089089dfa00af821e#10c216444b35477089089dfa00af821e</guid>
		<dc:creator>Soviut</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Soviut/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">Soviut wrote:</div>
<div class="quoteBody">&#65279;<br />This problem isn't really a performance issue though, its more to do with behaviour that the developer wants.&nbsp; He needs 10000 records processed and the performance of that processing really doesn't matter (of course it does, but not for this problem), its the
 ability to stop the operation but let all the threads finish.<br /></div>
</blockquote>
<br /><br />True enough, but creating 100 threads isn't the way to solve it unless they're going to be spending a lot of time blocking. Otherwise you'll just be using all the CPU power performing context switches and never really getting any actual work done.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/29a3f43546454be69ddc9dfa00af826d#29a3f43546454be69ddc9dfa00af826d</link>
		<pubDate>Wed, 15 Aug 2007 15:40:15 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/29a3f43546454be69ddc9dfa00af826d#29a3f43546454be69ddc9dfa00af826d</guid>
		<dc:creator>AndyC</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/AndyC/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - More Advanced ThreadPool</title>
		<description><![CDATA[<p><blockquote>
<div class="quoteAuthor">AndyC wrote:</div>
<div class="quoteBody">&#65279;
<blockquote>
<table class="quoteTable">
<tbody>
<tr>
<td valign="top" width="10"><img src="/Themes/AlmostGlass/images/icon-quote.gif"></td>
<td class="txt3"><strong>Soviut wrote:</strong>
<hr size="1">
<i>&#65279;<br />This problem isn't really a performance issue though, its more to do with behaviour that the developer wants.&nbsp; He needs 10000 records processed and the performance of that processing really doesn't matter (of course it does, but not for this problem), its the
 ability to stop the operation but let all the threads finish.<br /></i></td>
</tr>
</tbody>
</table>
</blockquote>
<br /><br />True enough, but creating 100 threads isn't the way to solve it unless they're going to be spending a lot of time blocking. Otherwise you'll just be using all the CPU power performing context switches and never really getting any actual work done.</div>
</blockquote>
<br /><br />Naturally.&nbsp; But i think the &quot;100 threads&quot; was more of an example and not a suggestion.<br /></p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/3e82137030be4cb8bc199dfa00af82fb#3e82137030be4cb8bc199dfa00af82fb</link>
		<pubDate>Thu, 16 Aug 2007 15:13:31 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/256994-More-Advanced-ThreadPool/3e82137030be4cb8bc199dfa00af82fb#3e82137030be4cb8bc199dfa00af82fb</guid>
		<dc:creator>Soviut</dc:creator>
		<slash:comments>9</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/Soviut/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>