Created
September 12, 2011 03:33
-
-
Save dvryaboy/1210524 to your computer and use it in GitHub Desktop.
Giraph Memory Benchmarks, v2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Current : 0 144 | |
Just Value : 0 144 | |
Primitive Map : 0 272 | |
Primitive : 0 56 | |
Current : 1 240 | |
Just Value : 1 216 | |
Primitive Map : 1 272 | |
Primitive : 1 72 | |
Current : 10 1104 | |
Just Value : 10 864 | |
Primitive Map : 10 528 | |
Primitive : 10 176 | |
Current : 100 10704 | |
Just Value : 100 8304 | |
Primitive Map : 100 3728 | |
Primitive : 100 1256 | |
Current : 1000 104272 | |
Just Value : 1000 80272 | |
Primitive Map : 1000 45976 | |
Primitive : 1000 12056 | |
Current : 10000 1025616 | |
Just Value : 10000 785616 | |
Primitive Map : 10000 301192 | |
Primitive : 10000 120056 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.giraph.util; | |
import java.util.Arrays; | |
import java.util.Map; | |
import org.apache.giraph.graph.Edge; | |
import org.apache.hadoop.io.FloatWritable; | |
import org.apache.hadoop.io.LongWritable; | |
import org.apache.mahout.math.map.OpenLongFloatHashMap; | |
import com.google.common.collect.Maps; | |
import com.twitter.common.objectsize.ObjectSizeCalculator; | |
public class VertexMemBench { | |
public static abstract class Vertex { | |
public abstract void addEdge(Edge<LongWritable, FloatWritable> edge); | |
} | |
public static class MapVertex extends Vertex { | |
Map<LongWritable, Edge<LongWritable, FloatWritable>> edges = Maps.newHashMap(); | |
@Override | |
public void addEdge(Edge<LongWritable, FloatWritable> edge) { | |
edges.put(edge.getDestVertexId(), edge); | |
} | |
} | |
public static class MapValueVertex extends Vertex { | |
Map<LongWritable, FloatWritable> edges = Maps.newHashMap(); | |
@Override | |
public void addEdge(Edge<LongWritable, FloatWritable> edge) { | |
edges.put(edge.getDestVertexId(), edge.getEdgeValue()); | |
} | |
} | |
public static class PrimitiveMapVertex extends Vertex { | |
private OpenLongFloatHashMap verticesWithEdgeValues = new OpenLongFloatHashMap(10); | |
@Override | |
public void addEdge(Edge<LongWritable, FloatWritable> edge) { | |
verticesWithEdgeValues.put(edge.getDestVertexId().get(), edge.getEdgeValue().get()); | |
} | |
} | |
public static class PrimitiveVertex extends Vertex { | |
private long[] edgeIds = new long[0]; | |
private float[] edgeValues = new float[0]; | |
@Override | |
public final void addEdge(Edge<LongWritable, FloatWritable> edge) { | |
edgeIds = Arrays.copyOf(edgeIds, edgeIds.length + 1); | |
edgeValues = Arrays.copyOf(edgeValues, edgeValues.length + 1); | |
edgeIds[edgeIds.length - 1] = edge.getDestVertexId().get(); | |
edgeValues[edgeValues.length - 1] = edge.getEdgeValue().get(); | |
} | |
} | |
public static void main(String[] args) throws InstantiationException, IllegalAccessException { | |
int[] sizes = {0, 1, 10, 100, 1000, 10000}; | |
for (int size : sizes) { | |
System.out.println("Current : " + size + "\t" + getMem(MapVertex.class, size)); | |
System.out.println("Just Value : " + size + "\t" + getMem(MapValueVertex.class, size)); | |
System.out.println("Primitive Map : " + size + "\t" + getMem(PrimitiveMapVertex.class, size)); | |
System.out.println("Primitive : " + size + "\t" + getMem(PrimitiveVertex.class, size)); | |
} | |
} | |
public static long getMem(Class<? extends Vertex> klass, int numEdges) throws InstantiationException, IllegalAccessException { | |
Vertex vertex = klass.newInstance(); | |
for (int i = 0; i < numEdges; i++) { | |
vertex.addEdge(new Edge<LongWritable, FloatWritable>(new LongWritable(i), new FloatWritable(i))); | |
} | |
return ObjectSizeCalculator.getObjectSize(vertex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment