<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
> <channel><title>Comments on: Using Copy-On-Write In Multithreaded Code To Reduce Locking Overhead</title> <atom:link href="http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Tue, 22 May 2012 17:40:00 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>By: Markus Tamm &#187; Blog Archive &#187; Links 10.03.2010</title><link>http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/comment-page-1/#comment-31363</link> <dc:creator>Markus Tamm &#187; Blog Archive &#187; Links 10.03.2010</dc:creator> <pubDate>Wed, 10 Mar 2010 08:45:42 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/#comment-31363</guid> <description>[...] Using Copy-On-Write In Multithreaded Code To Reduce Locking Overhead (Davy Brion) [...]</description> <content:encoded><![CDATA[<p>[...] Using Copy-On-Write In Multithreaded Code To Reduce Locking Overhead (Davy Brion) [...]</p> ]]></content:encoded> </item> <item><title>By: Awkward Coder</title><link>http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/comment-page-1/#comment-31288</link> <dc:creator>Awkward Coder</dc:creator> <pubDate>Tue, 09 Mar 2010 16:27:57 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/#comment-31288</guid> <description>that&#039;s what i thought</description> <content:encoded><![CDATA[<p>that&#8217;s what i thought</p> ]]></content:encoded> </item> <item><title>By: Davy Brion</title><link>http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/comment-page-1/#comment-31282</link> <dc:creator>Davy Brion</dc:creator> <pubDate>Tue, 09 Mar 2010 15:12:10 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/#comment-31282</guid> <description>@Akward Coderi think the difference would be minimal... it&#039;s the call to BuildSessionFactory that will take most of the time</description> <content:encoded><![CDATA[<p>@Akward Coder</p><p>i think the difference would be minimal&#8230; it&#8217;s the call to BuildSessionFactory that will take most of the time</p> ]]></content:encoded> </item> <item><title>By: Awkward Coder</title><link>http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/comment-page-1/#comment-31281</link> <dc:creator>Awkward Coder</dc:creator> <pubDate>Tue, 09 Mar 2010 15:09:50 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/#comment-31281</guid> <description>As you stated the lock on the create will be held for a long time because of creating the SessionFactory and I realise reducing the amount of time the lock is held for is not highest priority but couldn&#039;t you move most of the local variable assignment outside of the lock in the create method?I realise there are times when it (create method) will have wasted processor cycles but it reduces the amount of time the lock is held, therefore giving greater parallelism.e.g.private void CreateSessionFactoryForCurrentTenant()
{
var tenantId = tenantContext.CurrentTenantId;
var connectionString = tenantInfoHolder.GetDatabaseConnectionString(tenantId);
var configuration = new Configuration()
.Configure()
.AddProperties(new Dictionary
{
{ &quot;connection.connection_string&quot;, connectionString },
{ &quot;cache.region_prefix&quot;, &quot;Tenant_&quot; + tenantId }
})
.AddAssembly(mappingAssemblyName);lock (writeLock)
{
if (!sessionFactories.ContainsKey(tenantId))
{
var newDictionary = new Dictionary(sessionFactories);
newDictionary[tenantId] = configuration.BuildSessionFactory();;
sessionFactories = newDictionary;
}
}
}</description> <content:encoded><![CDATA[<p>As you stated the lock on the create will be held for a long time because of creating the SessionFactory and I realise reducing the amount of time the lock is held for is not highest priority but couldn&#8217;t you move most of the local variable assignment outside of the lock in the create method?</p><p>I realise there are times when it (create method) will have wasted processor cycles but it reduces the amount of time the lock is held, therefore giving greater parallelism.</p><p>e.g.</p><p> private void CreateSessionFactoryForCurrentTenant()<br
/> {<br
/> var tenantId = tenantContext.CurrentTenantId;<br
/> var connectionString = tenantInfoHolder.GetDatabaseConnectionString(tenantId);</p><p> var configuration = new Configuration()<br
/> .Configure()<br
/> .AddProperties(new Dictionary<br
/> {<br
/> { &#8220;connection.connection_string&#8221;, connectionString },<br
/> { &#8220;cache.region_prefix&#8221;, &#8220;Tenant_&#8221; + tenantId }<br
/> })<br
/> .AddAssembly(mappingAssemblyName);</p><p> lock (writeLock)<br
/> {<br
/> if (!sessionFactories.ContainsKey(tenantId))<br
/> {<br
/> var newDictionary = new Dictionary(sessionFactories);<br
/> newDictionary[tenantId] = configuration.BuildSessionFactory();;<br
/> sessionFactories = newDictionary;<br
/> }<br
/> }<br
/> }</p> ]]></content:encoded> </item> <item><title>By: The Morning Brew - Chris Alcock &#187; The Morning Brew #555</title><link>http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/comment-page-1/#comment-31242</link> <dc:creator>The Morning Brew - Chris Alcock &#187; The Morning Brew #555</dc:creator> <pubDate>Tue, 09 Mar 2010 08:32:01 +0000</pubDate> <guid
isPermaLink="false">http://davybrion.com/blog/2010/03/using-copy-on-write-in-multithreaded-code-to-reduce-locking-overhead/#comment-31242</guid> <description>[...] Using Copy-On-Write In Multi-threaded Code To Reduce Locking Overhead - Davy Brion explores the &#8216;copy on write&#8217; method of making a thread safe collection with lower locking overhead than the traditional lock on read and lock on write approach, discussing some of the more difficult issues with this way of working. [...]</description> <content:encoded><![CDATA[<p>[...] Using Copy-On-Write In Multi-threaded Code To Reduce Locking Overhead &#8211; Davy Brion explores the &#8216;copy on write&#8217; method of making a thread safe collection with lower locking overhead than the traditional lock on read and lock on write approach, discussing some of the more difficult issues with this way of working. [...]</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/13 queries in 0.009 seconds using disk: basic
Object Caching 385/463 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-05-23 02:59:59 -->
