hama-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tomm...@apache.org
Subject svn commit: r1446615 - in /hama/branches/hama-732/graph: ./ src/main/java/org/apache/hama/graph/ src/test/java/org/apache/hama/graph/
Date Fri, 15 Feb 2013 14:53:39 GMT
Author: tommaso
Date: Fri Feb 15 14:53:39 2013
New Revision: 1446615

URL: http://svn.apache.org/r1446615
Log:
HAMA-732 - sketching up a first impl

Added:
    hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/OffHeapVerticesInfo.java
  (with props)
    hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/OffHeapVerticesInfoTest.java
  (with props)
Modified:
    hama/branches/hama-732/graph/pom.xml
    hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java
    hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java

Modified: hama/branches/hama-732/graph/pom.xml
URL: http://svn.apache.org/viewvc/hama/branches/hama-732/graph/pom.xml?rev=1446615&r1=1446614&r2=1446615&view=diff
==============================================================================
--- hama/branches/hama-732/graph/pom.xml (original)
+++ hama/branches/hama-732/graph/pom.xml Fri Feb 15 14:53:39 2013
@@ -43,6 +43,11 @@
       <type>test-jar</type>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.apache.directmemory</groupId>
+      <artifactId>directmemory-cache</artifactId>
+      <version>0.2-SNAPSHOT</version>
+    </dependency>
   </dependencies>
   <build>
     <finalName>hama-graph-${project.version}</finalName>

Modified: hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java
URL: http://svn.apache.org/viewvc/hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java?rev=1446615&r1=1446614&r2=1446615&view=diff
==============================================================================
--- hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java (original)
+++ hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/GraphJobRunner.java Fri
Feb 15 14:53:39 2013
@@ -71,7 +71,7 @@ public final class GraphJobRunner<V exte
   private Combiner<M> combiner;
   private Partitioner<V, M> partitioner;
 
-  private VerticesInfo<V, E, M> vertices;
+  private OffHeapVerticesInfo<V, E, M> vertices;
   private boolean updated = true;
   private int globalUpdateCounts = 0;
 
@@ -261,7 +261,7 @@ public final class GraphJobRunner<V exte
     aggregationRunner = new AggregationRunner<V, E, M>();
     aggregationRunner.setupAggregators(peer);
 
-    vertices = new VerticesInfo<V, E, M>();
+    vertices = new OffHeapVerticesInfo<V, E, M>();
   }
 
   /**

Added: hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/OffHeapVerticesInfo.java
URL: http://svn.apache.org/viewvc/hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/OffHeapVerticesInfo.java?rev=1446615&view=auto
==============================================================================
--- hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/OffHeapVerticesInfo.java
(added)
+++ hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/OffHeapVerticesInfo.java
Fri Feb 15 14:53:39 2013
@@ -0,0 +1,65 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.graph;
+
+import java.util.Iterator;
+
+import org.apache.directmemory.DirectMemory;
+import org.apache.directmemory.cache.CacheService;
+import org.apache.directmemory.utils.CacheValuesIterable;
+import org.apache.hadoop.io.Writable;
+
+/**
+ * An off heap version of a {@link Vertex} storage.
+ */
+public class OffHeapVerticesInfo<V extends Writable, E extends Writable, M extends Writable>
+        implements Iterable<Vertex<V, E, M>> {
+
+    private final CacheService<V, Vertex<V, E, M>> vertices;
+
+    private final boolean strict;
+
+    public OffHeapVerticesInfo(boolean strict) {
+        this.strict = strict;
+        this.vertices = new DirectMemory<V, Vertex<V, E, M>>().setNumberOfBuffers(1).
+                setSize(1000).setInitialCapacity(10000).setConcurrencyLevel(100).
+                setDisposalTime(100000).newCacheService();
+    }
+
+    public OffHeapVerticesInfo() {
+        this(true);
+    }
+
+    public void addVertex(Vertex<V, E, M> vertex) {
+        vertices.put(vertex.getVertexID(), vertex);
+    }
+
+    public void clear() {
+        vertices.clear();
+    }
+
+    public int size() {
+        return (int) this.vertices.entries();
+    }
+
+    @Override
+    public Iterator<Vertex<V, E, M>> iterator() {
+        return new CacheValuesIterable<V, Vertex<V, E, M>>(vertices, strict).iterator();
+    }
+
+}

