Last active
August 29, 2015 14:05
-
-
Save spmallette/78176e56ebcca1395389 to your computer and use it in GitHub Desktop.
test out driver for "batch loading"
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
import org.apache.commons.lang.RandomStringUtils | |
g = Neo4jGraph.open('/tmp/neo4j-test') | |
vertexCount = 500 | |
edgeCount = 5000 | |
rand = new Random() | |
ids = new java.util.concurrent.CopyOnWriteArrayList() | |
clock(1) { | |
(0..<vertexCount).each{ | |
def v = g.addVertex('name',RandomStringUtils.random(32),'age',rand.nextInt(99)+1,'description',RandomStringUtils.random(256)) | |
if (it % 100 == 0) g.tx().commit() | |
ids << v.id() | |
};null | |
(0..<edgeCount).each{ | |
def v1 = g.v(ids[rand.nextInt(vertexCount)]) | |
def v2 = g.v(ids[rand.nextInt(vertexCount)]) | |
def bindings = [w:rand.nextDouble(),id1:v1,id2:v2] | |
v1.addEdge('knows',v2,'weight',rand.nextDouble()) | |
if (it % 100 == 0) g.tx().commit() | |
};null | |
} |
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
import org.apache.commons.lang.RandomStringUtils | |
g = Neo4jGraph.open('/tmp/neo4j-test') | |
vertexCount = 500 | |
edgeCount = 5000 | |
rand = new Random() | |
ids = new java.util.concurrent.CopyOnWriteArrayList() | |
clock(1) { | |
(0..<vertexCount).each{ | |
def v = g.addVertex('name',RandomStringUtils.random(32),'age',rand.nextInt(99)+1,'description',RandomStringUtils.random(256)) | |
g.tx().commit() | |
ids << v.id() | |
};null | |
(0..<edgeCount).each{ | |
def v1 = g.v(ids[rand.nextInt(vertexCount)]) | |
def v2 = g.v(ids[rand.nextInt(vertexCount)]) | |
def bindings = [w:rand.nextDouble(),id1:v1,id2:v2] | |
v1.addEdge('knows',v2,'weight',rand.nextDouble()) | |
g.tx()commit() | |
};null | |
} |
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
Gremlin.use("com.tinkerpop.rexster","rexster-protocol","2.5.0") | |
import org.apache.commons.lang.RandomStringUtils | |
import com.tinkerpop.rexster.client.* | |
client = RexsterClientFactory.open("localhost","neo4jsample") | |
vertexCount = 500 | |
edgeCount = 5000 | |
rand = new Random() | |
ids = new java.util.concurrent.CopyOnWriteArrayList() | |
clock = { int loops = 100, Closure closure -> | |
closure.call() // warmup | |
(1..loops).collect { | |
t = System.nanoTime() | |
closure.call() | |
((System.nanoTime() - t) * 0.000001) | |
}.mean() | |
} | |
clock(1) { | |
(0..<vertexCount).each{ | |
def bindings = [n:RandomStringUtils.random(32),a:rand.nextInt(99)+1,d:RandomStringUtils.random(256)] | |
ids << client.execute("v = g.addVertex([name:n,age:a,description:d]);v.id()",bindings).get(0) | |
};null | |
(0..<edgeCount).each{ | |
def v1 = ids[rand.nextInt(vertexCount)] | |
def v2 = ids[rand.nextInt(vertexCount)] | |
def bindings = [w:rand.nextDouble(),id1:v1,id2:v2] | |
client.execute("v1 = g.v(id1);v2 = g.v(id2);g.addEdge(v1, v2,'knows',[weight:w])",bindings) | |
};null | |
} |
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
import com.tinkerpop.gremlin.driver.* | |
import org.apache.commons.lang.RandomStringUtils | |
sessionId = UUID.randomUUID() | |
cluster = Cluster.open() | |
client = cluster.connect(sessionId.toString()) | |
vertexCount = 500 | |
edgeCount = 5000 | |
rand = new Random() | |
ids = new java.util.concurrent.CopyOnWriteArrayList() | |
clock(1) { | |
(0..<vertexCount).each{ | |
def bindings = [n:RandomStringUtils.random(32),a:rand.nextInt(99)+1,d:RandomStringUtils.random(256)] | |
ids << client.submit("v = g.addVertex('name',n,'age',a,'description',d);v.id()",bindings).one().getLong() | |
if (it % 1000 == 0) client.submit("g.tx().commit()").all().get() | |
};null | |
(0..<edgeCount).each{ | |
def v1 = ids[rand.nextInt(vertexCount)] | |
def v2 = ids[rand.nextInt(vertexCount)] | |
def bindings = [w:rand.nextDouble(),id1:v1,id2:v2] | |
client.submit("v1 = g.v(id1);v2 = g.v(id2);v1.addEdge('knows',v2,'weight',w);1",bindings) | |
if (it % 1000 == 0) client.submit("g.tx().commit()").all().get() | |
};null | |
client.submit("g.tx().commit()").all().get() | |
} |
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
import org.apache.commons.lang.RandomStringUtils | |
cluster = Cluster.open() | |
client = cluster.connect() | |
vertexCount = 500 | |
edgeCount = 5000 | |
rand = new Random() | |
ids = new java.util.concurrent.CopyOnWriteArrayList() | |
clock(1) { | |
(0..<vertexCount).each{ | |
def bindings = [n:RandomStringUtils.random(32),a:rand.nextInt(99)+1,d:RandomStringUtils.random(256)] | |
ids << client.submit("v = g.addVertex('name',n,'age',a,'description',d);v.id()",bindings).one().getLong() | |
};null | |
(0..<edgeCount).each{ | |
def v1 = ids[rand.nextInt(vertexCount)] | |
def v2 = ids[rand.nextInt(vertexCount)] | |
def bindings = [w:rand.nextDouble(),id1:v1,id2:v2] | |
client.submit("v1 = g.v(id1);v2 = g.v(id2);v1.addEdge('knows',v2,'weight',w)",bindings) | |
};null | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment