I am evaluating the performance of Neo4j graph database with a simple benchmark for insert, update, delete and query. Using Neo4j OGM I see significantly slower execution times (about 2-4 times) compared to the direct access via Neo4j driver. For example, delete operation (see code below) is done in 500ms vs 1200ms for 10K nodes and 11K relations on my machine. I wonder why this happens, especially because the below code for deletion doesn't even use any node entity. I can imagine that OGM has some overhead but this seems to be too much. Anyone has an idea why it's slower?
Example node:
public abstract class AbstractBaseNode {
@GraphId
@Index(unique = true)
private Long id;
public Long getId() {
return id;
}
}
@NodeEntity
public class Company extends AbstractBaseNode {
private String name;
public Company(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Example code for delete via driver:
driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "secret" ) );
session = driver.session();
long start = System.nanoTime();
session.run("MATCH (n) DETACH DELETE n").list();
System.out.println("Deleted all nodes " + ((System.nanoTime() - start) / 1000) + "μs");
Example code for delete via OGM:
public org.neo4j.ogm.config.Configuration neo4jConfiguration() {
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
config.autoIndexConfiguration().setAutoIndex(AutoIndexMode.DUMP.getName());
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.bolt.driver.BoltDriver")
.setURI("bolt://neo4j:secret@localhost")
.setConnectionPoolSize(10);
return config;
}
sessionFactory = new SessionFactory(neo4jConfiguration(), "net.mypackage");
session = sessionFactory.openSession();
long start = System.nanoTime();
session.query("MATCH (n) DETACH DELETE n", Collections.emptyMap()).forEach(x -> {});
System.out.println("Deleted all nodes " + ((System.nanoTime() - start) / 1000) + "μs");
session.query
to create records as well, results seems to be almost indistinguishable. – SergGr