You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hama.apache.org by ed...@apache.org on 2014/04/07 01:54:02 UTC

svn commit: r1585363 - in /hama/trunk: ./ core/src/test/java/org/apache/hama/examples/ examples/src/main/java/org/apache/hama/examples/ graph/src/main/java/org/apache/hama/graph/ src/site/xdoc/

Author: edwardyoon
Date: Sun Apr  6 23:54:01 2014
New Revision: 1585363

URL: http://svn.apache.org/r1585363
Log:
HAMA-847: Vertex should provide Counters

Modified:
    hama/trunk/CHANGES.txt
    hama/trunk/core/src/test/java/org/apache/hama/examples/ClassSerializePrinting.java
    hama/trunk/examples/src/main/java/org/apache/hama/examples/CombineExample.java
    hama/trunk/examples/src/main/java/org/apache/hama/examples/DynamicGraph.java
    hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java
    hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInterface.java
    hama/trunk/src/site/xdoc/hama_bsp_tutorial.xml
    hama/trunk/src/site/xdoc/hama_graph_tutorial.xml

Modified: hama/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hama/trunk/CHANGES.txt?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/CHANGES.txt (original)
+++ hama/trunk/CHANGES.txt Sun Apr  6 23:54:01 2014
@@ -11,7 +11,8 @@ Release 0.7.0 (unreleased changes)
    HAMA-885: Semi-Clustering is not producing expected output (Renil J via edwardyoon)
 
   IMPROVEMENTS
-
+  
+   HAMA-847: Vertex should provide Counters (edwardyoon)
    HAMA-568: Add faster synchronized collections for message queues (edwardyoon)
 
 Release 0.6.4 - Mar 5, 2014

Modified: hama/trunk/core/src/test/java/org/apache/hama/examples/ClassSerializePrinting.java
URL: http://svn.apache.org/viewvc/hama/trunk/core/src/test/java/org/apache/hama/examples/ClassSerializePrinting.java?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/core/src/test/java/org/apache/hama/examples/ClassSerializePrinting.java (original)
+++ hama/trunk/core/src/test/java/org/apache/hama/examples/ClassSerializePrinting.java Sun Apr  6 23:54:01 2014
@@ -31,7 +31,7 @@ import org.apache.hama.bsp.sync.SyncExce
 
 public class ClassSerializePrinting extends
     BSP<NullWritable, NullWritable, IntWritable, Text, MapWritable> {
-
+  
   public static final int NUM_SUPERSTEPS = 15;
 
   @Override

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/CombineExample.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/CombineExample.java?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/CombineExample.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/CombineExample.java Sun Apr  6 23:54:01 2014
@@ -44,6 +44,10 @@ public class CombineExample {
   private static Path TMP_OUTPUT = new Path("/tmp/combine-"
       + System.currentTimeMillis());
 
+  private static enum CUSTOM_COUNTER {
+    CUSTOM_SEND_MESSAGE_COUNTER
+  }
+  
   public static class MyBSP extends
       BSP<NullWritable, NullWritable, Text, IntWritable, IntWritable> {
     public static final Log LOG = LogFactory.getLog(MyBSP.class);
@@ -56,6 +60,8 @@ public class CombineExample {
         peer.send(peerName, new IntWritable(1));
         peer.send(peerName, new IntWritable(2));
         peer.send(peerName, new IntWritable(3));
+        
+        peer.getCounter(CUSTOM_COUNTER.CUSTOM_SEND_MESSAGE_COUNTER).increment(1);
       }
       peer.sync();
 
@@ -120,6 +126,6 @@ public class CombineExample {
       System.out.println("Job Finished in "
           + (System.currentTimeMillis() - startTime) / 1000.0 + " seconds");
     }
-
+    
   }
 }

Modified: hama/trunk/examples/src/main/java/org/apache/hama/examples/DynamicGraph.java
URL: http://svn.apache.org/viewvc/hama/trunk/examples/src/main/java/org/apache/hama/examples/DynamicGraph.java?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/examples/src/main/java/org/apache/hama/examples/DynamicGraph.java (original)
+++ hama/trunk/examples/src/main/java/org/apache/hama/examples/DynamicGraph.java Sun Apr  6 23:54:01 2014
@@ -51,7 +51,10 @@ import org.apache.hama.graph.VertexInput
  * Output example: sum 10
  */
 public class DynamicGraph {
-
+  private static enum DYNAMIC_GRAPH_COUNTER {
+    ADDED_VERTEX
+  }
+  
   public static class GraphTextReader extends
       VertexInputReader<LongWritable, Text, Text, NullWritable, IntWritable> {
 
@@ -74,6 +77,8 @@ public class DynamicGraph {
         Text new_id = new Text("sum");
         this.addVertex(new_id, new ArrayList<Edge<Text, NullWritable>>(),
             new IntWritable(0));
+
+        this.getCounter(DYNAMIC_GRAPH_COUNTER.ADDED_VERTEX).increment(1);;
       }
     }
 

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/Vertex.java Sun Apr  6 23:54:01 2014
@@ -29,6 +29,7 @@ import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
 import org.apache.hama.HamaConfiguration;
 import org.apache.hama.bsp.BSPPeer;
+import org.apache.hama.bsp.Counters.Counter;
 import org.apache.hama.bsp.Partitioner;
 
 /**
@@ -397,4 +398,14 @@ public abstract class Vertex<V extends W
   public IntWritable getNumLastAggregatedVertices(int index) {
     return runner.getNumLastAggregatedVertices(index);
   }
+
+  @Override
+  public Counter getCounter(Enum<?> name) {
+    return runner.getPeer().getCounter(name);
+  }
+  
+  @Override
+  public Counter getCounter(String group, String name) {
+    return runner.getPeer().getCounter(group, name);
+  }
 }

Modified: hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInterface.java
URL: http://svn.apache.org/viewvc/hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInterface.java?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInterface.java (original)
+++ hama/trunk/graph/src/main/java/org/apache/hama/graph/VertexInterface.java Sun Apr  6 23:54:01 2014
@@ -23,6 +23,7 @@ import java.util.List;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
 import org.apache.hama.HamaConfiguration;
+import org.apache.hama.bsp.Counters.Counter;
 
 /**
  * The vertex interface.
@@ -127,4 +128,8 @@ public interface VertexInterface<V exten
     */
    public Writable getAggregatedValue(int index);
 
+   /** Counters */
+   public Counter getCounter(Enum<?> name);
+   
+   public Counter getCounter(String group, String name);
 }

Modified: hama/trunk/src/site/xdoc/hama_bsp_tutorial.xml
URL: http://svn.apache.org/viewvc/hama/trunk/src/site/xdoc/hama_bsp_tutorial.xml?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/src/site/xdoc/hama_bsp_tutorial.xml (original)
+++ hama/trunk/src/site/xdoc/hama_bsp_tutorial.xml Sun Apr  6 23:54:01 2014
@@ -210,6 +210,18 @@ xsi:schemaLocation="http://maven.apache.
     }
 
   }</pre>