Propchange: hama/branches/hama-732/graph/src/main/java/org/apache/hama/graph/OffHeapVerticesInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/OffHeapVerticesInfoTest.java
URL: http://svn.apache.org/viewvc/hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/OffHeapVerticesInfoTest.java?rev=1446615&view=auto
==============================================================================
--- hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/OffHeapVerticesInfoTest.java
(added)
+++ hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/OffHeapVerticesInfoTest.java
Fri Feb 15 14:53:39 2013
@@ -0,0 +1,93 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.hama.graph;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Random;
+
+import org.apache.hadoop.io.DoubleWritable;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Testcase for {@link OffHeapVerticesInfo}
+ */
+public class OffHeapVerticesInfoTest {
+
+    private Random random;
+
+    @Before
+    public void setUp() throws Exception {
+        random = new Random();
+    }
+
+    @Test
+    public void testAddition() throws Exception {
+        OffHeapVerticesInfo<DoubleWritable, DoubleWritable, DoubleWritable> verticesInfo
=
+                new OffHeapVerticesInfo<DoubleWritable, DoubleWritable, DoubleWritable>();
+        Vertex<DoubleWritable, DoubleWritable, DoubleWritable> vertex = creteDoubleVertex(1d);
+        verticesInfo.addVertex(vertex);
+        assertTrue("added vertex could not be found in the cache", verticesInfo.iterator().hasNext());
+    }
+
+    @Test
+    public void testAdditionWithNonStrictCache() throws Exception {
+        OffHeapVerticesInfo<DoubleWritable, DoubleWritable, DoubleWritable> verticesInfo
=
+                new OffHeapVerticesInfo<DoubleWritable, DoubleWritable, DoubleWritable>(false);
+        Vertex<DoubleWritable, DoubleWritable, DoubleWritable> vertex = creteDoubleVertex(1d);
+        verticesInfo.addVertex(vertex);
+        assertTrue("added vertex could not be found in the cache", verticesInfo.iterator().hasNext());
+    }
+
+
+    private Vertex<DoubleWritable, DoubleWritable, DoubleWritable> creteDoubleVertex(final
Double id) {
+        return new Vertex<DoubleWritable, DoubleWritable, DoubleWritable>() {
+            @Override
+            public DoubleWritable createVertexIDObject() {
+                return new DoubleWritable(id);
+            }
+
+            @Override
+            public DoubleWritable createEdgeCostObject() {
+                return new DoubleWritable(random.nextDouble());
+            }
+
+            @Override
+            public DoubleWritable createVertexValue() {
+                return new DoubleWritable(random.nextDouble());
+            }
+
+            @Override
+            public void readState(DataInput in) throws IOException {
+            }
+
+            @Override
+            public void writeState(DataOutput out) throws IOException {
+            }
+
+            @Override
+            public void compute(Iterator<DoubleWritable> messages) throws IOException
{
+            }
+        };
+    }
+}

Propchange: hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/OffHeapVerticesInfoTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java
URL: http://svn.apache.org/viewvc/hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java?rev=1446615&r1=1446614&r2=1446615&view=diff
==============================================================================
--- hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java
(original)
+++ hama/branches/hama-732/graph/src/test/java/org/apache/hama/graph/TestSubmitGraphJob.java
Fri Feb 15 14:53:39 2013
@@ -115,7 +115,7 @@ public class TestSubmitGraphJob extends 
       reader.close();
     }
     LOG.info("Sum is: " + sum);
-    assertTrue(sum > 0.9d && sum <= 1.1d);
+    assertTrue("unexpected sum " +sum, sum > 0.9d && sum <= 1.1d);
   }
 
 



Mime
View raw message