<?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>Cubeia &#187; Blog</title>
	<atom:link href="http://www.cubeia.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cubeia.com</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Wed, 01 May 2013 14:48:16 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5</generator>
		<item>
		<title>A DSL for Poker &#8211; On Achieving Your Dreams</title>
		<link>http://www.cubeia.com/2013/05/a-dsl-for-poker-on-achieving-your-dreams/</link>
		<comments>http://www.cubeia.com/2013/05/a-dsl-for-poker-on-achieving-your-dreams/#comments</comments>
		<pubDate>Wed, 01 May 2013 05:32:04 +0000</pubDate>
		<dc:creator>Viktor Nordling</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=1184</guid>
		<description><![CDATA[Six years ago, I saw some source code that has stayed with me ever since. It was a piece of Erlang code that described the game of Texas Hold&#8217;em poker. What struck me was the beautiful simplicity in that it described exactly the rules of poker and nothing else. This was very different from the [...]]]></description>
				<content:encoded><![CDATA[<p>Six years ago, I saw some source code that has stayed with me ever since. It was a <a href="https://github.com/wagerlabs/openpoker/blob/master/src/g.erl#L783">piece of Erlang code</a> that described the game of Texas Hold&#8217;em poker. What struck me was the beautiful simplicity in that it described exactly the rules of poker and nothing else. This was very different from the legacy poker system I wrestled with at the time. I decided then and there to set a goal to create &#8220;a card rules engine&#8221;. I even added this goal to a website which kept sending me emails nagging about this goal.</p>
<p>I tried some different things over the years, first I toyed with the idea of describing card games as a state machine. I even implemented the basics of Texas Hold&#8217;em in <a href="http://unimod.sourceforge.net/">UniMod</a>. That quickly got very messy, mostly because of all the special cases but also because it&#8217;s actually quite hard to reuse a sub state machine from the outer state machine.</p>
<p>I also considered modelling poker as rules with a rules engine (<a href="http://www.jboss.org/drools/">Drools</a> to be specific). It seems to make sense, poker is a set of rules and a rules engine takes a set of rules and a set of facts and applies these rules. However, these rules engines are meant for &#8220;business&#8221; rules, meaning they will help you apply the right insurance premium or offer the correct rebate on your order. Having a system where &#8220;any&#8221; matching rule will fire does not make for very predictable gameplay. In other words, it&#8217;s just a bad match.</p>
<p>For a while it seemed like my dream to create &#8220;a card rules engine&#8221; would remain just that (it was also a case of the goal not being <a href="http://en.wikipedia.org/wiki/SMART_criteria">SMART</a>, but I digress). During the last year and a bit, I have found myself writing poker code from scratch again, this time working on Cubeia&#8217;s <a href="http://www.cubeiapoker.com/">social poker network</a>. As always, there were deadlines and requirements, so I could not sit around and polish on this ivory tower dream of mine. I did however apply a lot of the good design principles I had picked up over the years, mostly from my man crush <a href="http://misko.hevery.com/2009/10/07/design-for-testability-talk/">Miško Hevery</a>. </p>
<p>The key principles in this case were &#8220;design for testability&#8221; (with the help of <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a>) and &#8220;<a href="http://en.wikipedia.org/wiki/Composition_over_inheritance">composition over inheritance</a>&#8220;. And so one evening it hit me that going from where I was to a <a href="http://en.wikipedia.org/wiki/Domain-specific_language">DSL</a> for poker would not even be a lot of work. So I sat down and spent just over one day before my new and shiny DSL for poker saw the light. Here&#8217;s what the definition of Texas Hold&#8217;em looks like with this DSL:</p>
<pre class="brush: java; title: ; notranslate">
    public static GameType createTexasHoldem() {
        return new PokerGameBuilder().withRounds(
                        blinds(),
                        dealFaceDownCards(2),
                        bettingRound(PRE_FLOP, fromBigBlind()),
                        dealCommunityCards(3),
                        bettingRound(FLOP),
                        dealCommunityCards(1),
                        bettingRound(TURN),
                        dealCommunityCards(1),
                        bettingRound(RIVER)).build();
    }
</pre>
<p>and here&#8217;s what Omaha would look like:</p>
<pre class="brush: java; title: ; notranslate">
    public static GameType createOmaha() {
        return new PokerGameBuilder().withRounds(
                        blinds(),
                        dealFaceDownCards(4),
                        bettingRound(PRE_FLOP, fromBigBlind()),
                        dealCommunityCards(3),
                        bettingRound(FLOP),
                        dealCommunityCards(1),
                        bettingRound(TURN),
                        dealCommunityCards(1),
                        bettingRound(RIVER)).
                        withHandEvaluator(new OmahaHandEvaluator()).build();
    }
</pre>
<p>You get the idea (the entire code is available from Cubeia&#8217;s <a href="https://bitbucket.org/cubeia/cubeia-poker/src/9e6316ffabe5e8960e0778d0f10db502b86e51a0/server/game-modules/poker-logic/src/main/java/com/cubeia/poker/variant/GameTypes.java?at=default">open source poker repo on BitBucket</a>). Having now achieved this goal of mine I felt very proud and slightly embarrassed that it took me so long to get there. </p>
<p>My takeaway from this and the message I want impress on you is to never give up on your goal and most of all to not get stuck searching for the &#8220;one grand unified model&#8221; as I did which easily gets you stuck in &#8220;<a href="http://en.wikipedia.org/wiki/Analysis_paralysis">analysis paralysis</a>&#8220;, but rather break the problem down into pieces and apply adequate design principles to each part.</p>
<p>I hope this gets you motivated to achieve your goal!</p>
<p>Viktor Nordling</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2013/05/a-dsl-for-poker-on-achieving-your-dreams/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Try our Social Poker</title>
		<link>http://www.cubeia.com/2013/04/try-our-social-poker/</link>
		<comments>http://www.cubeia.com/2013/04/try-our-social-poker/#comments</comments>
		<pubDate>Wed, 24 Apr 2013 13:18:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[cubeia]]></category>
		<category><![CDATA[social poker network]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[poker]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=1173</guid>
		<description><![CDATA[Our social poker network is now up and running in beta mode. We have been hard at work the last couple of weeks to react to the feedback we have been getting from our players and operators. If you are interested in running your own Social Poker network as an operator you can get more [...]]]></description>
				<content:encoded><![CDATA[<p>Our social poker network is now up and running in beta mode. We have been hard at work the last couple of weeks to react to the feedback we have been getting from our players and operators. If you are interested in running your own Social Poker network as an operator you can get more information at <a href="http://www.cubeiasocial.com/" title="http://www.cubeiasocial.com/" target="_blank">http://www.cubeiasocial.com/</a> and if you want to try the game out you can play through our example integration at <a href="http://www.cubeiapoker.com/" title="http://www.cubeiapoker.com/" target="_blank">http://www.cubeiapoker.com/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2013/04/try-our-social-poker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cubeia Social update</title>
		<link>http://www.cubeia.com/2013/03/cubeia-social-update/</link>
		<comments>http://www.cubeia.com/2013/03/cubeia-social-update/#comments</comments>
		<pubDate>Tue, 26 Mar 2013 15:58:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=1144</guid>
		<description><![CDATA[We have been releasing a lot of new things for our on Cubeia Social, check it out if you are interested in a social poker network. We are getting closer to an open beta and are really looking forward to put the product in Your hands!]]></description>
				<content:encoded><![CDATA[<p>We have been releasing a lot of new things for our on Cubeia Social, check it out if you are interested in a <a title="Social Poker" href="http://www.cubeiasocial.com">social poker network</a>. We are getting closer to an open beta and are really looking forward to put the product in Your hands!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2013/03/cubeia-social-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Authentication</title>
		<link>http://www.cubeia.com/2013/01/mysql-authentication/</link>
		<comments>http://www.cubeia.com/2013/01/mysql-authentication/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 14:40:59 +0000</pubDate>
		<dc:creator>fredrik</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=1134</guid>
		<description><![CDATA[We have added default support for integration between Cubeia Network&#8217;s user-service and legacy MySQL database. This might be useful if you already have an existing user base stored in a MySQL database and want to use that for authentication but still want to take advantage of Cubeia Network. Read more here: MySQL Migration Adapter Note: [...]]]></description>
				<content:encoded><![CDATA[<p>We have added default support for integration between Cubeia Network&#8217;s user-service and legacy MySQL database. This might be useful if you already have an existing user base stored in a MySQL database and want to use that for authentication but still want to take advantage of Cubeia Network.</p>
<p>Read more here: <a href="http://www.cubeia.org/wiki/index.php/Network/user/tutorials/mysql-migration-handler">MySQL Migration Adapter</a></p>
<p>Note: This will be included in Cubeia Network as of version 1.4.0</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2013/01/mysql-authentication/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Poker Demo updated</title>
		<link>http://www.cubeia.com/2013/01/poker-demo-updated/</link>
		<comments>http://www.cubeia.com/2013/01/poker-demo-updated/#comments</comments>
		<pubDate>Wed, 23 Jan 2013 14:36:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=1129</guid>
		<description><![CDATA[A new version of the poker network demo is now available for download. Grab it while its hot!]]></description>
				<content:encoded><![CDATA[<p>A new version of the <a href="http://www.cubeia.com/?page_id=858">poker network demo</a> is now available for <a href="http://www.cubeia.com/?page_id=858">download</a>. Grab it while its hot!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2013/01/poker-demo-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cubeia Poker Cloud Scalability</title>
		<link>http://www.cubeia.com/2012/12/cubeia-poker-cloud-scalability/</link>
		<comments>http://www.cubeia.com/2012/12/cubeia-poker-cloud-scalability/#comments</comments>
		<pubDate>Wed, 19 Dec 2012 15:59:46 +0000</pubDate>
		<dc:creator>larsan</dc:creator>
				<category><![CDATA[cubeia]]></category>
		<category><![CDATA[firebase]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[poker]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=1096</guid>
		<description><![CDATA[Introduction Would you want some cloud with your game server? Cubeia Firebase was initially build for real money gambling and for deployment on dedicated hardware. It makes sense to control your hardware when you&#8217;re dealing with monetary systems but as gambling focus has shifted the last couple of years towards social gaming cloud based deployments makes much [...]]]></description>
				<content:encoded><![CDATA[<p><strong>Introduction</strong></p>
<blockquote><p>Would you want some cloud with your game server?</p></blockquote>
<p>Cubeia Firebase was initially build for real money gambling and for deployment on dedicated hardware. It makes sense to control your hardware when you&#8217;re dealing with monetary systems but as gambling focus has shifted the last couple of years towards social gaming cloud based deployments makes much more sense. In this article we&#8217;ll present Cubeia Poker running on Amazon AWS and our initial load tests and evaluation.<span id="more-1096"></span><strong></strong></p>
<p><strong>Setup<br />
</strong>In order to make these tests as real-world as possible on this stage we made the following modifications to our standard suite of software that comprises Cubeia Poker:</p>
<ul>
<li>Cubeia Firebase &#8211; Normally Cubeia Firebase scales in all directions by using direct-connect inter-cluster communication. But as a cloud deployment usually cannot make hard guarantees on internal bandwidth and latency we settled for a pure scale-out architecture instead. This entailed disabling the internal message bus and state replication mechanisms.</li>
<li>Cubeia Network &#8211; The main challenge here was to scale the wallet functionality. Again, a real money network have demands on consistency that can be relaxed in a social setting. Our modification will be discussed later, but in essence we added sharding of table transactions to scale the load.</li>
<li>Cubeia Poker &#8211; A standard build was used except small changes to provide for the above changes to Cubeia Network. Note that the changes in Cubeia Firebase was completely outside the API and nothing needed to be changes in the Poker code to accommodate them.</li>
</ul>
<p><strong>Wallet Sharding</strong><br />
The Cubeia Network accounting modules uses dual entry bookkeeping, with <em>static</em> accounts for the main balance of a player and <em>session</em> accounts for all transactions for a player at a particular tables.   When a player signs up and plays at a table, this happens:</p>
<ol>
<li>The player signs up: a <em>static</em> account is created to hold the players balance.</li>
<li>The player sits down at a table with X chips: A <em>session</em> account is created for the player and the buy-in sum X is transferred from the players <em>static</em> account to the <em>session</em> account.</li>
<li>As player loose and win chips around the table the balances of the <em>session</em> accounts are updated.</li>
<li>The player leaves the table: The <em>session</em> account is closed and the resulting balance (ie. win or loss) is transferred to his <em>static</em> account.</li>
</ol>
<p>The code itself is write optimized and scales well on dedicated hardware. But for this test we opted to run the <em>session</em> accounts, ie table transactions, on separate servers and shard these across the cluster.</p>
<p><strong>Amazon AWS</strong><br />
We opted to run the tests on Amazon AWS in their East Coast data centers, but paid no attention to exact location.</p>
<ul>
<li>EC2 was used for all Firebase, Wallet and Bot servers. Pre-setup AMI&#8217;s where used with live configuration via Puppet and user data scripts. Only ephemeral storage was used. All servers ran as High-CPU Extra Large Instances (c1.xlarge).</li>
<li>RDS was used for the databases with MySQL 5 without and replication and read/write setup. Provisioned IO was not used. All instances ran as Extra Large instances with an allocated 5 GB of storage.</li>
</ul>
<p>It should be noted that apart from the large instance types no effort was made to customize or otherwise tweak the AWS installation, the servers were not even in the same data center.</p>
<p><strong>25 000 Concurrent Players</strong></p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/25.png"><img class="alignnone  wp-image-1114" title="25" src="http://www.cubeia.com/wp-content/uploads/2012/12/25.png" alt="" width="442" height="194" /></a></p>
<p>The Firebase and Bot servers where launched in pairs; one pairing of with one bot server with the bot server running 25 000 players. One Wallet server where handling the <em>static</em> account and one the <em>session</em> accounts. The CPU load on the Wallet servers where 25 and 20 percent respectively, and 12 and 18 percent for the matched databases (eyeball figures).</p>
<p><strong>50 000 Concurrent Players</strong></p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/50.png"><img class="alignnone  wp-image-1115" title="50" src="http://www.cubeia.com/wp-content/uploads/2012/12/50.png" alt="" width="442" height="194" /></a></p>
<p>As the load on the Wallet server was perfectly acceptable the only addition for this step was one more pair of Firebase and Bot servers.   The CPU load on the Wallet servers rose to 50 percent for both server, and 25 and 30 percent for the matched databases (eyeball figures).</p>
<p><strong>75 000 Concurrent Players</strong></p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/75.png"><img class="alignnone  wp-image-1116" title="75" src="http://www.cubeia.com/wp-content/uploads/2012/12/75.png" alt="" width="442" height="357" /></a></p>
<p>One more Firebase and Bot pair was added. Another database shard and <em>session</em> account Wallet server where added together with an additional <em>static</em> account Wallet server to share the rising CPU load. The load on the Wallet servers matched the expected loads from 50&#8242; + 25&#8242; above.</p>
<p><strong>100 000 Concurrent Players</strong></p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/100.png"><img class="alignnone  wp-image-1117" title="100" src="http://www.cubeia.com/wp-content/uploads/2012/12/100.png" alt="" width="442" height="357" /></a></p>
<p>For the final load a last Firebase and Bot pair of server where added.  Again the load on the Wallet servers matched the expected loads from above, ie. 50&#8242; + 50&#8242;.</p>
<p><strong>Test Results</strong><br />
Below follows some  evaluation of the actual numbers pulled from the servers during this test. Please note that the game play frequency oscillates naturally and therefore small variations on load and relations are expected.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/gevsh1.png"><img class="alignnone size-full wp-image-1105" style="border: 1px solid black;" title="Game Events vs Hands per Minute" src="http://www.cubeia.com/wp-content/uploads/2012/12/gevsh1.png" alt="Game Events vs Hands per Minute" width="600" height="371" /></a></p>
<p>The above chart shows the executed game events in a Firebase server correlated with Poker hands per minute.  At full load we were executing <strong>4264</strong> incoming events per second and generating a whooping <strong>13 204</strong> hands per minute (220 hands per second).</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/ehpp.png"><img class="alignnone size-full wp-image-1108" style="border: 1px solid black;" title="Events and Hands per Player" src="http://www.cubeia.com/wp-content/uploads/2012/12/ehpp.png" alt="Events and Hands per Player" width="600" height="371" /></a></p>
<p>As expected from the previous graph the relations between executed events and hands per player stays flat. Each player generates approximately <strong>2.4</strong> events per minute and you can expect approximately <strong>0.14</strong> hands per minute and player.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/oepp.png"><img class="alignnone size-full wp-image-1109" style="border: 1px solid black;" title="Outgoing Events per Player" src="http://www.cubeia.com/wp-content/uploads/2012/12/oepp.png" alt="Outgoing Events per Player" width="600" height="371" /></a></p>
<p>Poker is a naturally &#8220;talkative&#8221; game. In Cubeia Poker each executed event generates approximately 10.5 outgoing events. At full load the system was executing <strong>4264</strong> events per second and broadcasting <strong>46 264</strong> events per second (approximately 1050 and 11 500 per Firebase and Bot server pair).</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/12/scpp.png"><img class="alignnone size-full wp-image-1111" style="border: 1px solid black;" title="Server Cost per Player" src="http://www.cubeia.com/wp-content/uploads/2012/12/scpp.png" alt="Server Cost per Player" width="600" height="371" /></a></p>
<p>Using this we can calculate the cost per player to run this cluster. Two things should be taken into account here: 1) bandwidth is <em>not</em> included; and 2) no attempt was made to minimize the server cost by running the most effective instance type for each server. For example, each Firebase server had a CPU load of approximately <strong>50-65%</strong> during the test and could possibly have been run on cheaper instance types. But apart from this the monthly server cost of running 100 000 concurrent poker players is <strong>$5378</strong> which corresponds to <strong>$0.054</strong> per player. The slight increase in cost at 75&#8242; concurrent players is because the scaling model is not perfectly linear across this test, between 25&#8242; and 50&#8242; only one server was added, but between 50&#8242; and 75&#8242;  four servers entered the cluster.</p>
<p><strong>Conclusion</strong><br />
The total cost of running a Cubeia Poker cluster on Amazon is very low and decreases with more players despite the fact that Firebase is a heavy server (due to it&#8217;s real money origin) and that Poker is a very event heavy game. The scalability model works very well provided the limitations.</p>
<blockquote><p>Ma&#8217;, can I go out and play with my one million friends?</p></blockquote>
<p>In order to take this further the <em>static</em> account database needs to be sharded. Whereas <em>session</em> accounts deals with player to player interactions, <em>static</em> accounts do not, and the sharding is therefore relatively simple and can be done using user ID or any other available metric. One million? Sure, why not?</p>
<p><em>About the author: Lars J. Nilsson is a founder and Executive Vice President of Cubeia Ltd. He’s an autodidact programmer, former opera singer, and lunch time poet. Any questions are welcome at lars.j.nilsson in Cubeia’s domain.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2012/12/cubeia-poker-cloud-scalability/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cubeia + NDA = No Go</title>
		<link>http://www.cubeia.com/2012/11/cubeia-nda-no-go/</link>
		<comments>http://www.cubeia.com/2012/11/cubeia-nda-no-go/#comments</comments>
		<pubDate>Fri, 30 Nov 2012 10:26:25 +0000</pubDate>
		<dc:creator>larsan</dc:creator>
				<category><![CDATA[cubeia]]></category>
		<category><![CDATA[confidentiality]]></category>
		<category><![CDATA[legal]]></category>
		<category><![CDATA[nda]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=1084</guid>
		<description><![CDATA[Frequently we&#8217;re asked to sign Non-Disclosure Agreements (NDA). Either they&#8217;re presented at an exploratory stage or when agreements or licenses are to be written. Generally we say no to them, and here&#8217;s why. First a little bit of background: Cubeia is a technology company. We work as expert consultants with some of the larger companies [...]]]></description>
				<content:encoded><![CDATA[<p>Frequently we&#8217;re asked to sign Non-Disclosure Agreements (NDA). Either they&#8217;re presented at an exploratory stage or when agreements or licenses are to be written. Generally we say no to them, and here&#8217;s why.</p>
<p><span id="more-1084"></span>First a little bit of background: Cubeia is a technology company. We work as expert consultants with some of the larger companies in the iGaming business. We also are amendable to revenue share deals which makes us interesting for entrepreneurs. So on the one hand we have established relationships with existing companies and on the other hand start-ups.</p>
<p>Many NDA&#8217;s are simply badly written. Others contain possible death traps for a company like ours. But mostly, these are our problems:</p>
<ul>
<li>Too early: We find ourselves in a position much like an investor or a company with an established RD department. If you want to explore an <em>idea</em> with us that&#8217;s fine, but don&#8217;t expect us to sign an NDA at an exploratory stage, if we did we&#8217;d soon have drawers full of them.</li>
<li>Non-mutual: If you tell me your secret I&#8217;ll tell you mine. There&#8217;s usually no good reason for an NDA not to be mutual unless it is explicitly meant as a possible weapon. And if that&#8217;s your kind of game, don&#8217;t expect us to play along.</li>
<li>No expiration: If the NDA doesn&#8217;t expire we&#8217;d soon be drowning in NDA&#8217;s. Each new agreement would just pile on the stack of existing ones, and the accumulated legal risk would increase each time we sign a new one. Also it often makes little sense: do you <em>really</em> have an idea so powerful that it needs to be kept under wraps forever?</li>
</ul>
<p>Here&#8217;s an interesting detail: Cubeia often insists on Swedish jurisdiction for our agreements, and if I&#8217;ve understood it correctly, for any piece of information to be confidential according to Swedish law it not only needs to identified as such, it must also be business critical and the holder of the information must be able to show that they&#8217;ve taken steps to actually keep it secret. So not just any piece of data will do, and if you want to press claims based on the disclosure of information you also must make sure that you yourself has kept it secret. Which makes sense to me, and also renders many of the NDA&#8217;s I&#8217;ve seen fairly useless.</p>
<p>So where does this leave us? Obviously Cubeia will sign an NDA if needed. But you need to convince us that it is worth the time and the risk. By making it mutual, keeping it simple and supplying an expiration date the chances we&#8217;ll find it acceptable increases significantly. Also understand that we will not sign any NDA based on ideas only, or while we&#8217;re still only exploring possibilities of a deal.</p>
<p>In software development it is recognized that new code, however well written, will always increase complexity and risk. The same goes for legal documents, no matter how well written, the simple fact that there is  <em>one more</em> of them increases complexity, which equals increased cost of maintenance and increased risk.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2012/11/cubeia-nda-no-go/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Debugging Class Loading with AOP</title>
		<link>http://www.cubeia.com/2012/11/debugging-class-loading-with-aop/</link>
		<comments>http://www.cubeia.com/2012/11/debugging-class-loading-with-aop/#comments</comments>
		<pubDate>Fri, 23 Nov 2012 13:11:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=999</guid>
		<description><![CDATA[In this article I&#8217;ll briefly discuss how Aspect Oriented Programming (AOP) using AspectJ can be used to debug class loading, in particular in instances where a system have multiple class loaders. I&#8217;ll assume a basic understanding of Java class loading and AOP. Class loading in Java is often misunderstood and derided. I&#8217;ll not spend my [...]]]></description>
				<content:encoded><![CDATA[<p>In this article I&#8217;ll briefly discuss how Aspect Oriented Programming (AOP) using AspectJ can be used to debug class loading, in particular in instances where a system have multiple class loaders. I&#8217;ll assume a basic understanding of Java class loading and AOP.<span id="more-999"></span></p>
<p>Class loading in Java is often misunderstood and derided. I&#8217;ll not spend my time here defending it, but rather try to find a way to gain more information from multiple class loaders.</p>
<div class="alert success"><div class="msg">The solution is not perfect, but should be used as an example or as a jumping-off point. I'm writing this because I like the problem domain, not because I necessarily want to solve all <em>your</em> problems...  :)</div><a href="#" class="toggle-alert">Toggle</a></div><p>&nbsp;</p>
<p>You&#8217;ll find complete source code for this article in the resources at the end.</p>
<h2>The Problem</h2>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/hierarchy.jpg"><img class=" wp-image-1001 alignright" title="hierarchy" src="http://www.cubeia.com/wp-content/uploads/2012/11/hierarchy.jpg" alt="" width="286" height="118" /></a>In any non-trivial class loader hierarchy, there&#8217;s always a danger of mixing up the class files on deployment. Code deployed on an application server or similar systems will usually share classes. Using the diagram to the right we can easily envision “artifact 1” and “artifact 2” sharing some classes, but if the packaging is not exactly right, or if we have static dependencies, we may be hit with class loading difficulties</p>
<p>We should also remember that the called class loader will usually ask its parent class loader first, and only when the parent class loader returns null, look to its own classes. Using the diagram above as an example, if the class loader for “artifact 1” is asked for a class it will first ask the class loader “deploy” witch in its turn will ask “system”, so the actual lookup chain will be in this order: system &gt; deploy &gt; artifact 1.</p>
<h3>ClassNotFoundException</h3>
<p>This exception means that a class file could not be found when one of the following three methods were called:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">ClassLoader</span>.<span style="color: #006633;">loadClass</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span>
<span style="color: #003399;">ClassLoader</span>.<span style="color: #006633;">findSystemClass</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">Class</span>.<span style="color: #006633;">forName</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Given the string name the class loader will usually do a normal recursive search through the parents as described above and if the class file is not found, raise the exception.</p>
<h3>NoClassDefFoundError</h3>
<p>This is a linkage error when a class is implicitly loaded but cannot be found in runtime. In other words, the executing class was compiled with access to the missing class, but when the code is executing the class is missing. In that sense this error is usually caused by a class not found exception.</p>
<p>One common source of these errors is when a parent class loader attempts to load a class which depends implicitly on classes from a child class loader. This is often the case with static factory methods where an API defines a static method like this:</p>

<div class="wp_syntax"><table><tr><td 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> Foo loadFoo<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> fooClass<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>If we assume that this factory is loaded by our “deploy” class loader but we have dependencies in any of the artifacts, there are two plausible scenarios:</p>
<ul>
<li>We call the factory and the class we supply as the argument is located in one of the artifact class loaders we will get a class not found because a parent class loader will not search, or even be aware of, its child class loaders.</li>
<li>We call the factory and the class we supply as the argument is indeed found either in “deploy” or its parent “system”, but that class in its turn depends on a class found only  in one of the artifact class loaders we will get a class def not found error.</li>
</ul>
<p>Given this little crash course, why is this such a huge problem? The answer is often that we do not get enough information with the errors. It seems to me there are some basic things we would like to know when any of these problems occur:</p>
<ul>
<li>If a class is not found by a class loader, what classes does it actually contain? Or rather, from where does it read its classes?</li>
<li>If a class is not found by a class loader, is it perhaps loaded by another class loader but one which it does not have access to?</li>
</ul>
<p>This information can only be supplied by the class loaders themselves. Which is fine if you write your own server and can add debugging code as you please, but not so interesting if you use an application server of any sort.</p>
<h2>Enter AspectJ</h2>
<p>Now then, could we use AspectJ to help us out? After all, it is perfectly reasonable to define “points” in the executing code we can use to gather the information we need.</p>
<div class="alert success"><div class="msg">I'm using AspectJ for this article, but it should be possible to write it for other AOP frameworks as long as they support runtime weaving.</div><a href="#" class="toggle-alert">Toggle</a></div><p>&nbsp;</p>
<p>Let&#8217;s see then, in order to answer our two main questions above we need to:</p>
<ul>
<li>Gather data when a class is loaded anywhere in the system, to
<ul>
<li>Maintain a map between class names and their loaders.</li>
<li>Keep a set of known resources for each class loader.</li>
</ul>
</li>
<li>Intercept our two exceptions and print some debugging.</li>
</ul>
<h2>Pointcut: Loading a Class</h2>
<p>Looking at the class loaders, it turns out that there&#8217;s a very handy pointcut we can make: the call to load a class in the class loader.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">pointcut source<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s, <span style="color: #003399;">ClassLoader</span> l<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> 
        target<span style="color: #009900;">&#40;</span><span style="color: #003399;">ClassLoader</span><span style="color: #339933;">+</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;&amp;</span>amp<span style="color: #339933;">;</span> 
        target<span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
        args<span style="color: #009900;">&#40;</span>s<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span>
        call<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> loadClass<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This pointcut has two arguments, the name of the class being asked for, and the class loader which is called. It intercepts the call to “load class” in ClassLoader or any of its descendants (that&#8217;s what the &#8216;+&#8217; means).</p>
<div class="alert success"><div class="msg">I'm limiting myself to one method call (“load class”) here, feel free to extend it if need be.</div><a href="#" class="toggle-alert">Toggle</a></div><p>&nbsp;</p>
<h2>Gather Data</h2>
<p>Using the pointcut above we can now solve our first problem, maintain our maps of debugging data. Well start with defining the advice</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">after<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s, <span style="color: #003399;">ClassLoader</span> l<span style="color: #009900;">&#41;</span> returning <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> cl<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> source<span style="color: #009900;">&#40;</span>s, l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Some things to note here, this advice will only be called upon normal execution, because it is defined as “returning”, so we don&#8217;t have to worry about exceptions. When the advice executes we will also have access to three context items, the called class loader, the name of the class and the loaded class.</p>
<p>I&#8217;ll not add all code here, you find the source code of this article in the resources at the end, but what we need to do in the above advice is to map the class name to the class loader, and to create or update a set of resources associated with the class loader to include the code source of the loaded class.</p>
<p>All classes loaded by a secure class loader should have a “code source”. This represents the location the class was loaded from, in other words a file path, a JAR archive etc. It is available in the protection domain given the class, so you can extract the exact code source URL like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">CodeSource</span> src <span style="color: #339933;">=</span> .<span style="color: #006633;">getProtectionDomain</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getCodeSource</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">URL</span> url <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>src <span style="color: #339933;">==</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">?</span> <span style="color: #000066; font-weight: bold;">null</span> <span style="color: #339933;">:</span> src.<span style="color: #006633;">getLocation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>So in effect the advice will look like this:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">after<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s, <span style="color: #003399;">ClassLoader</span> l<span style="color: #009900;">&#41;</span> returning <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">Class</span> cl<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> source<span style="color: #009900;">&#40;</span>s, l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/*
     * map class name to class loader
     */</span>
    registerClassLoader<span style="color: #009900;">&#40;</span>cl, l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*
     * find the class code source and add it to a 
     * set mapped to the class loader
     */</span>
    registerSources<span style="color: #009900;">&#40;</span>cl, l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Debugging: Catch the ClassNotFoundException</h2>
<p>Now, let&#8217;s catch the class not found errors. We&#8217;ll do this using the same pointcut as above but with another advice:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">after<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s, <span style="color: #003399;">ClassLoader</span> l<span style="color: #009900;">&#41;</span> throwing <span style="color: #009900;">&#40;</span><span style="color: #003399;">ClassNotFoundException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> source<span style="color: #009900;">&#40;</span>s, l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>This advice will only run when a class not found is raised by the call identified by the pointcut. We could catch the exception before it is handled (using the “handler” directive) but since we want to know the class loader anyway, this method is a bit more effective.</p>
<p>Printing the debug information here will be rather straightforward (again, the complete sources can be found at the end of this article):</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">after<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> s, <span style="color: #003399;">ClassLoader</span> l<span style="color: #009900;">&#41;</span> throwing <span style="color: #009900;">&#40;</span><span style="color: #003399;">ClassNotFoundException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> source<span style="color: #009900;">&#40;</span>s, l<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/*
     * get the code sources for the given class loader
     */</span>
    LoaderSources fail <span style="color: #339933;">=</span> getSourcesFor<span style="color: #009900;">&#40;</span>l<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*
     * check if can find the class in any other class loader
     */</span>
    <span style="color: #003399;">ClassLoader</span> real <span style="color: #339933;">=</span> classLoaders.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>s<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>real <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>
        <span style="color: #666666; font-style: italic;">/*
         * get the resources for the class loader we found
         * and print debug information
         */</span>
        LoaderSources found <span style="color: #339933;">=</span> getSourcesFor<span style="color: #009900;">&#40;</span>real<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        DebugPrinter.<span style="color: #006633;">printClassNotFound</span><span style="color: #009900;">&#40;</span>s, fail, found<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>
        DebugPrinter.<span style="color: #006633;">printClassNotFound</span><span style="color: #009900;">&#40;</span>s, fail<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Pointcut: Trap the NoClassDefFoundError</h2>
<p>The no class def found error is a runtime error making it hard to catch. In this article we&#8217;ll simplify things a bit by using the special point “handler” which can be used for advice execution just before an exception is handled by a catch clause.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">pointcut noDef<span style="color: #009900;">&#40;</span><span style="color: #003399;">NoClassDefFoundError</span> e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> 
        args<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> 
        handler<span style="color: #009900;">&#40;</span><span style="color: #003399;">NoClassDefFoundError</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>This pointcut simply adds a handler for the error and saves the error as an argument.</p>
<h2>Debugging: Handle the NoClassDefFoundError</h2>
<p>We&#8217;ll use a very simple advice form here:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">before<span style="color: #009900;">&#40;</span><span style="color: #003399;">NoClassDefFoundError</span> e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> noDef<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// do something here...</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>As a no class def found is implicit, and hence can be thrown from method executions as well as calls, the weaving would be rather extensive, so we&#8217;ll limit ourselves by using the handler. The handler mechanism has one downside though, it&#8217;s hard to get to the class loader from which the problem originated. What we&#8217;ll do here is to use the “this” object available from the pointcut which will in effect be the object which contains the catch clause.</p>
<div class="alert success"><div class="msg">By using the handler you will most likely have to use an additional step when you get a no class def found error, when you get the error add a catch for it as high in the call stack you can within your own code, which will make the “this” object in the advice to be much more relevant</div><a href="#" class="toggle-alert">Toggle</a></div><p>&nbsp;</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;">before<span style="color: #009900;">&#40;</span><span style="color: #003399;">NoClassDefFoundError</span> e<span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> noDef<span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">/*
     * the class name we're looking for is the 
     * message of the exception with path separators
     * instead of dots, so...
     */</span>
    <span style="color: #003399;">String</span> name <span style="color: #339933;">=</span> e.<span style="color: #006633;">getMessage</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;">if</span><span style="color: #009900;">&#40;</span>name <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>
        name <span style="color: #339933;">=</span> name.<span style="color: #006633;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">File</span>.<span style="color: #006633;">separatorChar</span>, <span style="color: #0000ff;">'.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">/*
         * use the current object to try to find a relevant class
         * loader, the higher in the stack the exception is caught, the
         * more chance it is this class loader will be of use
         */</span>
        <span style="color: #003399;">ClassLoader</span> fail <span style="color: #339933;">=</span> attemptToFindFail<span style="color: #009900;">&#40;</span>thisJoinPoint.<span style="color: #006633;">getThis</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: #003399;">ClassLoader</span> real <span style="color: #339933;">=</span> classLoaders.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// print debugging here</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>The Rest is Plumbing</h2>
<p>Really, just add you own or download the sources. For your reference this is an example (somewhat abbreviated) output I got when I tested this is in a Tomcat 6 installation:</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #339933;">&gt;&gt;&gt;</span><span style="color: #003399;">ClassNotFoundException</span>
<span style="color: #000000; font-weight: bold;">Class</span> <span style="color: #0000ff;">'se.xec.commons.path.StringPath'</span> was not found in the called <span style="color: #000000; font-weight: bold;">class</span> loader. 
<span style="color: #006633;">However</span>, it was found in another <span style="color: #000000; font-weight: bold;">class</span> loader in the system.
 <span style="color: #339933;">---</span>
Failed to find <span style="color: #000000; font-weight: bold;">class</span> in <span style="color: #003399;">ClassLoader</span><span style="color: #339933;">:</span> WebappClassLoader
 <span style="color: #339933;">-</span> with parent <span style="color: #000000; font-weight: bold;">class</span> loader<span style="color: #339933;">:</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">StandardClassLoader</span>@1a85d38
 <span style="color: #339933;">-</span> with registered code sources<span style="color: #339933;">:</span>
        file<span style="color: #339933;">:/</span>test<span style="color: #339933;">/</span>webapps<span style="color: #339933;">/</span>tester<span style="color: #339933;">/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>classes<span style="color: #339933;">/</span>test<span style="color: #339933;">/</span>Tester.<span style="color: #000000; font-weight: bold;">class</span>
 <span style="color: #339933;">---</span>
<span style="color: #000000; font-weight: bold;">Class</span> found in <span style="color: #003399;">ClassLoader</span><span style="color: #339933;">:</span> WebappClassLoader
 <span style="color: #339933;">-</span> with parent <span style="color: #000000; font-weight: bold;">class</span> loader<span style="color: #339933;">:</span> org.<span style="color: #006633;">apache</span>.<span style="color: #006633;">catalina</span>.<span style="color: #006633;">loader</span>.<span style="color: #006633;">StandardClassLoader</span>@1a85d38
 <span style="color: #339933;">-</span> with registered code sources<span style="color: #339933;">:</span>
        file<span style="color: #339933;">:/</span>test<span style="color: #339933;">/</span>webapps<span style="color: #339933;">/</span>finder<span style="color: #339933;">/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>classes<span style="color: #339933;">/</span>test<span style="color: #339933;">/</span>Tester.<span style="color: #000000; font-weight: bold;">class</span>
        file<span style="color: #339933;">:/</span>test<span style="color: #339933;">/</span>webapps<span style="color: #339933;">/</span>finder<span style="color: #339933;">/</span>WEB<span style="color: #339933;">-</span>INF<span style="color: #339933;">/</span>lib<span style="color: #339933;">/</span>xec.<span style="color: #006633;">se</span><span style="color: #339933;">-</span>commons<span style="color: #339933;">-</span>1.4.4.<span style="color: #006633;">jar</span>
<span style="color: #339933;">&lt;&lt;&lt;</span></pre></td></tr></table></div>

<p>For this test I used two applications. One “finder” application that works as expected and loads the “StringPath” class from a JAR in its library folder, and one “tester” application that cannot find the string path object. As you can see the debug output answers our initial questions, what code source does the class loader know of, and where can the class be found if it exists in the system.</p>
<h2>Some Gotcha&#8217;s</h2>
<ul>
<li>Remember that in Java classes are loaded lazily, which means that if a class exists in a code location it does not automatically mean the class is loaded and hence may not be found even with our nice test harness.</li>
<li>Most application servers have their own variations of class loaders, so you may have to modify my suggestions on a case by case basis. For example, in order for this code to work on Tomcat 6, you need to trap the “find class” method instead of “load class” in the initial pointcut.</li>
<li>If your no class def found errors contains a stack trace, you may be able to traverse the stack frames within the debugging code &#8211; instead of adding an additional catch clause &#8211; to make the code more general.</li>
<li>Some class loader implementations uses class not found exceptions internally when a class is looked up in the parent chain, you may wish to add additional filtering to the debug code to clear up the output.</li>
<li>The aspect should only be instantiated once, so make sure it is declared with “issingleton”.</li>
</ul>
<h2>The End</h2>
<p>This should have given you an idea of what AOP could help you with in regards to debugging class loading. I&#8217;ll leave the details of using and configuring the load time weaver for a rainy day.</p>
<div align="left"><em>Lars J. Nilsson is a founder and Executive Vice President of Cubeia Ltd. He&#8217;s an autodidact programmer, former opera singer, and lunch time poet. You can contact him at lars.j.nilsson in Cubeia&#8217;s domain.</em></div>
<div align="left"></div>
<h2>Resources</h2>
<p><em>The source code for this article</em><br />
<a href="http://www.cubeia.se/docs/articles/cl-debugging/debugging-src.jar" target="_blank">http://www.cubeia.com/docs/articles/cl-debugging/debugging-src.jar</a></p>
<p><em>Demystifying class loading problems, Part 2</em><br />
<a href="http://www.ibm.com/developerworks/java/library/j-dclp2.html" target="_blank">http://www.ibm.com/developerworks/java/library/j-dclp2.html</a></p>
<p><em>AspectJ documentation</em><br />
<a href="http://www.eclipse.org/aspectj/doc/released/devguide/index.html" target="_blank">http://www.eclipse.org/aspectj/doc/released/devguide/index.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2012/11/debugging-class-loading-with-aop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Web Socket Performance</title>
		<link>http://www.cubeia.com/2012/11/web-socket-performance/</link>
		<comments>http://www.cubeia.com/2012/11/web-socket-performance/#comments</comments>
		<pubDate>Fri, 23 Nov 2012 13:07:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=991</guid>
		<description><![CDATA[We&#8217;re gearing up for the 1.8 release of Cubeia Firebase which will include native server-side support for HTML5 in the form of WebSockets and Comet, and naturally we want to make sure the performance is up to our normal standard. In this article we&#8217;l compare the standard Firebase binary socket communication with web sockets. Setup The tests were [...]]]></description>
				<content:encoded><![CDATA[<p>We&#8217;re gearing up for the 1.8 release of Cubeia Firebase which will include native server-side support for HTML5 in the form of <a href="http://en.wikipedia.org/wiki/WebSocket">WebSockets</a> and <a href="http://en.wikipedia.org/wiki/Comet_%28programming%29">Comet</a>, and naturally we want to make sure the performance is up to our normal standard. In this article we&#8217;l compare the standard Firebase binary socket communication with web sockets.<span id="more-991"></span></p>
<h2>Setup</h2>
<p>The tests were performed on Cubeia Ltd&#8217;s load test environment in Stockholm, Sweden. The participating server was configured as follows:</p>
<ul>
<li>Dual Core, Intel Xeon 2.4 GHz</li>
<li>Linux CentOS, Kernel 2.6.18 (EPOLL enabled)</li>
<li>Oracle Java HotSpot 64-Bit Server VM (16.3-b01, mixed mode)</li>
<li>1280M allocated heap memory</li>
<li>Cubeia Firebase 1.7-EE Release Candidate 3</li>
</ul>
<p>The Cubeia Firebase load test game was used, and the sample values were:</p>
<ul>
<li>CPU load (&#8220;cpu idle&#8221; sampled from system)</li>
<li>Throughput (number of game actions executed)</li>
<li>Response time (average sampled from the bots)</li>
<li>Bandwidth (sampled from system)</li>
</ul>
<h2>Binary vs Web Socket</h2>
<p>The semantics between the two sockets are similar, both are TCP-based using control characters for frame-demarcation. The main difference is that of the frame payload, whereas the standard binary socket uses a native Styx binary packaging, the Firebase implementation of web sockets uses the same packet format encoded in <a href="http://en.wikipedia.org/wiki/JSON">JSON</a> which is a text-based encoding over UTF-8. This will impact the bandwidth reading, and also the CPU performance.</p>
<h2>Throughput</h2>
<p>We&#8217;ll start with throughput as it is an important factor for reading the other results. The load test uses a bot implementation that sends one event per second and bot. Thus the theoretic MAX value for 100 bots are 100 events per second.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/throughput.png"><img class="alignnone size-full wp-image-992" title="throughput" src="http://www.cubeia.com/wp-content/uploads/2012/11/throughput.png" alt="" width="600" height="371" /></a></p>
<p>The above chart shows the theoretical max, which equals the number of started bots, with the actual throughput in terms of events per second. We can see that the performance is very similar between the two sockets. In fact, it&#8217;s not until approx. 1500 events per second the measured difference is bigger than 1%.</p>
<p>For the rest of the performance results below it pays to  remember that the throughput of web sockets trailed off around 1500 events per second as all results will be reported with the theoretical max events per second in order to make them comparable.</p>
<h2>CPU Idle</h2>
<p>The chart below show the idle percentage on the server as the load increases.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/cpu.png"><img class="alignnone size-full wp-image-994" title="cpu" src="http://www.cubeia.com/wp-content/uploads/2012/11/cpu.png" alt="" width="600" height="371" /></a></p>
<p>It&#8217;s interesting to see that both sockets shows a decline in CPU use around 1500 events per second. This corresponds to the decreasing web socket through put, and one can clearly see on the graph that the diminished throughput makes the CPU utilization grow in parallel between the sockets.</p>
<h2>Response Time</h2>
<p>Now lets look at response times. These values are sampled from the bot server and averaged over the last 1000 requests. As such it represents a sliding window over the last 1000 events.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/response.png"><img class="alignnone size-full wp-image-995" title="response" src="http://www.cubeia.com/wp-content/uploads/2012/11/response.png" alt="" width="600" height="371" /></a></p>
<p>Again we see exactly where the throughput of the web socket implementation started diverge. Still, at 2000 events per second the response times are well under 60 milliseconds which is more than enough.</p>
<h2>Bandwidth</h2>
<p>The bandwidth should be a fixed percentage higher in the web socket implementation than that of the binary socket. The size of the game data does not matter so much as Firebase treats the game data as a byte array, and will Base64-endcode it during transport.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/bandwidth.png"><img class="alignnone size-full wp-image-993" title="bandwidth" src="http://www.cubeia.com/wp-content/uploads/2012/11/bandwidth.png" alt="" width="600" height="371" /></a></p>
<p>At 1500 the web socket bandwidth tapers off as the throughput slows down. Up to this point we can see that web sockets consume approx 20% more bandwidth than does the corresponding binary socket. However, this test was performed<em>without</em> measuring lobby data which would probably slew the result significantly.</p>
<h2>Conclusion</h2>
<p>After this first glance we can conclude that web sockets performs really well compared to their binary counterparts.  Even the bandwidth difference is not too concerning when the lobby data is not included. For very intensive applications binary sockets still reign supreme but in most cases web socket will prove to be more than enough.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2012/11/web-socket-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Singleton Scalability</title>
		<link>http://www.cubeia.com/2012/11/singleton-scalability/</link>
		<comments>http://www.cubeia.com/2012/11/singleton-scalability/#comments</comments>
		<pubDate>Fri, 23 Nov 2012 12:56:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.cubeia.com/?p=982</guid>
		<description><![CDATA[This article looks at a simple scalability scenario using so called &#8220;singleton&#8221; configurations of Cubeia Firebase 1.7 Enterprise Edition. It is looking at high load scenarios on limited hardware, and will discuss the implications of the test result. Topology When a Firebase server is used stand-alone the configuration is called &#8220;singleton&#8221;, and that server will [...]]]></description>
				<content:encoded><![CDATA[<p>This article looks at a simple scalability scenario using so called &#8220;singleton&#8221; configurations of Cubeia Firebase 1.7 Enterprise Edition. It is looking at high load scenarios on limited hardware, and will discuss the implications of the test result.<span id="more-982"></span></p>
<h2>Topology</h2>
<p>When a Firebase server is used stand-alone the configuration is called &#8220;singleton&#8221;, and that server will run all necessary roles complete functionality (master, client, game and tournament). Normally a multi-node Firebase Cluster is configured in a role based topology where different servers handle different roles in the cluster. For example, you may run client sessions on dedicated machines and all game play on others. However, for smaller installations it may be easier to run several singleton servers side by side.</p>
<h2>Setup</h2>
<p>The tests were performed on Cubeia Ltd&#8217;s load test environment in Stockholm, Sweden. The participating servers were configured as follows:</p>
<ul>
<li>Dual Core, Intel Xeon 2.4 GHz</li>
<li>Linux CentOS, Kernel 2.6.18 (EPOLL enabled)</li>
<li>Oracle Java HotSpot 64-Bit Server VM (16.3-b01, mixed mode)</li>
<li>1280M allocated heap memory</li>
<li>Cubeia Firebase 1.7-EE Release Candidate 3</li>
</ul>
<p>As load test game Cubeia Poker was used (nightly build 18th Aug 2011), and the sample values were:</p>
<ul>
<li>CPU load (&#8220;cpu idle&#8221; sampled from system)</li>
<li>Hands per minute (poker hands executed)</li>
<li>Actions per second (number of game actions executed)</li>
</ul>
<h2>Game Configuration</h2>
<p>The game was configured using one speed for all tables, and 10 seats per table. The bots were configured to react within 2.5 and 3.3 seconds on normal actions (see &#8220;player speed and hands per minute&#8221; below&#8221;).</p>
<p>No external integrations such as wallet or databases were used in order to test the Firebase performance isolated. In real world scenarios the performance would be greatly affected by the latency and throughput of such integrations.</p>
<p>All bots were subscribing to the entire lobby. For a large installation (10 000 players or more) this is not recommended as it generates a massive load. Cubeia Firebase has the ability to partition the lobby so that players only needs to subscribe to a part of the whole lobby.</p>
<h3>Actions Versus Hands</h3>
<p>The actions sampled represents the total number of actions executed by the poker game. This value is directly linked to hands per minute as shown below, using samples from the single server scenario.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/chart_4.png"><img class="alignnone size-full wp-image-987" title="chart_4" src="http://www.cubeia.com/wp-content/uploads/2012/11/chart_4.png" alt="" width="600" height="371" /></a></p>
<p>As the graph shows, the relationship between hands per minute and actions per second appears to be fixed. Exploring the the full sample set the relationship between these two values seems to fluctuate between 2.3 and 2.6 (events per second / hands per minute).</p>
<h3>Player Speed and Hands per Minute</h3>
<p>Another relationship which is expected to scale linearly is between the number of players and hands per minute. The bots used for this test reacted to requests in between 3.3 and 2.5 seconds, thus a full table with 10 players is expected to generate approximately one event every 2.8 seconds and, for example, 2 000 players (200 tables) approximately 56 events per second.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/chart_5.png"><img class="alignnone size-full wp-image-984" title="chart_5" src="http://www.cubeia.com/wp-content/uploads/2012/11/chart_5.png" alt="" width="600" height="371" /></a></p>
<p>Again the graph is sampled from a single server. The relationship between the number of tables and the number of of events seems to by slightly less than assumed above, but this is to be expected when hand start/end and system latency is included in the calculation.</p>
<h2>Performance</h2>
<h3>Limiting Factors</h3>
<p>Each test run was ended when the CPU load of the machines reached up towards 80%. In reality the limiting factor was the CPU in relationship with the Java VM Garbage Collector (GC): as the number of player grows, the initial snapshot for lobby subscription gets larger, and when the available overhead gets too small the GC will fail to release enough memory. Large installations (10 000 players or more) should consider allocation significantly more memory to server &#8220;client&#8221; roles.</p>
<p>This limitation is not unique for singleton-style clusters however: even in mixed topologies large lobbies will put higher demands on the client role heap size.</p>
<h3>CPU</h3>
<p>The following chart shows the CPU load for 1-3 server together with the corresponding number of players connected.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/chart_1.png"><img class="alignnone size-full wp-image-985" title="chart_1" src="http://www.cubeia.com/wp-content/uploads/2012/11/chart_1.png" alt="" width="600" height="371" /></a></p>
<p>We can see that the load peaked at 16 000 players for a single server, 24 000 for 2 servers and 40 000 for three servers.</p>
<p>Going from 1 to 2 server increases the maximum load with approximately 50%. This is because a single server does not have to replicate state for fail over, and as such will not scale linearly compared to a single server.</p>
<h3>Hands per Minute</h3>
<p>The following chart shows the hands per minute for 1-3 servers together with the corresponding number of players connected.</p>
<p><a href="http://www.cubeia.com/wp-content/uploads/2012/11/chart_2.png"><img class="alignnone size-full wp-image-986" title="chart_2" src="http://www.cubeia.com/wp-content/uploads/2012/11/chart_2.png" alt="" width="600" height="371" /></a></p>
<p>The game performance scales almost perfectly across all servers, and the peak was reached at 2 763 hand per minute when 40 000 players were connected.</p>
<p>The speed of the bots seems to correspond to a factor of 13-14 in relation to the hands per minute, so for example, we would expect approximately 1 400 hands per minute for 20 000 players.</p>
<h2>Conclusion</h2>
<p>Cubeia Firebase 1.7 Enterprise Edition shows healthy performance and scalability numbers even when configured to use singleton nodes. The hardware for the tests is a few years old and is lacking on RAM, it is recommended that very large installations (20 000 players or more) is set-up on hardware with significantly more memory available.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cubeia.com/2012/11/singleton-scalability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
