Created
September 11, 2011 23:01
-
-
Save dvryaboy/1210245 to your computer and use it in GitHub Desktop.
Test memory consumption for Giraph Vertex implementations
This file contains 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
Tiny: 0 832 | |
Object: 0 864 | |
Primitive: 0 1072 | |
Tiny: 1 832 | |
Object: 1 48184 | |
Primitive: 1 51232 | |
Tiny: 10 832 | |
Object: 10 54856 | |
Primitive: 10 55160 | |
Tiny: 100 2632 | |
Object: 100 93016 | |
Primitive: 100 95080 | |
Tiny: 1000 16072 | |
Object: 1000 474616 | |
Primitive: 1000 504528 | |
Tiny: 10000 123592 | |
Object: 10000 4290616 | |
Primitive: 10000 4431744 |
This file contains 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.io.DataInput; | |
import java.io.DataOutput; | |
import java.io.IOException; | |
import java.util.Arrays; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.SortedMap; | |
import org.apache.giraph.graph.Aggregator; | |
import org.apache.giraph.graph.BspUtils; | |
import org.apache.giraph.graph.Edge; | |
import org.apache.giraph.graph.GiraphJob; | |
import org.apache.giraph.graph.GraphState; | |
import org.apache.giraph.graph.LongDoubleFloatDoubleVertex; | |
import org.apache.giraph.graph.MutableVertex; | |
import org.apache.giraph.graph.Vertex; | |
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.io.DoubleWritable; | |
import org.apache.hadoop.io.FloatWritable; | |
import org.apache.hadoop.io.LongWritable; | |
import org.apache.hadoop.io.Writable; | |
import org.apache.hadoop.mapreduce.Mapper.Context; | |
import org.mockito.Mockito; | |
import com.twitter.common.objectsize.ObjectSizeCalculator; | |
public class VertexMemBench { | |
public static class ObjectVertex extends Vertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable> { | |
@Override | |
public void compute(Iterator<DoubleWritable> msgIterator) throws IOException { | |
} | |
} | |
public static class TinyVertex extends MutableVertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable> { | |
private long[] edgeIds = new long[10]; | |
private float[] edgeValues = new float[10]; | |
private int numEdges = 0; | |
@Override | |
public void compute(Iterator<DoubleWritable> msgIterator) throws IOException { | |
} | |
@Override | |
public final boolean addEdge(Edge<LongWritable, FloatWritable> edge) { | |
if (edgeIds.length == numEdges) { | |
edgeIds = Arrays.copyOf(edgeIds, edgeIds.length * 2); | |
edgeValues = Arrays.copyOf(edgeValues, edgeValues.length * 2); | |
} | |
edgeIds[numEdges] = edge.getDestVertexId().get(); | |
edgeValues[numEdges] = edge.getEdgeValue().get(); | |
numEdges += 1; | |
return true; | |
} | |
@Override | |
public void readFields(DataInput arg0) throws IOException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void write(DataOutput arg0) throws IOException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public Aggregator<? extends Writable> getAggregator(String arg0) { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public <A extends Writable> Aggregator<A> registerAggregator(String arg0, | |
Class<? extends Aggregator<A>> arg1) throws InstantiationException, IllegalAccessException { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public boolean useAggregator(String arg0) { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
@Override | |
public void addEdgeRequest(LongWritable arg0, Edge<LongWritable, FloatWritable> arg1) | |
throws IOException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void addVertexRequest( | |
MutableVertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable> arg0) | |
throws IOException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public MutableVertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable> instantiateVertex() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public void removeEdgeRequest(LongWritable arg0, LongWritable arg1) throws IOException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void removeVertexRequest(LongWritable arg0) throws IOException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void setVertexId(LongWritable arg0) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public List<DoubleWritable> getMsgList() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public long getNumEdges() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public long getNumVertices() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public SortedMap<LongWritable, Edge<LongWritable, FloatWritable>> getOutEdgeMap() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public long getSuperstep() { | |
// TODO Auto-generated method stub | |
return 0; | |
} | |
@Override | |
public LongWritable getVertexId() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public DoubleWritable getVertexValue() { | |
// TODO Auto-generated method stub | |
return null; | |
} | |
@Override | |
public boolean isHalted() { | |
// TODO Auto-generated method stub | |
return false; | |
} | |
@Override | |
public void postApplication() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void postSuperstep() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void preApplication() throws InstantiationException, IllegalAccessException { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void preSuperstep() { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void sendMsg(LongWritable arg0, DoubleWritable arg1) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void sendMsgToAllEdges(DoubleWritable arg0) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void setVertexValue(DoubleWritable arg0) { | |
// TODO Auto-generated method stub | |
} | |
@Override | |
public void voteToHalt() { | |
// TODO Auto-generated method stub | |
} | |
} | |
public static class PrimitiveVertex extends LongDoubleFloatDoubleVertex { | |
@Override | |
public void compute(Iterator<DoubleWritable> arg0) throws IOException { | |
} | |
} | |
public static void main(String[] args) { | |
int[] sizes = {0, 1, 10, 100, 1000, 10000}; | |
for (int size : sizes) { | |
System.out.println("Tiny: \t" + size + "\t" + getMem(TinyVertex.class, size)); | |
System.out.println("Object: \t" + size + "\t" + getMem(ObjectVertex.class, size)); | |
System.out.println("Primitive:\t" + size + "\t" + getMem(PrimitiveVertex.class, size)); | |
} | |
} | |
public static long getMem(Class<? extends MutableVertex> klass, int numEdges) { | |
GraphState<LongWritable, DoubleWritable, FloatWritable, DoubleWritable> gs = | |
new GraphState<LongWritable, DoubleWritable, | |
FloatWritable, DoubleWritable>(); | |
gs.setContext(Mockito.mock(Context.class)); | |
Configuration conf = new Configuration(); | |
conf.set(GiraphJob.VERTEX_CLASS, klass.getName()); | |
MutableVertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable> vertex = | |
(MutableVertex<LongWritable, DoubleWritable, FloatWritable, DoubleWritable>) | |
BspUtils.createVertex(conf, gs); | |
for (int i = 0; i < numEdges; i++) { | |
vertex.addEdge(new Edge<LongWritable, FloatWritable>(new LongWritable(i), new FloatWritable(i))); | |
} | |
vertex.setVertexId(new LongWritable(123)); | |
vertex.setVertexValue(new DoubleWritable(321)); | |
return ObjectSizeCalculator.getObjectSize(vertex); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment