Issue Details (XML | Word | Printable)

Key: HADOOP-3398
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Trivial Trivial
Assignee: Chris Douglas
Reporter: Chris Douglas
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Hadoop Common

ReduceTask::closestPowerOf2 is inefficient

Created: 15/May/08 10:19 PM   Updated: 08/Jul/09 04:52 PM
Component/s: None
Affects Version/s: None
Fix Version/s: 0.18.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works 3398-0.patch 2008-05-15 10:20 PM Chris Douglas 0.7 kB
Text File Licensed for inclusion in ASF works 3398-1.patch 2008-05-16 02:37 AM Chris Douglas 0.7 kB
Text File Licensed for inclusion in ASF works 3398-2.patch 2008-05-16 07:57 PM Chris Douglas 1 kB
Text File Licensed for inclusion in ASF works 3398-3.patch 2008-05-19 08:40 PM Chris Douglas 1 kB

Hadoop Flags: Reviewed
Resolution Date: 19/May/08 09:20 PM


 Description  « Hide
ReduceTask computes the "closest power of 2" using loops
private static int getClosestPowerOf2(int value) {
  int power = 0;
  int approx = 1;
  while (approx < value) {
    ++power;
    approx = (approx << 1);
  }
  if ((value - (approx >> 1)) < (approx - value)) {
    --power;
  }
  return power;
}

This could be improved.



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Chris Douglas added a comment - 15/May/08 10:20 PM
This returns the same results as the original, save for values <= 0, which neither support.

Hadoop QA added a comment - 16/May/08 12:10 AM
-1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12382141/3398-0.patch
against trunk revision 656852.

+1 @author. The patch does not contain any @author tags.

-1 tests included. The patch doesn't appear to include any new or modified tests.
Please justify why no tests are needed for this patch.

+1 javadoc. The javadoc tool did not generate any warning messages.

+1 javac. The applied patch does not increase the total number of javac compiler warnings.

+1 findbugs. The patch does not introduce any new Findbugs warnings.

+1 release audit. The applied patch does not increase the total number of release audit warnings.

+1 core tests. The patch passed core unit tests.

+1 contrib tests. The patch passed contrib unit tests.

Test results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2481/testReport/
Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2481/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
Checkstyle results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2481/artifact/trunk/build/test/checkstyle-errors.html
Console output: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2481/console

This message is automatically generated.


Hadoop QA added a comment - 16/May/08 01:31 AM
-1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12382146/3398-1.patch
against trunk revision 656852.

+1 @author. The patch does not contain any @author tags.

-1 tests included. The patch doesn't appear to include any new or modified tests.
Please justify why no tests are needed for this patch.

+1 javadoc. The javadoc tool did not generate any warning messages.

+1 javac. The applied patch does not increase the total number of javac compiler warnings.

+1 findbugs. The patch does not introduce any new Findbugs warnings.

+1 release audit. The applied patch does not increase the total number of release audit warnings.

+1 core tests. The patch passed core unit tests.

+1 contrib tests. The patch passed contrib unit tests.

Test results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2482/testReport/
Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2482/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
Checkstyle results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2482/artifact/trunk/build/test/checkstyle-errors.html
Console output: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2482/console

This message is automatically generated.


Amar Kamat added a comment - 16/May/08 04:41 AM
Code looks fine. The values are same for both the implementations. Some comments as to what is done could be useful. I compared the two implementations
input num-iterations before (milli) after (milli)
10000 1000000 642 19
5000 1000000 78 9
2500 1000000 74 5
1000 1000000 69 3
500 1000000 51 1
300 1000000 49 1

Assuming that the map runtime can vary from 300sec to 10,000 secs and the maximum number of times getClosestPowerOf2() will be invoked is 1,000,000.


Chris Douglas added a comment - 16/May/08 07:57 PM
Thanks for the review and benchmarks. It's obvious that this isn't an important optimization (hence "trivial"), but it was a fun problem.

Added some documentation and an explicit check for value leq 0 to make its behavior clearer.


Tsz Wo (Nicholas), SZE added a comment - 16/May/08 08:33 PM
if (value < 0), why not return -getClosestPowerOf2(-value-1)?

Tsz Wo (Nicholas), SZE added a comment - 16/May/08 08:43 PM
Mathematically, we should throw an exception (Math.log() returns NaN for -ve numbers and -infinity for 0) when value <= 0 since logarithm is undefined.

Hadoop QA added a comment - 17/May/08 01:08 AM
-1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12382208/3398-2.patch
against trunk revision 656939.

+1 @author. The patch does not contain any @author tags.

-1 tests included. The patch doesn't appear to include any new or modified tests.
Please justify why no tests are needed for this patch.

+1 javadoc. The javadoc tool did not generate any warning messages.

+1 javac. The applied patch does not increase the total number of javac compiler warnings.

+1 findbugs. The patch does not introduce any new Findbugs warnings.

+1 release audit. The applied patch does not increase the total number of release audit warnings.

-1 core tests. The patch failed core unit tests.

+1 contrib tests. The patch passed contrib unit tests.

Test results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2493/testReport/
Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2493/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
Checkstyle results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2493/artifact/trunk/build/test/checkstyle-errors.html
Console output: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2493/console

This message is automatically generated.


Amar Kamat added a comment - 19/May/08 04:03 AM

Mathematically, we should throw an exception (Math.log() returns NaN for -ve numbers and -infinity for 0) when value <= 0 since logarithm is undefined.

+1.


Chris Douglas added a comment - 19/May/08 08:40 PM
Alright, alright, you pedants.

Tsz Wo (Nicholas), SZE added a comment - 19/May/08 08:45 PM
+1 3398-3.patch looks good

Chris Douglas added a comment - 19/May/08 09:20 PM
I just committed this.

Hadoop QA added a comment - 19/May/08 10:12 PM
-1 overall. Here are the results of testing the latest attachment
http://issues.apache.org/jira/secure/attachment/12382331/3398-3.patch
against trunk revision 657965.

+1 @author. The patch does not contain any @author tags.

-1 tests included. The patch doesn't appear to include any new or modified tests.
Please justify why no tests are needed for this patch.

+1 javadoc. The javadoc tool did not generate any warning messages.

+1 javac. The applied patch does not increase the total number of javac compiler warnings.

+1 findbugs. The patch does not introduce any new Findbugs warnings.

+1 release audit. The applied patch does not increase the total number of release audit warnings.

+1 core tests. The patch passed core unit tests.

+1 contrib tests. The patch passed contrib unit tests.

Test results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2500/testReport/
Findbugs warnings: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2500/artifact/trunk/build/test/findbugs/newPatchFindbugsWarnings.html
Checkstyle results: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2500/artifact/trunk/build/test/checkstyle-errors.html
Console output: http://hudson.zones.apache.org/hudson/job/Hadoop-Patch/2500/console

This message is automatically generated.


Hudson added a comment - 22/May/08 12:24 PM