<?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>Technical Notes &#187; architecture</title>
	<atom:link href="http://blog.anthonychaves.net/category/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.anthonychaves.net</link>
	<description>Life is software and jujitsu</description>
	<lastBuildDate>Tue, 16 Feb 2010 22:15:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Nati Shalom to speak at Boston Scalability Group next Wednesday</title>
		<link>http://blog.anthonychaves.net/2009/02/11/nati-shalom-to-speak-at-boston-scalability-group-next-wednesday/</link>
		<comments>http://blog.anthonychaves.net/2009/02/11/nati-shalom-to-speak-at-boston-scalability-group-next-wednesday/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 18:02:52 +0000</pubDate>
		<dc:creator>Anthony Chaves</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://blog.anthonychaves.net/?p=130</guid>
		<description><![CDATA[There is an interesting BostonSUG meeting next week at the IBM Innovation center in Waltham, MA.  GigaSpaces CTO Nati Shalom will speak on cloud-based infrastructure, space-based architecture, scalability with latency in mind and more.  BostonSUG web site for more details: http://www.bostonsug.org/2009/02/09/nati-shalom-speaking-on-february-18/
I&#8217;ll be there!
]]></description>
			<content:encoded><![CDATA[<p>There is an interesting BostonSUG meeting next week at the IBM Innovation center in Waltham, MA.  GigaSpaces CTO Nati Shalom will speak on cloud-based infrastructure, space-based architecture, scalability with latency in mind and more.  BostonSUG web site for more details: http://www.bostonsug.org/2009/02/09/nati-shalom-speaking-on-february-18/</p>
<p>I&#8217;ll be there!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anthonychaves.net/2009/02/11/nati-shalom-to-speak-at-boston-scalability-group-next-wednesday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dummy Code (Quick&#8217;n&#039;Dirty vs. Engineered)</title>
		<link>http://blog.anthonychaves.net/2009/02/04/dummy-code-quickndirty-vs-engineered/</link>
		<comments>http://blog.anthonychaves.net/2009/02/04/dummy-code-quickndirty-vs-engineered/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 22:34:13 +0000</pubDate>
		<dc:creator>Anthony Chaves</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[career]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.anthonychaves.net/?p=125</guid>
		<description><![CDATA[When creating software, two people will never write the same implementation of a method or system of non-trivial design.  Creating software is a problem solving process and there are usually many ways to solve one problem.  The solutions may differ in elegance and efficiency while giving the same output for a given set of inputs.  [...]]]></description>
			<content:encoded><![CDATA[<p>When creating software, two people will never write the same implementation of a method or system of non-trivial design.  Creating software is a problem solving process and there are usually many ways to solve one problem.  The solutions may differ in elegance and efficiency while giving the same output for a given set of inputs.  A correct solutions is a correct solution regardless of implementation.<span id="more-125"></span></p>
<p>Building software modules within a team requires communicating, at a minimum,  method or class signatures and a general idea of the functionality.  This may include a detailed design document clearly specifying method signature and a pseudo-code implementation or method stubs and comments about what the method should do right in the source file.  One thing that should never be used for communicating a signature and functionality is dummy code.</p>
<p>Dummy code looks like real code.  It is real code but it rarely works.  Even if it compiles it doesn&#8217;t produce the correct result when run.  Nor are there any tests that prove it (in)correct.  Dummy code exists only for the sake of its author&#8217;s gratification.</p>
<p>Rather than talk about the desired functionality through some more productive means the dummy code author thinks he is helpfully providing a guesstimate of correct implementation.  What he has actually done is provide a jumbled mess of non-working code cleverly disguised as a working part of the project when he checks it in to the SCM.  The dummy code author thinks someone else will come along and provide the correct implementation &#8220;later&#8221;.</p>
<p>What he doesn&#8217;t realize is that his dummy code is almost indistinguishable from code that should be part of the project.  The next person to try to reuse this code is in for hours of WTF moments trying to figure out WTF the code is supposed to do and why it&#8217;s got code branching five levels deep.</p>
<p>At my first post-college job I had a wonderful mentor.  Thys (pronounced <em>Tays</em>, like &#8220;taste&#8221; without the second &#8216;t&#8217;) and I were talking one day when he asked me a question.  &#8220;Anthony, if you were given a task of writing software that would only be run once would you do it quick-and-dirty or with a well-measured, engineered approach?&#8221;</p>
<p>How bad could &#8220;quick-and-diry&#8221; be if the software would run only once?  I thought about it for a moment before answering.  Quick and dirty.</p>
<p>Thys said he would never write quick and dirty software.  Doing so figuratively creates a  monkey on the developerment team&#8217;s back.  The software that only needs to run once inevitably needs to run a second time and a third time and eventually run regularly.  Thys helped me realize that software evolves and escapes.  Useful software will run indefinitely.  Any time and effort saved on the initial write will be lost 10 times (I made that number up.  It is actually higher.  Any want to provide real data or examples?) over on the maintenance, bug fixes and rewrites.</p>
<p>Writing dummy code is writing software quick and dirty without any idea of the implementation details.  Bad code and bad algorithms.  The worst of both worlds.  It&#8217;s been a long time since Thys and I had that conversation but the years have proven him right again and again.  Any code worth checking in to SCM is worth writing well.  That includes unit tests.</p>
<p>Dummy code has no place in SCM.  If you&#8217;re not going to correctly implement a method you stub out then don&#8217;t provide an implementation at all.  Leave some comments around the method stub if you have to.  Open a ticket in the issue tracking system to let someone know the method needs an implementation and describe the input and output.  Let the implementer determine which algorithms and data structures to use.</p>
<p>Dummy code is a hazard to software projects.  It violates the principle of least astonishment.  Next time you think about writing some remember that the next person that uses the code will waste time figuring out why it doesn&#8217;t work as expected.</p>
<p>If you check code in to your SCM where other people can pull it, take a look at what you&#8217;re checking in.  Does it work?  Does it work well?  Are there tests that prove it?  Helping someone by coding less is sometimes the best help of all.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anthonychaves.net/2009/02/04/dummy-code-quickndirty-vs-engineered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Industry Ignorance</title>
		<link>http://blog.anthonychaves.net/2009/01/22/industry-ignorance/</link>
		<comments>http://blog.anthonychaves.net/2009/01/22/industry-ignorance/#comments</comments>
		<pubDate>Thu, 22 Jan 2009 22:27:41 +0000</pubDate>
		<dc:creator>Anthony Chaves</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://blog.anthonychaves.net/?p=106</guid>
		<description><![CDATA[Today I let out a dejected sigh after reading a response to my latest post on the Joel on Software message board.  My post was just a reminder about the BostonScalability User Group meeting that takes place next Wednesday the 28th.  I post the meeting announcements on JoS and a good number of people hear [...]]]></description>
			<content:encoded><![CDATA[<p>Today I let out a dejected sigh after reading a response to my latest post on the Joel on Software message board.  My post was just a reminder about the BostonScalability User Group meeting that takes place next Wednesday the 28th.  I post the meeting announcements on JoS and a good number of people hear about the meetings from the JoS board.  Every month a few new people tell me they found the group through JoS.  So why did I sigh after reading the response to the meeting reminder?</p>
<p><span id="more-106"></span>I don&#8217;t make any money running the group.  In fact it costs me money.  I do a good amount of planning, coordinating, buying, booking and raffle prize finding for the group.  I love seeing 30+ people show up for our after work meetings.   It&#8217;s a lot of work but I do it because I am passionate about emerging trends in application scalability.  It&#8217;s a labor of love that I find professionally and personally rewarding.  Like all good geeks I maintain a healthy hobby writing software outside business hours.</p>
<p>I&#8217;m interested in building bigger, better software.  Batch applications, database interactions, web applications, CPU intensive algorithims should be as effective as possible.  Effective does not necessarily mean efficient.  Effectiveness is based on price, time-to-market, performance, maintenance cost, etc.  Analyzing these facets is important. The tools used to arrive at the solution are important, too.</p>
<p>BostonSUG has wonderful speakers who generously donate their time to speak at our meetings.  These people come in from all over the country.  Just a few examples, we&#8217;ve hosted Orion Letizi and Nikita Ivanov from San Francisco, Billy Newport from Minnesota and Mike Culver from Washington.  We&#8217;ve had numerous local speakers who we appreciate just as much as those that fly to see us.  Patrick Peralta, Tom O&#8217;Hare and Rakesh Chaudhary had large audiences.  Each of these speakers is an expert in a different facet of building scalable applications.  They are industry leaders in compute clouds, data grids, object caching, streaming media and more.</p>
<p>One thing we haven&#8217;t touched yet is building a web site that performs well.  The person that replied to the meeting reminder said:</p>
<blockquote><p>save your time:<br />
only put strings in session; and only put one item per-user in the session; unless they are doing some heavy form processing.<br />
use native clustering.<br />
put professional load balancer in from.<br />
max pipe.</p></blockquote>
<p>Thanks.  That is a helpful reply.  It immediately invalidates the hours of insightful discussion we&#8217;ve had at past BostonSUG meetings that have spent less than five minutes total dedicated to the problem to which he so generously offers his solution&lt;/sarcasm&gt;.</p>
<p><img class="alignnone size-medium wp-image-107" title="traditional-web-architecture" src="http://blog.anthonychaves.net/wp-content/uploads/2009/01/traditional-web-architecture-300x225.png" alt="traditional-web-architecture" width="300" height="225" /></p>
<p>This is a picture of what is described in the reply post.  As an industry we have known this works for a long time.  That&#8217;s why we don&#8217;t talk about the architecture depicted by this diagram at BostonSUG.  Sure, we&#8217;ll talk about HOW an app server achieve scalability.  We&#8217;ll talk about the implementation, not just about using JBoss or Mongrel.  We got a good look inside GridGain.  We had a guided tour around Terracotta.  BostonSUG evokes deeper discussion than &#8220;small sessions, load balancer, database cluster, done!&#8221;.  <em>You should do that anyway</em>.</p>
<p>Past meetings aside we have a lot to talk about this year.  Rails 3, Java 7, CloudFront, Hibernate Shards, Google AppEngine, tons of topics that push the industry foward.  If you&#8217;re interested in evolving and not building the same old software then come to BostonSUG.  If you&#8217;re interested in building what we know works (and have known since pre-2000) then it&#8217;s not the meeting for you.</p>
<p>I didn&#8217;t intend for this to turn into a meeting plug but I might as well include the link to the meeting announcement.  <a href="http://www.bostonsug.org/2009/01/05/january-28-2009-meeting-announcement/">Wednesday January 28, 2009 @ 6 p.m.  IBM Innovation Center Waltham, MA 02451</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anthonychaves.net/2009/01/22/industry-ignorance/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>&#8220;Deep Integration&#8221; is a waste of time</title>
		<link>http://blog.anthonychaves.net/2009/01/20/deep-integration-is-a-waste-of-time/</link>
		<comments>http://blog.anthonychaves.net/2009/01/20/deep-integration-is-a-waste-of-time/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 12:53:58 +0000</pubDate>
		<dc:creator>Anthony Chaves</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://blog.anthonychaves.net/?p=89</guid>
		<description><![CDATA[It&#8217;s 2009, right?  As an industry we&#8217;ve cast off heavyweight solutions and processes in favor of lightweight software and Agility.  Now we create RESTful APIs as part of this push for more meaningful software development.  Web applications communicate with each other via RESTful APIs these days.  YouTube, Yahoo!, Twitter, Facebook, Google Apps, Digg, everyone has [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s 2009, right?  As an industry we&#8217;ve cast off heavyweight solutions and processes in favor of lightweight software and Agility.  Now we create RESTful APIs as part of this push for more meaningful software development.  Web applications communicate with each other via RESTful APIs these days.  YouTube, Yahoo!, Twitter, Facebook, Google Apps, Digg, everyone has a RESTful API.  Integrating two applications has never been easier.  Punch a hole in the firewall for a known host on the other side, give their developers an API key and let them get to work.  Couldn&#8217;t be easier, could it?  This is why you&#8217;ll never believe what I heard last week.</p>
<p><span id="more-89"></span></p>
<p>I was told, quite authoritatively, a better way of integrating with an application is to give the other application developers your messaging system and have them integrate with that.  Not just the message broker but the entire end-to-end message system, producers and consumers included.  I panicked when I heard this because I knew this guy was serious.  He wanted to build an application like this?!</p>
<div id="attachment_90" class="wp-caption alignnone" style="width: 310px"><img class="size-medium wp-image-90" title="deep_integration" src="http://blog.anthonychaves.net/wp-content/uploads/2009/01/deep_integration-300x225.png" alt="Deep Integration" width="300" height="225" /><p class="wp-caption-text">Deep Integration</p></div>
<p>The messaging platform needs some kind of web server to handle the RESTful calls coming from the client application.  It needs a message broker, ActiveMQ, RabbitMQ, WebSphereMQ, take your pick.  It needs some way of consuming messages produced by the web/application server.  It needs at least one dedicated server to run it.</p>
<p>Hardening an appliance for use on a customer site is significantly more time consuming and expensive than running that platform in-house.  The appliance has to &#8220;just work&#8221; for the customer.  The customer also has access to the provider database.  Notice how the message consumer communicates with that provider database through both corporate firewalls.  The provider database is exposed and the customer has a box with the credentials on their premises.</p>
<p>The push for this &#8220;deep integration&#8221; with the customer was so that their developers wouldn&#8217;t have to learn how to make RESTful API calls.  Instead they would learn how to administer the provider platform (keeping the database credentials safe, of course), learn the Ruby/Java/C#/C++ API to put messages on the queue and learn the RESTful API anyway because that&#8217;s the easiest way to interact with the message platform.</p>
<p>I can&#8217;t help but wonder why the customer needs to be bothered with the provider message platform.  The provider isn&#8217;t in the business of providing a message platform.  The provider only needs to provide the services the customer is buying.  Pushing some messaging platform on them doesn&#8217;t help them get their job done.  It&#8217;s a waste of time, effort and money.  Giving them the messaging platform and saying, &#8220;here, you administer it&#8221; shows laziness and ignorance in the provider.  What could possibly be gained from making the customer use the messaging platform?  It makes the provider&#8217;s tech guys feel good because they worked on what seems like a big, important project.</p>
<div id="attachment_91" class="wp-caption alignnone" style="width: 310px"><img class="size-medium wp-image-91" title="restful_integration" src="http://blog.anthonychaves.net/wp-content/uploads/2009/01/restful_integration-300x225.png" alt="RESTful Integration" width="300" height="225" /><p class="wp-caption-text">RESTful Integration</p></div>
<p>Most of the time this works just fine.  Keep your message platforms to yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anthonychaves.net/2009/01/20/deep-integration-is-a-waste-of-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scalability round-table/forum on January 28</title>
		<link>http://blog.anthonychaves.net/2009/01/13/scalability-round-tableforum-on-january-28/</link>
		<comments>http://blog.anthonychaves.net/2009/01/13/scalability-round-tableforum-on-january-28/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 21:03:28 +0000</pubDate>
		<dc:creator>Anthony Chaves</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.anthonychaves.net/?p=80</guid>
		<description><![CDATA[The Boston Scalability User Group is hosting a technology round-table meeting on Wednesday January 28th at 6 p.m.  The meeting is at the IBM Innovation Center in Waltham, MA.
This is the first time we&#8217;ve done the round-table style meeting and I&#8217;m excited to see how it goes.  Guests are encouraged to come prepared with questions, [...]]]></description>
			<content:encoded><![CDATA[<p>The Boston Scalability User Group is hosting a technology round-table meeting on Wednesday January 28th at 6 p.m.  The meeting is at the IBM Innovation Center in Waltham, MA.</p>
<p>This is the first time we&#8217;ve done the round-table style meeting and I&#8217;m excited to see how it goes.  Guests are encouraged to come prepared with questions, answers and opinions on application scalability tools, strategies and designs.  Hot topics will include platform and software stack, cloud computing and resources, vendor tools and support and CDNs. Those are my guesses about hot topics doesn&#8217;t mean the meeting is limited to those topics.</p>
<p>Guests, be the regular or first-timers, will drive the direction of the discussion.  We&#8217;ll talk about solving technical problems based on past experience or serve as an advisory panel on where and when to use a particular tool.</p>
<p>Full meeting details are at the <a href="http://www.bostonsug.org">BostonSUG web site</a>.  We ask that you sign up for the meeting at the <a href="http://www.bostonsug.org/meeting-registration/">meeting registration page</a> so we have an idea of how much food to buy.  There will be snacks and bottled water at this meeting.</p>
<p>Hope to see everyone on the 28th at 6 p.m.!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anthonychaves.net/2009/01/13/scalability-round-tableforum-on-january-28/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring Web MVC and the benefits of pagination</title>
		<link>http://blog.anthonychaves.net/2008/03/14/spring-web-mvc-and-the-benefits-of-pagination/</link>
		<comments>http://blog.anthonychaves.net/2008/03/14/spring-web-mvc-and-the-benefits-of-pagination/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 08:05:06 +0000</pubDate>
		<dc:creator>Anthony Chaves</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[criteria]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.anthonychaves.net/java/2008/03/14/spring-web-mvc-and-the-benefits-of-pagination</guid>
		<description><![CDATA[Lately I&#8217;ve been working on a project that keeps my web bookmarks sync&#8217;d across multiple computers and different web browsers.  The project is implemented in Java using JBoss 4.2.2, MySQL 5.0 and Spring 2.0.  It&#8217;s not a very big project right now, only about 40 class files and some small number of configuration [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve been working on a project that keeps my web bookmarks sync&#8217;d across multiple computers and different web browsers.  The project is implemented in Java using JBoss 4.2.2, MySQL 5.0 and Spring 2.0.  It&#8217;s not a very big project right now, only about 40 class files and some small number of configuration files, but the amount of data the application deals with can get fairly large.<br />
<span id="more-48"></span><br />
Since this app isn&#8217;t the only way to manage ones bookmarks that everyone has used since the dawn of the web, a feature to import bookmarks from browsers was very high on the to-do list.  So across the set of different browsers I&#8217;ve used on the different computers, and the backed up bookmarks that survived system formats I have around 700 bookmarks in total.  That probably isn&#8217;t a whole lot, but that many spread across thousands of users can add up quickly.</p>
<p>I used jhat to find out that each bookmark object uses 1.5 kilobytes of memory.  It doesn&#8217;t take much to see that a LOT of bookmarks will fit into 8 gigs of memory on a medium sized server.  It would take hundreds of thousands of users to generate enough bookmark data to fill that memory.  At this point it&#8217;s clear the application server box can handle the data load (that isn&#8217;t to say that it can handle the network load, however).</p>
<p>I spent some time coming up with a nice data model and ORM design so accessing the data once it&#8217;s in memory is lightning fast, maybe even faster.  But what about when it&#8217;s on a hard disk, deep in the database?  Dragging my 700 bookmarks out of the database when I only want to view the 25 most frequently visited is a bit overkill, especially when you consider dragging everyone else&#8217;s bookmarks out at the same time.  Even though this is still a small-time application I decided to be nice to the database anyway and implement some kind of paging solution.  Spring Web MVC doesn&#8217;t offer much that I&#8217;m aware of in regard to pagination help so it looks like I&#8217;m on my own.</p>
<p>Pagination is something that must take place in the model with the help of the view.  Right away we&#8217;ve got two things to deal with, though it&#8217;s best to deal with them in isolation.  The first thing I did was get the model right.  I&#8217;m using Hibernate for ORM and the Criteria API makes it easy to set offsets and limits.  That is, I can ask for the 50 next items (limit) starting at row 20 (offset).</p>
<p>The Criteria API is great at getting your data into a workable format without HQL or SQL (not that either of them is a bad thing.  I enjoy working with them).  Let&#8217;s take a look at the method that gets some new bookmarks.</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">List&lt;Bookmark&gt; getNewestBookmarks</font><font color="#000000">(</font><font color="#7f0055"><strong>int </strong></font><font color="#000000">offset, </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">numBookmarks</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#000000">DetachedCriteria c = DetachedCriteria.forClass</font><font color="#000000">(</font><font color="#000000">Bookmark.</font><font color="#7f0055"><strong>class</strong></font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">c.addOrder</font><font color="#000000">(</font><font color="#000000">Order.desc</font><font color="#000000">(</font><font color="#2a00ff">"createdDate"</font><font color="#000000">))</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return </strong></font><font color="#000000">getHibernateTemplate</font><font color="#000000">()</font><font color="#000000">.findByCriteria</font><font color="#000000">(</font><font color="#000000">c, offset, numBookmarks</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></code></td>
</tr>
</table>
<p>So this method gets the model for us, but where do the offset and limit come from?  From the controller, of course.  This method is called from the controller like so:</p>
<p class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
<tr>
<td align="left" nowrap="nowrap" valign="top"><code><br />
<font color="#ffffff">  </font><font color="#7f0055"><strong>public </strong></font><font color="#000000">ModelAndView newest</font><font color="#000000">(</font><font color="#000000">HttpServletRequest request, HttpServletResponse response</font><font color="#000000">) {</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">numberOfBookmarks = requestUtils.getSafeValueFromRequest</font><font color="#000000">(</font><font color="#000000">request, </font><font color="#2a00ff">"numberOfBookmarks"</font><font color="#000000">, </font><font color="#990000">250</font><font color="#000000">, defaultNumberOfNewest</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>int </strong></font><font color="#000000">offset = requestUtils.getSafeValueFromRequest</font><font color="#000000">(</font><font color="#000000">request, </font><font color="#2a00ff">"offset"</font><font color="#000000">, </font><font color="#990000">300</font><font color="#000000">, </font><font color="#990000">0</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><br />
<font color="#ffffff">    </font><font color="#000000">List bookmarks = bookmarkService.getNewestBookmarks</font><font color="#000000">(</font><font color="#000000">offset, numberOfBookmarks</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><br />
<font color="#ffffff">    </font><font color="#000000">Map model = requestUtils.generateBookmarkModel</font><font color="#000000">(</font><font color="#000000">offset, numberOfBookmarks, </font><font color="#990000">300</font><font color="#000000">, bookmarks</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#000000">model.put</font><font color="#000000">(</font><font color="#2a00ff">"bookmarkListName"</font><font color="#000000">, </font><font color="#2a00ff">"Newest Bookmarks"</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">    </font><font color="#7f0055"><strong>return new </strong></font><font color="#000000">ModelAndView</font><font color="#000000">(</font><font color="#2a00ff">"index"</font><font color="#000000">, model</font><font color="#000000">)</font><font color="#000000">;</font><br />
<font color="#ffffff">  </font><font color="#000000">}</font></code></td>
</tr>
</table>
<p>After sanity checking the offset and limit received from the request they are passed on to the getNewestBookmarks method to create and execute a somewhat unsightly query.  At this point, rather than gathering up all 700 of my bookmarks only 25 or so are returned.  What if I one day want to view the top 50 most visited bookmarks though?  Or what if I want to scroll through them one page at a time?  Passing in 0, 25 for the offset and limit of every method call won&#8217;t cut it.  The view needs to tell us how many bookmarks to retrieve and where to start the search.</p>
<p>Let&#8217;s say I&#8217;m viewing the top 25 bookmarks in my collection and I want to view 26-50.  Somehow the view has to tell the controller to tell the model about the  desired offset and limit.   This can be done by passing them in as request parameters.  In the code sample above, the HttpServletRequest object passed in to the controller contains values for offset and limit (numberOfBookmark) variables.  The JSP code below shows how to pass these parameters when a user clicks a link. (Actually I&#8217;m having a hard time getting the JSP to show up right when the code is rendered as HTML.  Just click the link and view the entire file instead.)</p>
<p><a href="http://blog.anthonychaves.net/wp-content/uploads/2008/03/operations.jsp" title="operations">JSP Pagination Operations</a></p>
<p>This page uses the JSTL core tag library to build the links that display the &#8220;previous/next/more/less&#8221; options.  Right after the body tag there is code to create four URLs, one for each action.  Each one starts off with a name and a value.  c:url var=&#8221;viewMoreUrl&#8221; value=&#8221;" creates a page-scoped variable called viewMoreUrl.  This variable will later be used to display the link that allows me to display five more bookmarks when I view the list.  The value is left blank which tells the tag to use the current base URL in creating the new one.  If I&#8217;m on a page that is located at /bookmarks/pages/viewUserBookmarks.html the new URL will start off as /bookmarks/pages/viewUserBookmarks.html.</p>
<p>Adding parameters to a URL is easy.  Using the c:param tag we get c:param name=&#8221;numberOfBookmarks&#8221; value=&#8221;${numberOfBookmarks + 5}&#8221;.  This tag appends a variable called numberOfBookmarks to the base URL described in the previous paragraph.  The value is a JSP expression that uses the numberOfBookmarks value passed in the model and increases it by five to pass back in the request.  Because we want the link only to display five more bookmarks and not change the offset that value will remain the value passed out in the model.  That gives us a URL that looks like /bookmarks/pages/viewUserBookmarks.html?numberOfBookmarks=30&amp;offset=0.</p>
<p>When this URL is accessed the request values for offset and numberOfBookmarks are exposed in the HttpServletRequest object for use by the controller.  When the getNewestBookmarks method is called the offset and limit are 0 and 30 instead of 0 and 25.</p>
<p>Obtaining a new offset value is done like getting a new limit value.  We start off with the same base URL and leave the numberOfBookmarks value unchanged.  We need to change the offset value though. c:param name=&#8221;offset&#8221; value=&#8221;${offset + numberOfBookmarks}&#8221; creates the offset value of the URL.  If we are viewing the newest bookmarks (offset 0)  and we are viewing 30 bookmarks when we click the link we should see bookmarks 31-60.</p>
<p>Here is an interesting thing to consider: what if a user goes to the second page using the default values.  The user will be viewing bookmarks 26-50.  The user then clicks the &#8220;view more&#8221; link three times and is now viewing 40 bookmarks.  The &#8220;previous&#8221; will now request that the offset be -15.  Unfortunately we can&#8217;t have negative bookmarks.  In this case the controller has some sanity checking built in to it.  The input parameter values must always be validated before they are used.  The controller uses a utility method to get a safe value for the offset and limit and ensures that neither can be a negative value.  This safe value is then passed back to the view once the model has been built.  Even though the offset in the request says -15 the controller will only go as low as 0.  More interesting work takes place in the generateBookmarksModel method, which I will talk about more next week.</p>
<p>What did I learn from making this effort?  Well, giving 8GB of RAM to an application server is a little overkill for a domain model like this.  The pagination that I came up with is still rudimentary, but a little more work could add more features, namely displaying page number links and the ability to change the number of bookmarks added at a time.</p>
<p>What is gained from this effort?  Being nice to the database opens up a few doors.  It dramatically improves scalability because it allows these requests to be stateless.  If an app server queried the database for all of my bookmarks then my session would have to be directed to that app server every time I made a request in order to not incur the cost of hitting the database again by another app server.  If round-robin load balancing is used the Hibernate session on each app server would contain a copy of my data and that&#8217;s a waste of resources, most notably it&#8217;s a hit to the database that didn&#8217;t have to happen.</p>
<p>Reducing the load on the database by getting only what we need and stateless sessions gives me the option of scaling the database with less difficulty.  A mostly-read application can get by with fewer hits to the write master and do a majority of their work from read-only slaves.   Spreading complex queries over multiple read slaves is much preferable to every app server hitting one database for every query.  By having stateless requests I can have more app servers (using less memory) hitting more database servers without maxing out the CPU utilization due to the cost of complex queries.</p>
<p>What should I do with the unused memory in the app server boxes?  Rather than give it to one app server instance for use as a cache it should be given to the pool of application servers for use as a cache.  One way to do that is with memcached.  I&#8217;ll talk about that more in the future too.</p>
<p>As always please leave comments.  I enjoy getting feedback on what I&#8217;ve written.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anthonychaves.net/2008/03/14/spring-web-mvc-and-the-benefits-of-pagination/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Boston Scalability User Group</title>
		<link>http://blog.anthonychaves.net/2008/02/04/boston-scalability-user-group/</link>
		<comments>http://blog.anthonychaves.net/2008/02/04/boston-scalability-user-group/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 20:59:16 +0000</pubDate>
		<dc:creator>Anthony Chaves</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[career]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[work]]></category>

		<guid isPermaLink="false">http://blog.anthonychaves.net/java/2008/02/04/boston-scalability-user-group</guid>
		<description><![CDATA[I&#8217;ve been digging around lately for a Boston area user group dedicated to architectural scalability and I haven&#8217;t been able to find one.  Other user groups that I regularly attend have meetings centered around scalability once in a while, but I&#8217;m looking for something with a schedule dedicated to the topic.  It&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been digging around lately for a Boston area user group dedicated to architectural scalability and I haven&#8217;t been able to find one.  Other user groups that I regularly attend have meetings centered around scalability once in a while, but I&#8217;m looking for something with a schedule dedicated to the topic.  It&#8217;s a hot topic in the industry right now with a lot happening on different fronts and there should be some ongoing professional discussion dedicated what goes into growing an application.</p>
<p>Here are some of the topics I want to talk about:</p>
<ul>
<li>Data growth and access &#8211; What kind of DBMS topologies allow maximum scalability without breaking the budget?  What if the budget wasn&#8217;t a problem?  How do you migrate your data model from hundreds of users to millions of users?  Should you partition user data across shards or keep it in a central database?  How do you profile data access paterns?  Is your application mostly-read or mostly-write?  When should you use an LDAP directory for data storage?  When should you use MySQL and when should you use Oracle?</li>
<li>Application server scaling &#8211; app server clustering, web server integration, load balancing, application session management, data caching</li>
<li>Web Tier &#8211; load balancing reverse proxies, data caching, working with HTTP, considerations for exposing functionality via REST</li>
<li>Language conisderations and platform choices &#8211; Dynamic languages vs. Static languages, Linux vs. Windows, Solaris vs. Linux, RedHat vs. Oracle, IBM vs. Oracle &#8211; How do you make these choices?  What evaluation critera are most important?  Which ones are misleading?</li>
<li>Framework scalability &#8211; How can you scale if your framework can&#8217;t?  Does Rails really scale better than Spring Web MVC?  Where do PHP frameworks fit in?  What are the alternatives?  This is where we will investigate what you gain and lose by binding yourself to a particular framework, how to keep the coupling to a minimum and how to use your framework as a solid foundation instead viewing it as a cage.</li>
<li>Emerging technology &#8211; Should you become familiar with Map Reduce and Hadoop?  What kind of impact do object databases have on your application?  Should you buy your own Sun or Dell boxes or use Amazon&#8217;s EC2 and S3?</li>
<li>Application architecture &#8211; How do you write an application that scales?  What does your application look like as it grows from servicing hundreds to millions of users?  How does it handle session management?  How does it access datastores?  Are there any design patterns that are helpful?  What are the anti-patterns to be aware of?</li>
</ul>
<p>Like I said, I haven&#8217;t found a group dedicated to discussing these topics.  If you know of one in the Boston area please let me know.  Assuming there isn&#8217;t one <strong>I am willing to start one</strong>.  I&#8217;d like to start off small and meet at coffee shops around Burlington or Lowell.  I have no delusions that this is going to start off or even become as big as NEJUG is now.  If it starts off as a few people getting together to talk about scalability trends, cool caching solutions and specific products then I&#8217;d call it a good start.</p>
<p>The meeting location is still TBD and will be based on how many people are interested in attending.  It will probably be somewhere in Burlington, MA.  There is no planned presentation at this time.  Instead we will have a meet and greet and then discuss scalability trends and news, what approaches to scalability are commonly used now and what are the plans for the future.</p>
<p>If you are interested in coming or in finding out more information please email me at &lt;my first name&gt;@&lt;my domain name&gt;.&lt;my tld&gt; or leave a comment below.  Please make sure to include your email address when you fill out the form so that I can get in touch with you &#8211; your email address will not be displayed on my site.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.anthonychaves.net/2008/02/04/boston-scalability-user-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
