<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.3" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Comments on: Scalable Counters for Web Applications</title>
	<link>http://www.semergence.com/2008/06/28/scalable-counters-for-web-applications/</link>
	<description>Semantic Web, Ruby on Rails, and Massive Data</description>
	<pubDate>Fri, 21 Nov 2008 21:24:26 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.3</generator>

	<item>
		<title>By: Peter Daly</title>
		<link>http://www.semergence.com/2008/06/28/scalable-counters-for-web-applications/#comment-696</link>
		<dc:creator>Peter Daly</dc:creator>
		<pubDate>Mon, 30 Jun 2008 11:27:03 +0000</pubDate>
		<guid>http://www.semergence.com/2008/06/28/scalable-counters-for-web-applications/#comment-696</guid>
		<description>Message queue persistence - depends on the requirements...if minor losses are not a problem, a RAM based queue may be acceptable.

Counter persistence - again, depends on the requirements.  Message beans would the easiest, but for better scalability I would implement a custom consumer for the queue that would read the queue and write many hits at once as a single DB transaction.  Even without partitioning, that "write many at once" method can be tweaked to persist millions of records an hour based on similar personal experience.  Primary bottleneck would be bandwidth to the DB or disk IO of the DB.  If this becomes the bottleneck, then sure, partition it.

-Pete</description>
		<content:encoded><![CDATA[<p>Message queue persistence - depends on the requirements&#8230;if minor losses are not a problem, a RAM based queue may be acceptable.</p>
<p>Counter persistence - again, depends on the requirements.  Message beans would the easiest, but for better scalability I would implement a custom consumer for the queue that would read the queue and write many hits at once as a single DB transaction.  Even without partitioning, that &#8220;write many at once&#8221; method can be tweaked to persist millions of records an hour based on similar personal experience.  Primary bottleneck would be bandwidth to the DB or disk IO of the DB.  If this becomes the bottleneck, then sure, partition it.</p>
<p>-Pete</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: admin</title>
		<link>http://www.semergence.com/2008/06/28/scalable-counters-for-web-applications/#comment-695</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 30 Jun 2008 07:24:39 +0000</pubDate>
		<guid>http://www.semergence.com/2008/06/28/scalable-counters-for-web-applications/#comment-695</guid>
		<description>Hi Peter,

Yes, from Manlius. :)

Second, I'd caution about the message queue.  Where are you going to persist those messages?  Are you concerned about possibly losing them?

Third, if you are using Java, you want to look at AtomicLong.

Fourth, if you have a group of message beans (man, that's old school.  you haven't switched to Spring yet? :) are they going to write to the same counter?  If so, you have the same contention issue.  Or are you going to use partitioned counters?</description>
		<content:encoded><![CDATA[<p>Hi Peter,</p>
<p>Yes, from Manlius. <img src='http://www.semergence.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Second, I&#8217;d caution about the message queue.  Where are you going to persist those messages?  Are you concerned about possibly losing them?</p>
<p>Third, if you are using Java, you want to look at AtomicLong.</p>
<p>Fourth, if you have a group of message beans (man, that&#8217;s old school.  you haven&#8217;t switched to Spring yet? <img src='http://www.semergence.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> are they going to write to the same counter?  If so, you have the same contention issue.  Or are you going to use partitioned counters?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter Daly</title>
		<link>http://www.semergence.com/2008/06/28/scalable-counters-for-web-applications/#comment-693</link>
		<dc:creator>Peter Daly</dc:creator>
		<pubDate>Mon, 30 Jun 2008 01:46:52 +0000</pubDate>
		<guid>http://www.semergence.com/2008/06/28/scalable-counters-for-web-applications/#comment-693</guid>
		<description>Here's how I'd tackle this problem...although my mind is thinking in terms of Java solution.

First, you need a single counting entity.  Static session bean type thing.

When it is created, it loads an initial count from a persistent store and sets in it in a variable.

When it is asked to get/increment count it would (in a synchronized/locking method) 
1.  Increment the counter variable
2.  Throw a (small) "hit" event onto a message queue
3.  Return the new value

Problem 1 solved..how to count fast in a synchronized manor.

Problem 2 is left...persisting the data.  There are a few options here.  The most simple option would to have a group of message beans read the queue and write the records to a DB.

This method should be able to scale very well.  For outputting a new "hit" value, no DB read is required.

A fail-over system could be implemented to handle counts for downtime situations with no data loss.

Thanks for giving my brain a simple yet complex problem to crunch on this evening.

Are you the Seth Ladd from Manlius, NY?

Peter Daly</description>
		<content:encoded><![CDATA[<p>Here&#8217;s how I&#8217;d tackle this problem&#8230;although my mind is thinking in terms of Java solution.</p>
<p>First, you need a single counting entity.  Static session bean type thing.</p>
<p>When it is created, it loads an initial count from a persistent store and sets in it in a variable.</p>
<p>When it is asked to get/increment count it would (in a synchronized/locking method)<br />
1.  Increment the counter variable<br />
2.  Throw a (small) &#8220;hit&#8221; event onto a message queue<br />
3.  Return the new value</p>
<p>Problem 1 solved..how to count fast in a synchronized manor.</p>
<p>Problem 2 is left&#8230;persisting the data.  There are a few options here.  The most simple option would to have a group of message beans read the queue and write the records to a DB.</p>
<p>This method should be able to scale very well.  For outputting a new &#8220;hit&#8221; value, no DB read is required.</p>
<p>A fail-over system could be implemented to handle counts for downtime situations with no data loss.</p>
<p>Thanks for giving my brain a simple yet complex problem to crunch on this evening.</p>
<p>Are you the Seth Ladd from Manlius, NY?</p>
<p>Peter Daly</p>
]]></content:encoded>
	</item>
</channel>
</rss>
