<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: A reminder about remainder operator (%)</title>
	<atom:link href="http://www.javablogging.com/a-reminder-about-remainder-operator/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javablogging.com/a-reminder-about-remainder-operator/</link>
	<description>Tracking surprises, features and bugs</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:43:49 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Adam Malter</title>
		<link>http://www.javablogging.com/a-reminder-about-remainder-operator/comment-page-1/#comment-32</link>
		<dc:creator>Adam Malter</dc:creator>
		<pubDate>Fri, 10 Jul 2009 21:03:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=71#comment-32</guid>
		<description>What is this uint you speak of? Some mystical item from a faraway land?</description>
		<content:encoded><![CDATA[<p>What is this uint you speak of? Some mystical item from a faraway land?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ppow</title>
		<link>http://www.javablogging.com/a-reminder-about-remainder-operator/comment-page-1/#comment-30</link>
		<dc:creator>ppow</dc:creator>
		<pubDate>Fri, 10 Jul 2009 18:08:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=71#comment-30</guid>
		<description>About the circular buffer: Try to imagine that your system is trying to compare two algorithms (A and B) against each other by running them with different inputs (i1, i2,...iN) and checking whether they will give the same results (For example A is a brut-force slow solution, B is a fast sophisticated algorithm that you want to check). It is very possible that your jobs queue will look like this:
A(i1), B(i1), A(i2), B(i2), A(i3), B(i3), ..., A(iN), B(iN)
so there is always alternating A and B tasks. The execution time of every task is &#039;random&#039;, but then it is expected that A(i) &gt;&gt; B(i).

Now try to imagine that you have 100 machines in S. If the system would use your algorithm, then all servers with even IDs would get the A tasks and servers with even IDs would get the tasks B. Therefore odd-ID servers would have much more load and still continue to process the tasks while the even-ID servers would be idle....

I just wanted to show you that there can be a task distribution pattern in J and its impact on processing can be really bad. Basically since the task generator is not really random you do have to expect to have some pattern in J and that is why you should distribute them among the machines in a &#039;random&#039; way:)

...and yes, unsigned int would solve the issue. But then again you would have to know about the issue first and if you did you would probably find a more elegant solution:)</description>
		<content:encoded><![CDATA[<p>About the circular buffer: Try to imagine that your system is trying to compare two algorithms (A and B) against each other by running them with different inputs (i1, i2,&#8230;iN) and checking whether they will give the same results (For example A is a brut-force slow solution, B is a fast sophisticated algorithm that you want to check). It is very possible that your jobs queue will look like this:<br />
A(i1), B(i1), A(i2), B(i2), A(i3), B(i3), &#8230;, A(iN), B(iN)<br />
so there is always alternating A and B tasks. The execution time of every task is &#8216;random&#8217;, but then it is expected that A(i) >> B(i).</p>
<p>Now try to imagine that you have 100 machines in S. If the system would use your algorithm, then all servers with even IDs would get the A tasks and servers with even IDs would get the tasks B. Therefore odd-ID servers would have much more load and still continue to process the tasks while the even-ID servers would be idle&#8230;.</p>
<p>I just wanted to show you that there can be a task distribution pattern in J and its impact on processing can be really bad. Basically since the task generator is not really random you do have to expect to have some pattern in J and that is why you should distribute them among the machines in a &#8216;random&#8217; way:)</p>
<p>&#8230;and yes, unsigned int would solve the issue. But then again you would have to know about the issue first and if you did you would probably find a more elegant solution:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: antimatroid</title>
		<link>http://www.javablogging.com/a-reminder-about-remainder-operator/comment-page-1/#comment-29</link>
		<dc:creator>antimatroid</dc:creator>
		<pubDate>Fri, 10 Jul 2009 15:37:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=71#comment-29</guid>
		<description>Why bother to randomly distribute the jobs if the execution times of those jobs are inherently random? Say you have a queue of jobs (J), and a circular buffer of servers (S) which those jobs may execute upon. For each job j in J, put j on S and make S the next server in the circular buffer. If the jobs are random, then this configuration will be just &#039;as random&#039; as the configuration you choose by route of hashcode. 

As a side note- you could have avoided this bug by going with a uint rather than int and your ring would have been Z+ rather than just Z.</description>
		<content:encoded><![CDATA[<p>Why bother to randomly distribute the jobs if the execution times of those jobs are inherently random? Say you have a queue of jobs (J), and a circular buffer of servers (S) which those jobs may execute upon. For each job j in J, put j on S and make S the next server in the circular buffer. If the jobs are random, then this configuration will be just &#8216;as random&#8217; as the configuration you choose by route of hashcode. </p>
<p>As a side note- you could have avoided this bug by going with a uint rather than int and your ring would have been Z+ rather than just Z.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ppow</title>
		<link>http://www.javablogging.com/a-reminder-about-remainder-operator/comment-page-1/#comment-31</link>
		<dc:creator>ppow</dc:creator>
		<pubDate>Fri, 10 Jul 2009 15:11:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=71#comment-31</guid>
		<description>Yeah, random with a defined seed would be the best solution - it would give you a guarantee of an even and fair distribution no matter the number of servers or pattern in task queue.</description>
		<content:encoded><![CDATA[<p>Yeah, random with a defined seed would be the best solution &#8211; it would give you a guarantee of an even and fair distribution no matter the number of servers or pattern in task queue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Artur</title>
		<link>http://www.javablogging.com/a-reminder-about-remainder-operator/comment-page-1/#comment-28</link>
		<dc:creator>Artur</dc:creator>
		<pubDate>Fri, 10 Jul 2009 12:11:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=71#comment-28</guid>
		<description>It would be quite funny if you have written unit tests with all the task names having positive hashcodes by accident...</description>
		<content:encoded><![CDATA[<p>It would be quite funny if you have written unit tests with all the task names having positive hashcodes by accident&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tk</title>
		<link>http://www.javablogging.com/a-reminder-about-remainder-operator/comment-page-1/#comment-27</link>
		<dc:creator>tk</dc:creator>
		<pubDate>Fri, 10 Jul 2009 12:03:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=71#comment-27</guid>
		<description>Relying on hashcode is rather tricky -- if any component in the computed hashcode relies on the built-in hashcode of an instance variable, you might be basing your hashcode computation on memory address somewhere.

Have you thought about instantiating a PRNG with a defined seed?  Just use random.next() * N and you should get a repeatable, uniform distribution.</description>
		<content:encoded><![CDATA[<p>Relying on hashcode is rather tricky &#8212; if any component in the computed hashcode relies on the built-in hashcode of an instance variable, you might be basing your hashcode computation on memory address somewhere.</p>
<p>Have you thought about instantiating a PRNG with a defined seed?  Just use random.next() * N and you should get a repeatable, uniform distribution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rajs</title>
		<link>http://www.javablogging.com/a-reminder-about-remainder-operator/comment-page-1/#comment-25</link>
		<dc:creator>rajs</dc:creator>
		<pubDate>Wed, 08 Jul 2009 16:55:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.javablogging.com/?p=71#comment-25</guid>
		<description>Thanks for sharing this! I can imagine the furstation of debugging and the relief of &quot;Aha!&quot; moment when you figured it. I had similar moments when I made a mistake in commenting out a innocent looking println (part of code cleanup to avoid clogging of log files) and created a infinite loop in production environment bringing all app servers down! It took around 6 hours to figure out that a simple comment of the println has caused this. The println was &quot;System.out.println(&quot;the element is :&quot; + e.nextElement())&quot; which was inside a while (e.hasMoreElements()) loop. Since only the println was commented, the while loop became a infite one. We never bothered to test it as we just commented a simple println. Hard way to learn the importance of testing! 

Rajs
http://thoughtsinprogress.co.in</description>
		<content:encoded><![CDATA[<p>Thanks for sharing this! I can imagine the furstation of debugging and the relief of &#8220;Aha!&#8221; moment when you figured it. I had similar moments when I made a mistake in commenting out a innocent looking println (part of code cleanup to avoid clogging of log files) and created a infinite loop in production environment bringing all app servers down! It took around 6 hours to figure out that a simple comment of the println has caused this. The println was &#8220;System.out.println(&#8221;the element is :&#8221; + e.nextElement())&#8221; which was inside a while (e.hasMoreElements()) loop. Since only the println was commented, the while loop became a infite one. We never bothered to test it as we just commented a simple println. Hard way to learn the importance of testing! </p>
<p>Rajs<br />
<a href="http://thoughtsinprogress.co.in" rel="nofollow">http://thoughtsinprogress.co.in</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

