use of org.goldenorb.Vertices in project goldenorb by jzachr.
the class OutboundVertexThread method testOutBoundVertexQueue.
@Test
public void testOutBoundVertexQueue() throws Exception {
// OutboundVertexQueue settings
int numberOfPartitions = 100;
// max number of Vertices to be sent by a Thread
int numOfVerticesToSendPerThread = 10500;
// max number of Vertices to trigger a send operation by the queue
int numOfVerticesPerBlock = 1000;
int partitionId = 1;
Class<? extends Vertex<?, ?, ?>> vertexClass = TestVertex.class;
Map<Integer, OrbPartitionCommunicationProtocol> orbClients = new HashMap<Integer, OrbPartitionCommunicationProtocol>();
for (int i = 0; i < numberOfPartitions; i++) {
orbClients.put(new Integer(i), infoCollector);
}
OutboundVertexQueue ovq = new OutboundVertexQueue(numberOfPartitions, numOfVerticesPerBlock, orbClients, vertexClass, partitionId);
// initialize the Threads and pass them their test Vertices
CountDownLatch startLatch = new CountDownLatch(1);
CountDownLatch everyoneDoneLatch = new CountDownLatch(numberOfPartitions);
for (int i = 0; i < numberOfPartitions; i++) {
Vertices vrts = new Vertices(vertexClass);
for (int p = 0; p < numOfVerticesToSendPerThread; p++) {
String vertexID = "vertex " + p;
IntWritable vertexValue = new IntWritable(p);
List<Edge<IntWritable>> edgesList = new ArrayList<Edge<IntWritable>>();
TestVertex vrt = new TestVertex(vertexID, vertexValue, edgesList);
vrts.add(vrt);
}
OutboundVertexThread obmThread = new OutboundVertexThread(vrts, ovq, startLatch, everyoneDoneLatch);
// initialize a Thread
obmThread.start();
}
// start all Threads simultaneously
startLatch.countDown();
// wait until all Threads are done
everyoneDoneLatch.await();
ovq.sendRemainingVertices();
System.out.println(infoCollector.vList.size());
assertThat(ovq, notNullValue());
assertTrue(infoCollector.vList.size() == (numberOfPartitions * numOfVerticesToSendPerThread));
}
use of org.goldenorb.Vertices in project goldenorb by jzachr.
the class OutboundVertexQueue method sendRemainingVertices.
/**
* Sends any remaining vertices if the maximum number of vertices is not met.
*/
public void sendRemainingVertices() {
for (int partitionID = 0; partitionID < numberOfPartitions; partitionID++) {
ovqLogger.info(this.toString() + " Partition: " + Integer.toString(partitionId) + " Sending bulk vertices. Count: " + pvo.partitionVertexCounter.get(partitionID) + ", " + pvo.partitionVertexList.get(partitionID).size());
if (pvo.partitionVertexList.get(partitionID) != null) {
Vertices verticesToBeSent = pvo.partitionVertexList.get(partitionID);
verticesToBeSent.setVertexType(vertexClass);
orbClients.get(partitionID).sendVertices(pvo.partitionVertexList.get(partitionID));
}
}
}
use of org.goldenorb.Vertices in project goldenorb by jzachr.
the class OutboundVertexQueue method sendVertex.
/**
* This method queues up a Vertex to be sent. Once the Vertex count reaches the maximum number, it sends the
* vertices via Hadoop RPC.
*
* @param v
* - a Vertex to be sent
*/
public void sendVertex(Vertex<?, ?, ?> v) {
synchronized (pvo) {
int vertexHash = Math.abs(v.getVertexID().hashCode()) % numberOfPartitions;
Vertices currentPartition = pvo.partitionVertexList.get(vertexHash);
Integer vertexCounter;
synchronized (pvo.partitionVertexCounter) {
synchronized (currentPartition) {
vertexCounter = pvo.partitionVertexCounter.get(vertexHash);
vertexCounter++;
pvo.partitionVertexCounter.set(vertexHash, vertexCounter);
currentPartition.add(v);
// once the expected number of vertices is met, begins the send operation
if (vertexCounter >= maxVertices) {
Vertices verticesToBeSent = currentPartition;
Vertices vs = new Vertices(vertexClass);
// logger stuff
ovqLogger.info(this.toString() + " Partition: " + Integer.toString(partitionId) + " Sending bulk vertices. Count: " + vertexCounter + ", " + verticesToBeSent.size());
verticesToBeSent.setVertexType(vertexClass);
orbClients.get(vertexHash).sendVertices(verticesToBeSent);
currentPartition = vs;
pvo.partitionVertexCounter.set(vertexHash, new Integer(0));
}
pvo.partitionVertexList.set(vertexHash, currentPartition);
}
}
}
}
Aggregations