<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>~pperalta</title>
	<atom:link href="http://blackbeanbag.net/wp/feed/" rel="self" type="application/rss+xml" />
	<link>http://blackbeanbag.net/wp</link>
	<description>Thoughts on software development and other stuff</description>
	<lastBuildDate>Fri, 19 Feb 2010 18:28:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>What&#8217;s happening in the world of Coherence?</title>
		<link>http://blackbeanbag.net/wp/2010/02/19/whats-happening-in-the-world-of-coherence/</link>
		<comments>http://blackbeanbag.net/wp/2010/02/19/whats-happening-in-the-world-of-coherence/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 18:28:23 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=395</guid>
		<description><![CDATA[It has been a while since I&#8217;ve posted, so I figured it would be a good time to give an update on what is happening in Coherence land.
New Coherence Bloggers
We have two new bloggers sharing their experiences with Coherence!
The first is by Oracle JDBC expert Pas Apicella who recently took on Coherence.  Upon his [...]]]></description>
			<content:encoded><![CDATA[<p>It has been a while since I&#8217;ve posted, so I figured it would be a good time to give an update on what is happening in Coherence land.</p>
<h3>New Coherence Bloggers</h3>
<p>We have two new bloggers sharing their experiences with Coherence!</p>
<p>The first is by Oracle JDBC expert Pas Apicella who recently took on Coherence.  Upon his introduction to Coherence he immediately proceeded to create a <a href="http://theblasfrompas.blogspot.com/2009/11/oracle-coherence.html">CacheStore example using PL/SQL</a>, followed by an example of using the <a href="http://www.oracle.com/technology/obe/11gr1_db/appdev/dcn/dcn.htm">Oracle JDBC Data Change Notification</a> mechanism to <a href="http://theblasfrompas.blogspot.com/2010/02/using-database-change-notification-dcn.html">push updates from the database to a cache</a>.</p>
<p>Additionally we have Coherence architect Andy Nguyen debuting with a detailed description of a <a href="http://cohfu.wordpress.com/2010/01/06/bulk-loading-a-coherence-cache-from-an-oracle-database/">sophisticated distributed bulk loading technique</a> he&#8217;s employed on several customer projects.</p>
<h3>Coherence Book in March</h3>
<p>After many months of blood, sweat, and blisters from too much typing, <a href="http://coherence.seovic.com/">Aleksandar Seovic</a> has completed the highly anticipated <a href="http://www.packtpub.com/oracle-coherence-3-5/book">Coherence book</a> published by <a href="http://www.packtpub.com">Packt</a>.  Having worked closely with Aleks on reviews and contributions, I believe this book will be a terrific resource for developers and architects that need to write scalable applications.  Both experienced users of Coherence and new users will find relevant and useful content.  Aleks was recently interviewed by Cameron Purdy about the book which can be downloaded as an <a href="http://streaming.oracle.com/ebn/podcasts/media/8458541_Aleksander_Seovic_020310.mp3">MP3</a>.</p>
<h3>User Group Meetings</h3>
<p>The UK SIG in London is the last Coherence user group meeting for the winter, it is coming up on <a href="http://brianoliver.wordpress.com/2010/02/01/london-coherence-sig-winter-edition-26th-february-2010-2/">February 26th</a>.  The spring events are currently being planned; stay tuned for details!</p>
<p>Also coming up on February 24th is the first <a href="http://www.bostonsug.org/">Boston SUG</a> meeting of the year.  Although the topic won&#8217;t be Coherence this time, it will be of interest for developers and architects interested in scalable systems.  We&#8217;ll be meeting up for drinks and snacks at Bertucci&#8217;s afterwards.  And I&#8217;ll be there if anyone wants to chat about Coherence or any other topic!</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2010/02/19/whats-happening-in-the-world-of-coherence/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oracle Open World: The most Coherence content under one roof!</title>
		<link>http://blackbeanbag.net/wp/2009/09/22/oracle-open-world-the-most-coherence-content-under-one-roof/</link>
		<comments>http://blackbeanbag.net/wp/2009/09/22/oracle-open-world-the-most-coherence-content-under-one-roof/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 21:26:49 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=391</guid>
		<description><![CDATA[This year I&#8217;ll be at Oracle Open World for the first time.  I hear that this conference dwarfs JavaOne in size which is hard to imagine given how large JavaOne is.  For those of you attending that are interested in Coherence, we have over two dozen sessions to choose from &#8211; making this [...]]]></description>
			<content:encoded><![CDATA[<p>This year I&#8217;ll be at Oracle Open World for the first time.  I hear that this conference dwarfs JavaOne in size which is hard to imagine given how large JavaOne is.  For those of you attending that are interested in Coherence, we have over two dozen sessions to choose from &#8211; making this the biggest Coherence event ever.</p>
<p>The Coherence content is available on <a href="http://www.oracle.com/technology/products/coherence/coherencedatagrid/coherence_openworld_2009.html">OTN</a>.  (There&#8217;s also a <a href="http://www.oracle.com/technology/products/coherence/pdf/focuson_coherence_openworld-2009.pdf">PDF</a> version that is nicer for printing out.)  It includes sessions on future direction, integration with other products in the Oracle lineup, developer workshops, and customer panels describing their use of Coherence.</p>
<p>I&#8217;ll be talking about <a href="http://www.oracle.com/technology/products/coherence/coherencedatagrid/coherence_openworld_2009.html#coherence-persistence">using Coherence to scale out external data stores</a> (including relational databases.)  This is mostly the same content that will be covered during the <a href="http://blackbeanbag.net/wp/2009/09/17/next-ny-coherence-sig-on-october-1st/">NY SIG</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/09/22/oracle-open-world-the-most-coherence-content-under-one-roof/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Next NY Coherence SIG on October 1st</title>
		<link>http://blackbeanbag.net/wp/2009/09/17/next-ny-coherence-sig-on-october-1st/</link>
		<comments>http://blackbeanbag.net/wp/2009/09/17/next-ny-coherence-sig-on-october-1st/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 12:35:30 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=383</guid>
		<description><![CDATA[The next NY Coherence SIG is on October 1st (two weeks from today) and it promises to be a great event.  For those of you who follow my blog, I previously introduced these two gentlemen a few months ago when they started blogging.  
The first talk will be by Aleksandar Seovic who has [...]]]></description>
			<content:encoded><![CDATA[<p>The next <a href="http://coherence.oracle.com/display/CSIG/1+Oct+2009+-+New+York%2C+NY">NY Coherence SIG</a> is on October 1st (two weeks from today) and it <a href="http://craigblitz.typepad.com/rawpower/2009/09/fall-edition-of-the-new-york-coherence-sig.html">promises to be a great event</a>.  For those of you who follow my blog, I previously <a href="http://blackbeanbag.net/wp/2009/05/27/two-new-coherence-blogs/">introduced these two gentlemen</a> a few months ago when they started blogging.  </p>
<p>The first talk will be by <a href="http://coherence.seovic.com/">Aleksandar Seovic</a> who has an extensive Coherence resume.  In addition to implementing POF in .NET, he is also the author of an upcoming <a href="http://www.packtpub.com/oracle-coherence-3-5/book">book on Coherence</a>.  In his spare time (insert tongue in cheek) he runs <a href="http://www.s4hc.com/">S4HC</a>, a consulting company specializing in Spring, Coherence, and other technologies.  </p>
<p><i>If you&#8217;re in Tampa, you can also check out his <a href="http://www.tampajug.org/wordpress/?p=133">upcoming talk at Tampa JUG</a> on September 29th.</i></p>
<p>We will also have <a href="http://markfalco.wordpress.com/">Mark Falco</a>, one of our rock star engineers who concentrates on our network protocol (TCMP), C++, and other areas.  Mark is usually the first (and last) person I reach out to when I have questions about Coherence networking &#8211; so if you have any questions of your own be sure to bring them.  He will talk to us about TCMP and how to optimize your machines and network for optimum performance.</p>
<p>Finally, yours truly will talk about configuring Coherence to work with an external data source (usually relational databases.)  I&#8217;ll describe in detail how each of the external connectivity features work (including many features you&#8217;ve probably never heard of), best practices, and good old fashioned war stories.  (Shout out to <a href="http://calmerthanur.wordpress.com/">Rob</a> for helping with the Omni Graffle diagrams!)  This is the same talk that I will present in mid October at <a href="http://www.oracle.com/openworld/index.html">Oracle Open World</a> in San Francisco.  I&#8217;ll provide more detail on this later; for now you can check out the <a href="http://www.oracle.com/technology/products/coherence/pdf/focuson_appgrid_openworld_2009.pdf">Application Grid</a> lineup &#8211; which includes WebLogic Server, Coherence, JRockit, Tuxedo and Enterprise Manager.</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/09/17/next-ny-coherence-sig-on-october-1st/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NFJS Boston Day 3</title>
		<link>http://blackbeanbag.net/wp/2009/09/16/nfjs-boston-day-3/</link>
		<comments>http://blackbeanbag.net/wp/2009/09/16/nfjs-boston-day-3/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 23:03:26 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=362</guid>
		<description><![CDATA[Coverage of the last day of No Fluff Just Stuff (albeit a few days late):
Spring DM and OSGi
Craig Walls provided an extensive overview (and defense) of OSGi.  OSGi is a framework for managing library dependencies.  It enables the installation, configuration, and updating of modules in a live program without JVM restarts.  Multiple [...]]]></description>
			<content:encoded><![CDATA[<p>Coverage of the last day of <a href="http://www.nofluffjuststuff.com/conference/boston/2009/09/home">No Fluff Just Stuff</a> (albeit a few days late):</p>
<h3>Spring DM and OSGi</h3>
<p>Craig Walls provided an extensive overview (and defense) of OSGi.  OSGi is a framework for managing library dependencies.  It enables the installation, configuration, and updating of modules in a live program without JVM restarts.  Multiple versions of a class and/or libraries can coexist in a container.  Each module has a defined lifecycle and dependencies between modules can be defined.</p>
<p>Here is a list of OSGi implementations:</p>
<h4>Open Source</h4>
<ul>
<li><a href="http://www.eclipse.org/equinox">Eclipse Equinox</a>
<li><a href="http://felix.apache.org">Apache Felix</a>
<li><a href="http://www.knopﬂerﬁsh.org">Knopﬂerﬁsh</a>
<li><a href="http://concierge.sourceforge.net/">Concierge</a>
</ul>
<h4>Commercial</h4>
<ul>
<li><a href="http://www.makewave.com">Makewave Knopﬂerﬁsh Pro</a>
<li><a href="http://www.prosyst.com">ProSyst mBedded Server</a>
<li>Samsung OSGi R4 Solution
<li>HitachiSoft SuperJ Engine Framework
</ul>
<p>Craig provided a live demonstration of the <a href="http://wiki.ops4j.org/display/ops4j/Pax+Shell">OPS4J Pax shell</a> running under Eclipse Equinox and Apache Felix.  Unfortunately we ran out of time and we didn&#8217;t get to see much of the Spring DM server in action.</p>
<h3>java.next</h3>
<p>Stuart Halloway gave an overview of the latest and greatest languages available for the JVM.  Like some of the other NFJS speakers he has very strong opinions, especially when it comes to the use of Java.  I believe the quote was something along the lines of &#8220;every time you start a greenfield project with Java, God kills a kitten.&#8221;  (Incidentally, Ted Neward believes that using Java arrays instead of collections will lead to the same fate for said kitten.)</p>
<p>Straight from Stuart&#8217;s slides: pros and cons for your consideration:</p>
<h4>Clojure Pros</h4>
<ul>
<li>Functional
<li>Multimethods
<li>Concurrency
<li>Lisp
<li>A la carte
</ul>
<h4>Clojure Cons</h4>
<ul>
<li>Youngest java.next language
</ul>
<h4>Groovy Pros</h4>
<ul>
<li>Easiest to learn
<li>Easiest bi-di interop
<li>More committed to reusing Java libs
</ul>
<h4>Groovy Cons</h4>
<ul>
<li>Worst Java baggage
<li>No concurrency/multicore story
</ul>
<h4>JRuby Pros</h4>
<ul>
<li>Biggest community
<li>Commercial support: EngineYard
<li>Rails
<li>multiple platforms
</ul>
<h4>JRuby Cons</h4>
<ul>
<li>No concurrency/multicore story
</ul>
<h4>Scala Pros</h4>
<ul>
<li>Functional
<li>High performance
<li>Pattern matching
<li>Actor model
<li>Hybrid object/functional (could also be a con)
</ul>
<h4>Scala Cons</h4>
<ul>
<li>Hardest to learn
</ul>
<p>The general theme on these new generation languages is:</p>
<ul>
<li>Dynamic typing (Scala is not as dynamic as the others, but offers more flexibility than Java)
<li>No checked exceptions
<li>Reasonable defaults
<li>Convention over configuration
<li><a href="http://en.wikipedia.org/wiki/YAGNI">YAGNI</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/09/16/nfjs-boston-day-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NFJS Boston Day 2</title>
		<link>http://blackbeanbag.net/wp/2009/09/12/nfjs-boston-day-2/</link>
		<comments>http://blackbeanbag.net/wp/2009/09/12/nfjs-boston-day-2/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 02:25:03 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=349</guid>
		<description><![CDATA[Here are my highlights of No Fluff Just Stuff Day 2:
Garbage Collector Friendly Programming
Garbage collection is an interesting topic to me for several reasons, the main reason being that poor GC performance is very harmful in distributed environments.  When you have a peer to peer system such as Coherence, any one node can directly [...]]]></description>
			<content:encoded><![CDATA[<p>Here are my highlights of <a href="http://www.nofluffjuststuff.com/conference/boston/2009/09/home">No Fluff Just Stuff</a> Day 2:</p>
<h3>Garbage Collector Friendly Programming</h3>
<p>Garbage collection is an interesting topic to me for several reasons, the main reason being that poor GC performance is very harmful in distributed environments.  When you have a peer to peer system such as Coherence, any one node can directly communicate with any other node at any point in time to service a request.  If a node that needs to service several requests is in a long GC pause, it isn&#8217;t just that node that is affected.  Every JVM that is waiting for a response from that node also experiences high latency, thus causing a cascading effect.  (More on what to do about this later.)</p>
<p>Brian Goetz described the evolution of GC in Java, starting with the single threaded mark and sweep algorithms up to the modern generational collector.         What they each have in common is the tracking of allocation roots (which include static variables and local variables allocated on thread stacks) and the traversal of object references starting at these roots.  The implementation of the generational collector is (roughly) as follows:</p>
<ul>
<li>New objects are allocated in the young generation space
<li>When a minor GC occurs, objects that have references pointing to them are copied to the survival space.  The remaining objects are removed
<li>Eventually objects that live long enough in the survival space are moved to the old generation.
<li>If a minor collection fails to free up enough space in the young generation  area, a full collection (which is much more expensive) will occur in the old generation space.
</ul>
<p>An implementation detail is that the JVM must track references from the old generation to the young generation in order to know which GC roots to traverse when performing a minor collection.  This means that the more &#8220;old&#8221; objects there are pointing to &#8220;new&#8221; objects, the more work the collector has to do.  In a practical sense, this means that allocating new objects is preferred to reference field updates.</p>
<p>It took a while to wrap my head around that last statement, so let me attempt to demonstrate.  Let&#8217;s say I have a map that contains objects with many fields.  If I wanted to update some of those fields I could do it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Map</span> map <span style="color: #339933;">=</span> ...
<span style="color: #006633;">MyObject</span> o <span style="color: #339933;">=</span> map.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
o.<span style="color: #006633;">setField1</span><span style="color: #009900;">&#40;</span>f1<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
o.<span style="color: #006633;">setField3</span><span style="color: #009900;">&#40;</span>f3<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
o.<span style="color: #006633;">setField5</span><span style="color: #009900;">&#40;</span>f5<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Or I could do it like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Map</span> map <span style="color: #339933;">=</span> ...
<span style="color: #006633;">MyObject</span> oOld <span style="color: #339933;">=</span> map.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>key<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
MyObject oNew <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MyObject<span style="color: #009900;">&#40;</span>f1, o.<span style="color: #006633;">getField2</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, f3, o.<span style="color: #006633;">getField4</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, f5<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>key, oNew<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first example updates three reference fields (assuming the object in the map is in the old generation), whereas the second is updating one (the reference held by Map.Entry) &#8211; and as an added bonus the second implementation is thread safe (assuming that MyObject is immutable and the Map implementation is also thread safe.)  If anyone has a better (or more correct) example of this concept, I&#8217;d be happy to see it!</p>
<p>Many other concepts were covered including: why you should use <i>finally</i> instead of finalizers to clean up, weak references, soft references, and tracking down memory leaks.  Capturing heap dumps to track memory usage is a technique I recommend to customers (this works much better than speculating/wild guesses about where unexpected memory allocation is coming from) &#8211; I especially recommend configuring the JVM to generate a heap dump when an OutOfMemoryError is thrown.  My favorite tool to read heap dumps is <a href="http://www.eclipse.org/mat/">Eclipse MAT</a>.  Heap histograms are also a nice light weight approach to analyze memory problems.</p>
<p>When customers ask for suggestions on GC tuning, my recommendation is to keep it simple: fixed size 1 GB heaps (on the Sun VM), and don&#8217;t use more than 75% of the heap.  I usually don&#8217;t recommend any specific tuning parameters, as the GC algorithms are constantly improving and any exotic flags that may have worked in older JVMs (assuming they helped in the first place) may not work so well in newer JVMs.  The best advice I can give is to not fill up the heap as this will cause more frequent full collections.</p>
<h3>Inside the Modern JVM</h3>
<p>NFJS tends to cover languages in the JVM other than Java (such as Groovy, Scala, JRuby, etc.)  This is a testament to the strength and viability of the modern JVM.  Brian covered some of the advancements and (quite frankly) rocket science that goes into the JVM, HotSpot in particular.  No matter what happens to Java (which isn&#8217;t going away any time soon), the JVM will be around for a very long time.</p>
<p>In a nutshell: why is Java, a supposedly interpreted language, faster than C++ in many cases?  The answer is that the JVM determines which optimizations to make at run time instead of compile time, which is the opposite approach of C++ and other native languages.  Optimization at runtime is far more effective, since the JVM has hard statistics of real world usage to draw on as opposed to the speculation and guessing that happens when everything has to be compiled to machine code before execution.</p>
<p>The overall theme of this talk (and the previous ones) is to write simple clean code &#8211; the runtime recognizes common usage patterns in Java and is built to optimize these patterns.</p>
<h3>Java Collections</h3>
<p>Ted Neward gave an engaging and entertaining talk on the Java Collections API.  To be honest I was familiar with most of the material, but he is a fun speaker to watch, in spite of the fact that he gave me a good ribbing for showing up to his talk after it had already started!  He is quite biased against arrays and towards collections, which made me think back to a web/remote services API I designed a few years ago.  I exclusively used arrays as the collection type for this API for two reasons:</p>
<ol>
<li>To make SOAP/cross language interoperability much simpler (least common denominator &#8211; every language does arrays)
<li>There were no generics at the time; using arrays instead of generics in the interfaces meant that I could explicitly define the type of the array
</ol>
<p>The second item is not as important anymore now that we have generics, so I&#8217;m inclined to agree that arrays should be used sparingly nowadays.  </p>
<p>Another interesting point is that iteration over collections should be done using a <a href="http://en.wikipedia.org/wiki/Functor">functor</a> instead of a plain iterator.  For example:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">List<span style="color: #339933;">&lt;</span>Name<span style="color: #339933;">&gt;</span> names <span style="color: #339933;">=</span> ...<span style="color: #339933;">;</span> 
MyListOps.<span style="color: #006633;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MyApplyFn<span style="color: #339933;">&lt;</span>Name<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> apply<span style="color: #009900;">&#40;</span><span style="color: #003399;">Name</span> n<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
    <span style="color: #666666; font-style: italic;">// use n </span>
  <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span>, names<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This allows the possibility of processing the collection in multiple threads.</p>
<h3>What&#8217;s coming in Java 7</h3>
<p>This was Ted Neward&#8217;s next talk which was just as interesting and opinionated.  Here are the highlights:</p>
<ul>
<li>The release is targeted for early 2010
<li>There is no official JSR for Java 7
<li>Most of the information on what is going into Java 7 can be found on the blog of <a href="http://blogs.sun.com/darcy/date/20090828">Joe Darcy of Sun</a>.
<li><a href="http://tech.puredanger.com/java7/">Alex Miller</a> has a <i>huge</i> page on his blog detailing what is in and what is out.  This is information that is is aggregating off the web.
</ul>
<p>One of the most compelling additions to Java 7 is <a href="http://jcp.org/en/jsr/detail?id=292">JSR 292</a>, which introduces the bytecode <i>invokedynamic</i>.  The implications of this addition are narrated by <a href="http://blog.headius.com/2008/09/first-taste-of-invokedynamic.html">Charles Nutter</a> of JRuby.  There are other syntactic conveniences making it in; however it will not include closures (a fairly controversial topic.)</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/09/12/nfjs-boston-day-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>NFJS Boston Day 1</title>
		<link>http://blackbeanbag.net/wp/2009/09/12/nfjs-boston-day-1/</link>
		<comments>http://blackbeanbag.net/wp/2009/09/12/nfjs-boston-day-1/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 16:12:08 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=322</guid>
		<description><![CDATA[Yesterday was day 1 of No Fluff Just Stuff in Boston.  Here is a highlight of the sessions I attended.
JSF 2.0
David Geary presented an overview of JSF 2.0.  The reference implementation is known as Project Mojarra which falls under the GlassFish family.  The current reference implementation as well as the 2.0 RC [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday was day 1 of <a href="http://www.nofluffjuststuff.com/conference/boston/2009/09/home">No Fluff Just Stuff in Boston</a>.  Here is a highlight of the sessions I attended.</p>
<h3>JSF 2.0</h3>
<p>David Geary presented an overview of JSF 2.0.  The reference implementation is known as <a href="https://javaserverfaces.dev.java.net/">Project Mojarra</a> which falls under the GlassFish family.  The current reference implementation as well as the 2.0 RC can be downloaded from the <a href="https://javaserverfaces.dev.java.net/">project site</a>.</p>
<p>Here are the highlights of what is new:</p>
<ul>
<li>Facelets (templated XHTML with an expression language) instead of JSP
<li>Annotations and convention instead of XML for configuration
<li>Bookmark friendly views
<li>Improved error messages
<li>Richer event model
<li>Ajax integration
</ul>
<p>I personally don&#8217;t do any web development, however I was interested in this topic as some of our Coherence*Web customers do use JSF.</p>
<h3>The Java Memory Model</h3>
<p>The first time I heard about the JMM was during my interview with Tangosol which incidentally occurred almost three years ago to the day.  It isn&#8217;t often that you learn so much at a job interview.  This was a clear indication that a job at Tangosol would result in me learning many new things from people much smarter than me.  Consequently, many of the items covered during this talk I had at least passing familiarity with.  However I was glad to see that Brian Goetz is as clear of a speaker as he is a writer &#8211; which is a real treat.  The ability to transfer knowledge on complex topics not well understood by most people in the industry in such a straightforward manner is not something to be taken for granted. </p>
<p>I&#8217;ll try to provide a succinct 60 second overview of the JMM and why it matters if you&#8217;re a Java developer.  It can be boiled down to a simple question:</p>
<p>If you assign a variable as such in thread A:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span></pre></div></div>

<p>Under which circumstances will the following evaluate to <i>true</i> in thread B?</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">x <span style="color: #339933;">==</span> <span style="color: #cc66cc;">5</span></pre></div></div>

<p>If the write and read of variable x is done outside of a synchronization block or if x is not declared as volatile, then there is no guarantee that thread B will see the updated value.  Straight from the slide deck:</p>
<ul>
<li>The memory effects of one thread may not be immediately visible to other threads
<li>Modern microprocessors exhibit a higher level of asynchronous and nondeterministic behavior than &#8220;when we were kids&#8221;
<li>Compilers may reorder instructions (if permitted by language semantics) to achieve higher performance
</ul>
<p>In a nutshell, modern multi processor and multi core machines perform aggressive caching to improve performance, at the cost of non deterministic behavior as described above.  Therefore, any time variables are shared between threads, not only do you have to worry about ensuring that threads don&#8217;t step over each other (causing data corruption), but you also have to make sure that the updated value is visible to all threads.</p>
<p>Therefore the <i>synchronized</i> keyword actually performs double duty: it defines boundaries for critical sections, and it also ensures that variables written are immediately visible to all threads.  The <i>volatile</i> keyword indicates that a variable should not be cached &#8211; its value will be immediately visible to all threads whenever it is updated.</p>
<p>These IBM developerWorks articles describe the JMM in much greater detail:<br />
<a href="http://www.ibm.com/developerworks/java/library/j-jtp02244.html">Fixing the Java Memory Model, Part 1</a><br />
<a href="http://www.ibm.com/developerworks/java/library/j-jtp03304/">Fixing the Java Memory Model, Part 2</a></p>
<h3>Are All Web Applications Broken?</h3>
<p>This talk builds upon the previous JMM talk and looks at a practical example of where this knowledge becomes important: web applications.  Some web applications (i.e. servlets or web frameworks that run on servlets) are stateless, at least at the web tier.  Many use the database for state, in which case the database is handling concurrency.</p>
<p>However, some web applications do track state internally, either as a member variable in the servlet (uncommon) or in the SessionContext (more common.)  In this case it is definitely up to the developer to handle concurrency correctly, keeping in mind the lessons of the JMM.</p>
<p>The more subtle (and common) pitfall is in handling HttpSession objects.  The common assumption is that access to a session object does not necessarily need to be thread safe since each session is scoped to a specific user who will presumably make one request at a time.  However this assumption does not hold true in (at least) the following cases:</p>
<ul>
<li>Your app uses frames
<li>Your app uses Ajax
<li>Your app is a portlet
<li>Your user has an itchy trigger finger and likes to triple click on links
</ul>
<p>In these cases, you can easily have multiple threads accessing a session.  Setting and getting attributes in a session is likely thread safe, but there&#8217;s no guarantee that the objects in the session themselves are thread safe.  This is especially evident when distributing sessions, as this requires the container to serialize session attributes.  Best practice for objects in a session are as follows:</p>
<ul>
<li>Use immutable variables (may have to combine with atomic operations via <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/atomic/AtomicReference.html">AtomicReference</a> if there are check-then-act or read-modify-write actions.)
<li>Use thread safe objects (i.e. <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/concurrent/ConcurrentHashMap.html">ConcurrentHashMap</a> vs <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/util/HashMap.html">HashMap</a>)
<li><i>Don&#8217;t put plain JavaBeans in a session!</i>
</ul>
<p>For more, see the <a href="http://www.ibm.com/developerworks/library/j-jtp09238.html">IBM developerWorks article</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/09/12/nfjs-boston-day-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get an OutOfMemoryError without trying</title>
		<link>http://blackbeanbag.net/wp/2009/08/10/how-to-get-an-outofmemoryerror-without-trying/</link>
		<comments>http://blackbeanbag.net/wp/2009/08/10/how-to-get-an-outofmemoryerror-without-trying/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 14:16:41 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=312</guid>
		<description><![CDATA[In the past few months, I&#8217;ve seen customers run into mysterious OutOfMemoryErrors that seem to come out of nowhere.  For the most part their apps are working fine, then out of the blue the heap blows up, and it is never reproducible.  In each case, the culprit turned out to be something like [...]]]></description>
			<content:encoded><![CDATA[<p>In the past few months, I&#8217;ve seen customers run into mysterious OutOfMemoryErrors that seem to come out of nowhere.  For the most part their apps are working fine, then out of the blue the heap blows up, and it is never reproducible.  In each case, the culprit turned out to be something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> asArgs<span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span>    nCount <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span>    nRange <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Map</span>    map    <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">HashMap</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Random</span> random <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Runnable</span> r <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Runnable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                <span style="color: #000066; font-weight: bold;">int</span> nKey <span style="color: #339933;">=</span> random.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span>nRange<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>random.<span style="color: #006633;">nextBoolean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                    map.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>nKey, <span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                    <span style="color: #009900;">&#123;</span>
                    map.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">Thread</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> threads <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#91;</span>nCount<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Starting &quot;</span> <span style="color: #339933;">+</span> nCount <span style="color: #339933;">+</span>
            <span style="color: #0000ff;">&quot; threads, range = &quot;</span> <span style="color: #339933;">+</span> nRange<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> threads.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        threads<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Thread</span><span style="color: #009900;">&#40;</span>r, <span style="color: #0000ff;">&quot;Thread &quot;</span> <span style="color: #339933;">+</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        threads<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>See the bug?  The problem here is with multiple threads using a java.util.HashMap in the absence of synchronization.  One would imagine that at worst this usage would result in inaccurate data in the map.  However, this turns out not to be the case.</p>
<p>Running under Java 1.5 in OS X, this runs for a few seconds before it gets stuck in an infinite loop (evidenced by the CPU spiking to 100%):</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">&quot;Thread 4&quot; prio=5 tid=0x0100c350 nid=0x853000 runnable [0xb0e8e000..0xb0e8ed90]
        at java.util.HashMap.put(HashMap.java:420)
        at com.tangosol.examples.misc.HashMapTest$1.run(HashMapTest.java:30)
        at java.lang.Thread.run(Thread.java:613)
&nbsp;
&quot;Thread 3&quot; prio=5 tid=0x0100bde0 nid=0x852200 runnable [0xb0e0d000..0xb0e0dd90]
        at java.util.HashMap.removeEntryForKey(HashMap.java:614)
        at java.util.HashMap.remove(HashMap.java:584)
        at com.tangosol.examples.misc.HashMapTest$1.run(HashMapTest.java:34)
        at java.lang.Thread.run(Thread.java:613)
&nbsp;
&quot;Thread 2&quot; prio=5 tid=0x0100ba20 nid=0x851200 runnable [0xb0d8c000..0xb0d8cd90]
        at java.util.HashMap.removeEntryForKey(HashMap.java:614)
        at java.util.HashMap.remove(HashMap.java:584)
        at com.tangosol.examples.misc.HashMapTest$1.run(HashMapTest.java:34)
        at java.lang.Thread.run(Thread.java:613)
&nbsp;
&quot;Thread 1&quot; prio=5 tid=0x0100b610 nid=0x850400 runnable [0xb0d0b000..0xb0d0bd90]
        at java.util.HashMap.removeEntryForKey(HashMap.java:614)
        at java.util.HashMap.remove(HashMap.java:584)
        at com.tangosol.examples.misc.HashMapTest$1.run(HashMapTest.java:34)
        at java.lang.Thread.run(Thread.java:613)
&nbsp;
&quot;Thread 0&quot; prio=5 tid=0x0100b430 nid=0x84f600 runnable [0xb0c8a000..0xb0c8ad90]
        at java.util.HashMap.removeEntryForKey(HashMap.java:614)
        at java.util.HashMap.remove(HashMap.java:584)
        at com.tangosol.examples.misc.HashMapTest$1.run(HashMapTest.java:34)
        at java.lang.Thread.run(Thread.java:613)</pre></div></div>

<p>Under 1.6, it runs for about a minute before I get:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">java.lang.OutOfMemoryError: Java heap space
        at java.util.HashMap.resize(HashMap.java:462)
        at java.util.HashMap.addEntry(HashMap.java:755)
        at java.util.HashMap.put(HashMap.java:385)
        at com.tangosol.examples.misc.HashMapTest$1.run(HashMapTest.java:30)
        at java.lang.Thread.run(Thread.java:637)</pre></div></div>

<p>I configured the VM to generate a heap dump upon OutOfMemoryError.  Here are some screenshots from Eclipse MAT:</p>
<p><img src="http://blackbeanbag.net/wp/wp-content/uploads/2009/08/Picture-5.png" alt="MAT 1" title="MAT 1" width="688" height="181" class="aligncenter size-full wp-image-313" />            </p>
<p><img src="http://blackbeanbag.net/wp/wp-content/uploads/2009/08/Picture-6.png" alt="MAT 2" title="MAT 2" width="642" height="239" class="aligncenter size-full wp-image-314" /></p>
<p>Both of these behaviors can be explained by race conditions that corrupt the HashMap internal data structures causing infinite loops, the latter case resulting in an OOME.  This behavior is described in this <a href="http://stackoverflow.com/questions/1068190/why-does-executorservice-deadlock-when-performing-hashmap-operations">Stack Overflow thread</a>, which links to this <a href="http://mailinator.blogspot.com/2009/06/beautiful-race-condition.html">blog post</a> describing one of the possible race conditions in detail.</p>
<p>The lessons to be learned here are:</p>
<ul>
<li>When using non thread safe data structures, make sure that only one thread will access them at a time, or switch to a thread safe data structure.</li>
<li>Configure JVMs in production to generate a heap dump upon an OutOfMemoryError (this has helped us track down various OOMEs for customers), and consider configuring the JVM to shut down if this error is thrown.  The <a href="http://coherence.oracle.com/display/COH34UG/Production+Checklist#ProductionChecklist-JVM">Coherence production checklist</a> provides information on how to configure these settings on various JVMs.</li>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/08/10/how-to-get-an-outofmemoryerror-without-trying/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Coherence 3.5: POF Extractor/Updater</title>
		<link>http://blackbeanbag.net/wp/2009/07/21/coherence-3-5-pof-extractorupdater/</link>
		<comments>http://blackbeanbag.net/wp/2009/07/21/coherence-3-5-pof-extractorupdater/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 14:59:45 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=287</guid>
		<description><![CDATA[This article is part 3 of a 3 part series on my favorite new features in Coherence 3.5.
Ever since Coherence added support for .NET (and more recently C++, which can be implied when discussing .NET below) clients, we&#8217;ve always been asked this question:

When do I have to provide both .NET and Java implementations of my [...]]]></description>
			<content:encoded><![CDATA[<p><i>This article is part 3 of a 3 part series on my <a href="/wp/2009/07/20/my-favorite-new-features-in-coherence-3-5/">favorite new features in Coherence 3.5.</a></i></p>
<p>Ever since Coherence added support for .NET (and more recently C++, which can be implied when discussing .NET below) clients, we&#8217;ve always been asked this question:</p>
<blockquote><p>
<i>When do I have to provide both .NET and Java implementations of my classes?</i>
</p></blockquote>
<p>With each new release of Coherence, it becomes less of a requirement  to provide .NET and Java implementations of cache objects.  Here is a timeline of the evolution of multi language support:</p>
<h3>Coherence 3.2/3.3</h3>
<p>Support for .NET clients.  .NET objects are serialized into a platform neutral serialization format (POF) and sent over TCP to a proxy server.  The proxy server deserializes these objects and serializes them into Java format before sending into the grid for storage, thus the requirement for .NET and Java versions of each type.</p>
<h3>Coherence 3.4</h3>
<p>Support for .NET and C++ clients.  Grid is enhanced to allow for POF binaries to be stored natively in the grid, thus removing the deserialization/serialization step previously required in the proxy servers.  .NET and Java versions of cached objects are required for:</p>
<ul>
<li>Entry processors
<li>Queries
<li>Cache Store
<li>Key association
</ul>
<p>For applications with .NET clients that only do puts and gets, there is no need for Java versions of their objects in the grid.</p>
<h3>Coherence 3.5</h3>
<p>New in 3.5 is the ability for cache servers to extract and update data in POF binaries without deserializing the binary into an object.  This is done via <a href="http://coherence.oracle.com/display/COH35UG/PofExtractors+and+PofUpdaters">PofExtractors and PofUpdaters</a>.   A <a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/util/extractor/PofExtractor.html">PofExtractor</a> is an implementation of <a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/util/ValueExtractor.html">ValueExtractor</a>, which is an interface that defines how to extract data from objects.  The most common extractor in use today is <a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/util/extractor/ReflectionExtractor.html">ReflectionExtractor</a>, which simply means that the provided method will be invoked on the target object, and the result from that method is returned.</p>
<p>This means that operations that rely on extractors (such as queries and some entry processors) can now be executed on the server side without needing Java classes to represent the data types.</p>
<p>Here is an example.  Let&#8217;s say you have the following type (I wrote it in Java, but this could also be done in .NET)</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Person
        <span style="color: #000000; font-weight: bold;">implements</span> PortableObject
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> Person<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> Person<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> sFirstName, <span style="color: #003399;">String</span> sLastName, <span style="color: #003399;">String</span> sEmail<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        m_sFirstName <span style="color: #339933;">=</span> sFirstName<span style="color: #339933;">;</span>
        m_sLastName <span style="color: #339933;">=</span> sLastName<span style="color: #339933;">;</span>
        m_sEmail <span style="color: #339933;">=</span> sEmail<span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// getters and setters omitted.. </span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> readExternal<span style="color: #009900;">&#40;</span>PofReader in<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
        <span style="color: #009900;">&#123;</span>
        m_sFirstName <span style="color: #339933;">=</span> in.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span>FIRST_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        m_sLastName  <span style="color: #339933;">=</span> in.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span>LAST_NAME<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        m_sEmail     <span style="color: #339933;">=</span> in.<span style="color: #006633;">readString</span><span style="color: #009900;">&#40;</span>EMAIL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> writeExternal<span style="color: #009900;">&#40;</span>PofWriter out<span style="color: #009900;">&#41;</span>
            <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
        <span style="color: #009900;">&#123;</span>
        out.<span style="color: #006633;">writeString</span><span style="color: #009900;">&#40;</span>FIRST_NAME, m_sFirstName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out.<span style="color: #006633;">writeString</span><span style="color: #009900;">&#40;</span>LAST_NAME, m_sLastName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        out.<span style="color: #006633;">writeString</span><span style="color: #009900;">&#40;</span>EMAIL, m_sEmail<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> m_sFirstName<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> m_sLastName<span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">String</span> m_sEmail<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> FIRST_NAME <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> LAST_NAME  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000066; font-weight: bold;">int</span> EMAIL      <span style="color: #339933;">=</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now for some sample code on executing a query:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">NamedCache pofCache <span style="color: #339933;">=</span> CacheFactory.<span style="color: #006633;">getCache</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;pof&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// These names are fictitious: any resemblence to real people</span>
<span style="color: #666666; font-style: italic;">// is coincidental!</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Bob&quot;</span>, <span style="color: #0000ff;">&quot;Smith&quot;</span>, <span style="color: #0000ff;">&quot;bob.smith@google.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">2</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Jane&quot;</span>, <span style="color: #0000ff;">&quot;Doe&quot;</span>, <span style="color: #0000ff;">&quot;jane.doe@yahoo.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fred&quot;</span>, <span style="color: #0000ff;">&quot;James&quot;</span>, <span style="color: #0000ff;">&quot;fred.james@oracle.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Amy&quot;</span>, <span style="color: #0000ff;">&quot;Jones&quot;</span>, <span style="color: #0000ff;">&quot;amy.jones@oracle.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pofCache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span>, <span style="color: #000000; font-weight: bold;">new</span> Person<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ted&quot;</span>, <span style="color: #0000ff;">&quot;Black&quot;</span>, <span style="color: #0000ff;">&quot;ted.black@google.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Query for oracle.com addresses</span>
<span style="color: #003399;">Set</span> keys <span style="color: #339933;">=</span> pofCache.<span style="color: #006633;">keySet</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> LikeFilter<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> PofExtractor<span style="color: #009900;">&#40;</span>Person.<span style="color: #006633;">EMAIL</span><span style="color: #009900;">&#41;</span>, 
        <span style="color: #0000ff;">&quot;%@oracle.com&quot;</span>, <span style="color: #0000ff;">'<span style="color: #000099; font-weight: bold;">\\</span>'</span>, <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">assert</span> keys.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> keys.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">assert</span> keys.<span style="color: #006633;">contains</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The cache configuration (note the system-property override in the serializer config; this comes into play later):</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
&nbsp;
<span style="color: #00bbdd;">&lt;!DOCTYPE cache-config SYSTEM &quot;cache-config.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;caching-scheme-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cache-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pof<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pof<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/caching-scheme-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;caching-schemes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;distributed-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>pof<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scheme-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;serializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.tangosol.io.pof.ConfigurablePofContext<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>string<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value</span> <span style="color: #000066;">system-property</span>=<span style="color: #ff0000;">&quot;pof.config&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>pof-config.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
          <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-params<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/serializer<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;service-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>PofDistributedService<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/service-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;backing-map-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;local-scheme</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/backing-map-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;autostart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/autostart<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/distributed-scheme<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/caching-schemes<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cache-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>And, the POF configuration on the client:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE pof-config SYSTEM &quot;pof-config.dtd&quot;&gt;</span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pof-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user-type-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>coherence-pof-config.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/include<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;type-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>10001<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/type-id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.tangosol.examples.pof.Person<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user-type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/user-type-list<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pof-config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>To run this, I set up a cache server without adding any extra classes to the classpath.  I only provided the above cache configuration, and I supplied the following to the command line:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">-Dpof.config=coherence-pof-config.xml</pre></div></div>

<p>Why did I do this?  This is because the server side does not need to know about the client&#8217;s POF configuration since it does not need to deserialize the objects.  Therefore I&#8217;m simply supplying the default cache configuration that ships with Coherence.</p>
<p>Given the addition of this new feature, we can modify the list from 3.4 as such:</p>
<ul>
<li><s>Entry processors</s>
<li><s>Queries</s>
<li>Cache Store
<li>Key association
</ul>
<p>To summarize, the introduction of POF extractors and updaters means that .NET clients only need Java implementations of their respective classes when performing <a href="http://coherence.oracle.com/display/COH35UG/Read-Through%2C+Write-Through%2C+Write-Behind+and+Refresh-Ahead+Caching">CacheStore</a> operations and/or <a href="http://coherence.oracle.com/display/COH35UG/Data+Affinity">key association</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/07/21/coherence-3-5-pof-extractorupdater/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Coherence 3.5: Service Guardian (Deadlock Detection)</title>
		<link>http://blackbeanbag.net/wp/2009/07/20/coherence-3-5-service-guardian-deadlock-detection/</link>
		<comments>http://blackbeanbag.net/wp/2009/07/20/coherence-3-5-service-guardian-deadlock-detection/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 01:49:08 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=258</guid>
		<description><![CDATA[This article is part 2 of a 3 part series on my favorite new features in Coherence 3.5.
One of the great benefits of using a modern JVM is deadlock detection.   At my previous job I remember helping to track down an intermittent issue with our Swing desktop client that was eventually solved by [...]]]></description>
			<content:encoded><![CDATA[<p><i>This article is part 2 of a 3 part series on my <a href="/wp/2009/07/20/my-favorite-new-features-in-coherence-3-5/">favorite new features in Coherence 3.5.</a></i></p>
<p>One of the great benefits of using a modern JVM is deadlock detection.   At my previous job I remember helping to track down an intermittent issue with our Swing desktop client that was eventually solved by providing instructions to our support/QA staff on how to generate a thread dump when the issue surfaced (which is much harder on Windows than on Unix/Linux based OSes.)  Once they sent us the thread dump (which so conveniently printed the threads that were deadlocked at the bottom), fixing the issue was trivial.</p>
<p>Deadlocks can and do happen in distributed systems, and unfortunately there isn&#8217;t a good mechanism to detect distributed deadlocks.  However, Oracle Coherence 3.5 does bring us closer with a new feature we call the <a href="http://wiki.tangosol.com/display/COH35UG/service-guardian">Service Guardian</a>.  The concept behind the guardian is to ensure that each of the threads under our control are responsive; and when they&#8217;re not then the cluster node should take action.  Out of the box you can configure it to remove the node from the cluster (default) or shut down the JVM.  You can also provide an implementation of <code><a href="http://download.oracle.com/otn_hosted_doc/coherence/350/com/tangosol/net/ServiceFailurePolicy.html">ServiceFailurePolicy</a> </code> to provide custom handling of detected deadlocks.</p>
<p>Deadlocks can have especially bad consequences in a distributed system since there are inherent dependencies between nodes.  In my experience, I&#8217;ve seen deadlocks in clusters due to one of three reasons:</p>
<h3>Bugs in customer code</h3>
<p>Concurrent programming is difficult enough; mix it in with distributed computing and you can get into some sticky situations.  Several times in the past I&#8217;ve seen deadlocks occur within event handling code.  Here&#8217;s one way that event handlers can deadlock:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * @author pperalta Jul 20, 2009
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> GuardianDemo
        <span style="color: #000000; font-weight: bold;">implements</span> MapListener
    <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        NamedCache cache <span style="color: #339933;">=</span> CacheFactory.<span style="color: #006633;">getCache</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        cache.<span style="color: #006633;">addMapListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> GuardianDemo<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
            <span style="color: #000066; font-weight: bold;">int</span> nKey <span style="color: #339933;">=</span> RANDOM.<span style="color: #006633;">nextInt</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">try</span>
                <span style="color: #009900;">&#123;</span>
                cache.<span style="color: #006633;">lock</span><span style="color: #009900;">&#40;</span>nKey, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">List</span> listValue <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> cache.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>listValue <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
                    <span style="color: #009900;">&#123;</span>
                    listValue <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">ArrayList</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    <span style="color: #009900;">&#125;</span>
                listValue.<span style="color: #006633;">add</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                cache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>nKey, listValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #000000; font-weight: bold;">finally</span>
                <span style="color: #009900;">&#123;</span>
                cache.<span style="color: #006633;">unlock</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> entryInserted<span style="color: #009900;">&#40;</span>MapEvent evt<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> entryUpdated<span style="color: #009900;">&#40;</span>MapEvent evt<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        NamedCache cache <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>NamedCache<span style="color: #009900;">&#41;</span> evt.<span style="color: #006633;">getSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Object</span>     nKey  <span style="color: #339933;">=</span> evt.<span style="color: #006633;">getKey</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">try</span>
            <span style="color: #009900;">&#123;</span>
            cache.<span style="color: #006633;">lock</span><span style="color: #009900;">&#40;</span>nKey, <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">List</span> listValue <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">List</span><span style="color: #009900;">&#41;</span> cache.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>listValue.<span style="color: #006633;">size</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                <span style="color: #003399;">Object</span> lValue <span style="color: #339933;">=</span> listValue.<span style="color: #006633;">remove</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                cache.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>nKey, listValue<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Removed &quot;</span> <span style="color: #339933;">+</span> lValue <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; from &quot;</span> <span style="color: #339933;">+</span> nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #000000; font-weight: bold;">finally</span>
            <span style="color: #009900;">&#123;</span>
            cache.<span style="color: #006633;">unlock</span><span style="color: #009900;">&#40;</span>nKey<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> entryDeleted<span style="color: #009900;">&#40;</span>MapEvent evt<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #003399;">Random</span> RANDOM <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Random</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">System</span>.<span style="color: #006633;">currentTimeMillis</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>When registering a map listener with Coherence, a background thread will be spawned to handle events.  Upon receiving an event, Coherence will queue it up for the event handler (the customer provided implementation of <code>MapListener</code>) to process.  If we notice that events are being handled slower than they are being generated, then we will attempt to throttle the creation of new events so as to not allow the event queue to grow unbounded (and eventually exhaust the heap.)<br />
<i><br />
A bit of a digression: the event throttling is not a new feature of Coherence; it has been around since at least 3.2.<br />
</i></p>
<p>When I ran this code with Coherence 3.4, it ran for a while but eventually stopped:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">Oracle Coherence Version 3.4.2/411p7
 Grid Edition: Development mode
Copyright (c) 2000-2009 Oracle. All rights reserved.
...
Removed 1248134614674 from 9
Removed 1248134614692 from 9
Removed 1248134614697 from 9
Removed 1248134614699 from 9
Removed 1248134614703 from 9
Removed 1248134614706 from 9
Removed 1248134614717 from 9
Removed 1248134614708 from 6
Removed 1248134614713 from 3
Removed 1248134614719 from 6
Removed 1248134614727 from 6
Removed 1248134614723 from 3
Removed 1248134614701 from 5
Removed 1248134614709 from 8
Removed 1248134614732 from 8
Removed 1248134614736 from 3
Removed 1248134614725 from 7
Removed 1248134614729 from 5
Removed 1248134614745 from 3
Removed 1248134614733 from 8
...</pre></div></div>

<p>When it stopped running, I captured a thread dump:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">&quot;DistributedCache:EventDispatcher&quot; daemon prio=5 tid=0x01019e40 nid=0x83e200 in Object.wait() [0xb1113000..0xb1113d90]
	at java.lang.Object.wait(Native Method)
	at java.lang.Object.wait(Object.java:474)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:31)
	- locked &lt;0x295b8d88&gt; (a com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$LockRequest$Poll)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.lock(DistributedCache.CDB:37)
	at com.tangosol.util.ConverterCollections$ConverterConcurrentMap.lock(ConverterCollections.java:2024)
	at com.tangosol.util.ConverterCollections$ConverterNamedCache.lock(ConverterCollections.java:2539)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.lock(DistributedCache.CDB:1)
	at com.tangosol.coherence.component.util.SafeNamedCache.lock(SafeNamedCache.CDB:1)
	at com.tangosol.examples.guardian.GuardianDemo.entryUpdated(GuardianDemo.java:56)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:195)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:164)
	at com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:556)
	at com.tangosol.coherence.component.util.SafeNamedCache.translateMapEvent(SafeNamedCache.CDB:7)
	at com.tangosol.coherence.component.util.SafeNamedCache.entryUpdated(SafeNamedCache.CDB:1)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:195)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.dispatch(DistributedCache.CDB:22)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.entryUpdated(DistributedCache.CDB:1)
	at com.tangosol.util.MapEvent.dispatch(MapEvent.java:195)
	at com.tangosol.coherence.component.util.CacheEvent.run(CacheEvent.CDB:18)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.Service$EventDispatcher.onNotify(Service.CDB:19)
	at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:37)
	at java.lang.Thread.run(Thread.java:613)
&nbsp;
...
&nbsp;
&quot;main&quot; prio=5 tid=0x01001480 nid=0xb0801000 waiting on condition [0xb07ff000..0xb0800148]
	at java.lang.Thread.sleep(Native Method)
	at com.tangosol.coherence.component.util.Daemon.sleep(Daemon.CDB:9)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid$EventDispatcher.drainOverflow(Grid.CDB:15)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.post(Grid.CDB:17)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.send(Grid.CDB:1)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:12)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.unlock(DistributedCache.CDB:32)
	at com.tangosol.util.ConverterCollections$ConverterConcurrentMap.unlock(ConverterCollections.java:2032)
	at com.tangosol.util.ConverterCollections$ConverterNamedCache.unlock(ConverterCollections.java:2555)
	at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.unlock(DistributedCache.CDB:1)
	at com.tangosol.coherence.component.util.SafeNamedCache.unlock(SafeNamedCache.CDB:1)
	at com.tangosol.examples.guardian.GuardianDemo.main(GuardianDemo.java:40)</pre></div></div>

<p>We can see that the event dispatcher thread is waiting to acquire a lock for a key.  However, the main thread has that key locked and (in a bit of an ironic twist) is attempting to release the lock.  However, the throttling mechanism has kicked in, and it won&#8217;t allow for any more operations on the cache until the event queue is drained, which will never happen since the queue responsible for draining the event queue is stuck waiting for a lock to be released.</p>
<p>Now, let&#8217;s run it with Coherence 3.5:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">Oracle Coherence Version 3.5/459
 Grid Edition: Development mode
Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved.
...
Removed 1248136418346 from 2
Removed 1248136418361 from 2
Removed 1248136418363 from 6
Removed 1248136418365 from 3
Removed 1248136418366 from 6
Removed 1248136418369 from 2
Removed 1248136418367 from 3
Removed 1248136418371 from 6
Removed 1248136418376 from 6
Removed 1248136418389 from 2
Removed 1248136418383 from 6
Removed 1248136418384 from 3
...
Removed 1248136419975 from 3
Removed 1248136420113 from 2
Removed 1248136420114 from 7
Removed 1248136420116 from 2
2009-07-20 20:33:40.473/6.683 Oracle Coherence GE 3.5/459 &lt;Warning&gt; (thread=main, member=1): The event queue appears to be stuck.
Removed 1248136420076 from 12009-07-20 20:33:40.475/6.685 Oracle Coherence GE 3.5/459 &lt;Error&gt; (thread=main, member=1): Full Thread Dump
...
Thread[DistributedCache:EventDispatcher,5,Cluster]
        java.lang.Object.wait(Native Method)
        java.lang.Object.wait(Object.java:474)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:31)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.lock(DistributedCache.CDB:37)
        com.tangosol.util.ConverterCollections$ConverterConcurrentMap.lock(ConverterCollections.java:2024)
        com.tangosol.util.ConverterCollections$ConverterNamedCache.lock(ConverterCollections.java:2539)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.lock(DistributedCache.CDB:1)
        com.tangosol.coherence.component.util.SafeNamedCache.lock(SafeNamedCache.CDB:1)
        com.tangosol.examples.guardian.GuardianDemo.entryUpdated(GuardianDemo.java:56)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:210)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:166)
        com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:556)
        com.tangosol.coherence.component.util.SafeNamedCache.translateMapEvent(SafeNamedCache.CDB:7)
        com.tangosol.coherence.component.util.SafeNamedCache.entryUpdated(SafeNamedCache.CDB:1)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:210)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.dispatch(DistributedCache.CDB:22)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap$ProxyListener.entryUpdated(DistributedCache.CDB:1)
        com.tangosol.util.MapEvent.dispatch(MapEvent.java:210)
        com.tangosol.coherence.component.util.CacheEvent.run(CacheEvent.CDB:18)
        com.tangosol.coherence.component.util.daemon.queueProcessor.Service$EventDispatcher.onNotify(Service.CDB:26)
        com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
        java.lang.Thread.run(Thread.java:613)
...
Thread[main,5,main]
        java.lang.Thread.dumpThreads(Native Method)
        java.lang.Thread.getAllStackTraces(Thread.java:1460)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        java.lang.reflect.Method.invoke(Method.java:585)
        com.tangosol.net.GuardSupport.logStackTraces(GuardSupport.java:791)
        com.tangosol.coherence.component.util.daemon.queueProcessor.Service$EventDispatcher.drainOverflow(Service.CDB:45)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid$EventDispatcher.drainOverflow(Grid.CDB:9)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.post(Grid.CDB:17)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.send(Grid.CDB:1)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:12)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.Grid.poll(Grid.CDB:11)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$BinaryMap.unlock(DistributedCache.CDB:32)
        com.tangosol.util.ConverterCollections$ConverterConcurrentMap.unlock(ConverterCollections.java:2032)
        com.tangosol.util.ConverterCollections$ConverterNamedCache.unlock(ConverterCollections.java:2555)
        com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$ViewMap.unlock(DistributedCache.CDB:1)
        com.tangosol.coherence.component.util.SafeNamedCache.unlock(SafeNamedCache.CDB:1)
        com.tangosol.examples.guardian.GuardianDemo.main(GuardianDemo.java:40)</pre></div></div>

<p>Here the guardian took the following actions:</p>
<ol>
<li>Detected the stuck event dispatcher thread: <code>&lt;Warning&gt; (thread=main, member=1): The event queue appears to be stuck.</code>
<li>Printed the stacks of each thread
<li>Restarted the cluster threads in order to keep the node up and running
</ol>
<p>Much nicer than having a deadlocked node!</p>
<h3>Bugs in Coherence code</h3>
<p>Despite our best efforts, bugs (including deadlocks) do occasionally appear in Coherence (just like any other product.)  In particular, the kind of deadlock that has the worse consequences is a deadlock that involves a Service thread.  Everything in Coherence (the clustering logic, replicated caches, distributed caches, remote invocations, statistics, etc) is implemented internally using queues and threads that are responsible for processing messages in queues.  These are the service threads, and they are the lifeblood of Coherence.  If this type of defect should slip into any future versions of Coherence, the guardian will detect this condition and take corrective action to allow the node (and the cluster) to continue to function.</p>
<h3>Bugs in the JVM/Operating System</h3>
<p>In the absence of bugs in customer or Coherence code, we do occasionally see bugs in the JVM and/or the operating system that result in locked up service threads.  Perhaps the most notorious of these is with early versions of <a href="http://coherence.oracle.com/display/COH35UG/Deployment+Considerations+-+Linux">NPTL on Linux</a>.  In a nutshell, we saw that threads occasionally missed notifications (in other words, threads that were in <code>Object.wait()</code> would never receive the <code>Object.notify()</code> or <code>Object.notifyAll()</code> that we sent to it.)  I&#8217;ve also seen older JVMs with buggy implementations of the wait/notify mechanism with the same results.</p>
<p>One of our goals with Coherence is to keep your application up and running at all times, even when components of the system fail (hardware, databases, etc.)  This is yet one more tool in our arsenal to bring us closer to that goal.</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/07/20/coherence-3-5-service-guardian-deadlock-detection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coherence 3.5: Improved Partition Distribution Algorithm</title>
		<link>http://blackbeanbag.net/wp/2009/07/20/coherence-3-5-improved-partition-distribution-algorithm/</link>
		<comments>http://blackbeanbag.net/wp/2009/07/20/coherence-3-5-improved-partition-distribution-algorithm/#comments</comments>
		<pubDate>Mon, 20 Jul 2009 20:46:29 +0000</pubDate>
		<dc:creator>Patrick Peralta</dc:creator>
				<category><![CDATA[Coherence]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blackbeanbag.net/wp/?p=235</guid>
		<description><![CDATA[This article is part 1 of a 3 part series on my favorite new features in Coherence 3.5.
A partition is a unit of storage and transfer in a Coherence partitioned/distributed cache.  Out of the box we ship with 257 partitions, which means that clusters with 16 or fewer storage enabled nodes do not need [...]]]></description>
			<content:encoded><![CDATA[<p><i>This article is part 1 of a 3 part series on my <a href="/wp/2009/07/20/my-favorite-new-features-in-coherence-3-5/">favorite new features in Coherence 3.5.</a></i></p>
<p>A partition is a unit of storage and transfer in a Coherence <a href="http://coherence.oracle.com/display/COH35UG/Partitioned+Cache+Service">partitioned/distributed cache</a>.  Out of the box we ship with 257 partitions, which means that clusters with 16 or fewer storage enabled nodes do not need to have this setting modified.  Larger clusters require more partitions, as this will ensure even distribution of data across the grid.  Prior to Coherence 3.5, our guideline for setting the partition count was to take the number of storage enabled nodes, square it, and round up to the next prime number.  (See <code>partition-count</code> setting <a href="http://coherence.oracle.com/display/COH34UG/distributed-scheme">here</a>).  </p>
<p>When new nodes are added to a cluster, the senior node (the oldest in the grid) is responsible for coordinating ownership of the partitions.  Note that this is not a single point of failure since the departure of a senior node will result in the promotion of the next oldest node which will seamlessly take over the responsibilities of the senior.  However, when a large cluster with a large partition count is starting up, the senior node does have a lot of (CPU) work to do regarding the management of partitions, and this becomes noticeable when starting up many nodes simultaneously.  For this reason, large clusters are typically started up a few nodes at a time, the exact number depending on  the CPU capabilities of the box.</p>
<p>I decided to test this out with a hypothetical cluster consisting of 100 storage nodes.  Using the old partitioning guidelines, this would require 10,007 partitions.  I started up 4 nodes at the same (since there are four cores on this box) time with this partition count:</p>
<p><img src="http://blackbeanbag.net/wp/wp-content/uploads/2009/07/34_all-cpu.png" alt="Coherence 3.4 with 10,007 partitions" title="34_all-cpu" width="640" height="480" class="size-full wp-image-240" /></p>
<p>As you can see, we experienced about 95% CPU usage for about 15 seconds, followed by a couple of minutes of 5% usage.</p>
<p>In Coherence 3.5, we improved the distribution algorithm to require fewer partitions for large clusters.  The new <a href="http://coherence.oracle.com/display/COH35UG/distributed-scheme">guidelines</a> indicate that each partition should store no more than 50MB.  In my hypothetical example, I&#8217;m running 100 nodes, each with a 512MB heap.  Taking backups and headroom into account I can store 170MB of primary data on each node.  If I take a conservative approach and store about 25MB per partition, that takes me to 7 partitions per node.  7 * 100 rounded up to the next prime is 701.  </p>
<p>To summarize, we&#8217;re going from 10,001 partitions in 3.4 to 701 partitions in 3.5.</p>
<p>Here is the same CPU chart when starting up 4 nodes in 3.5 with this partition count:</p>
<p><img src="http://blackbeanbag.net/wp/wp-content/uploads/2009/07/35_all-cpu.png" alt="35_all-cpu" title="35_all-cpu" width="640" height="480" class="aligncenter size-full wp-image-255" /></p>
<p>This time we experience a very brief momentary spike of 65% CPU usage, after which we are using no CPU.  Both charts cover about a four minute period.</p>
<p>This enhancement will drastically reduce the amount of time required to start up large clusters, and it will result in less CPU consumption by the senior member.  The larger the cluster, the larger the benefit!</p>
]]></content:encoded>
			<wfw:commentRss>http://blackbeanbag.net/wp/2009/07/20/coherence-3-5-improved-partition-distribution-algorithm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