+    <h4>Counters</h4>
+    <p>Counters are used for measuring the progress or counting the number of events within job. For your own Counter, you need to define the enum type as follow:</p>
+<pre>
+  private static enum CUSTOM_COUNTER {
+    CUSTOM_SEND_MESSAGE_COUNTER,
+    ANOTHER_COUNTER
+  }
+</pre>
+    <p>Then you can increment your own counter by calling increment method as follow:</p>
+<pre>
+  peer.getCounter(CUSTOM_COUNTER.CUSTOM_SEND_MESSAGE_COUNTER).increment(1);
+</pre>
     
     <subsection name="Shell Command Line Interfaces"></subsection>
     <p>Hama provides several command for BSP job administration:</p>

Modified: hama/trunk/src/site/xdoc/hama_graph_tutorial.xml
URL: http://svn.apache.org/viewvc/hama/trunk/src/site/xdoc/hama_graph_tutorial.xml?rev=1585363&r1=1585362&r2=1585363&view=diff
==============================================================================
--- hama/trunk/src/site/xdoc/hama_graph_tutorial.xml (original)
+++ hama/trunk/src/site/xdoc/hama_graph_tutorial.xml Sun Apr  6 23:54:01 2014
@@ -83,6 +83,19 @@ xsi:schemaLocation="http://maven.apache.
    <p>To write your own combiner, you have to extend Combiner class and implement the methods of #combine(Iterable&lt;M&gt; messages). 
    For more, please see the implementation of MinIntCombiner in org.apache.hama.example.SSSP example.</p> 
 
+   <subsection name="Counters"></subsection>
+   <p>Counters are used for measuring the progress or counting the number of events within job. For your own Counter, you need to define the enum type as follow:</p>
+<pre>
+  private static enum DYNAMIC_GRAPH_COUNTER {
+    ADDED_VERTEX_COUNT,
+    REMOVED_VERTEX_COUNT
+  }
+</pre>
+   <p>Then you can increment your own counter by calling increment method as follow:</p>
+<pre>
+  this.getCounter(DYNAMIC_GRAPH_COUNTER.ADDED_VERTEX_COUNT).increment(1);
+</pre>
+
    <subsection name="Aggregators"></subsection>
    <p>Aggregators are a mechanism for global communication, monitoring, and data. Each vertex can provide a value to an aggregator in superstep S, the system combines those values using a reduction operator, and the resulting value is made available to all vertices in superstep S + 1.
    </p>