title: Are Blueprints/Gremlin graph DB queries inherently slow?
body: <p>I'm working on a proof of concept for using GraphDBs (specifically Titan 0.4.4 on HBase). For that I  created a relatively simple graph: I have companies that buy and sell products. A sale is associated with a department of the buyer:</p>
  
  <pre><code>buyer {name} --BUYS {departmentId}--&gt; product {name} &lt;--SELLS-- seller {name}
  </code></pre>
  
  <p>I filled the graph with 1000 buyers and sellers each as well as 1 million products. Each product is sold by exactly one company and bought by randomly chosen 1 to 5 departments of 1 to 6 companies. So I roughly end up with 1 million vertices and 11.5 million edges.</p>
  
  <p>Now I want to query the graph for the following: Return all products which name matches a given sub-string S bought by department D of company with name C, which I implemented like such:</p>
  
  <p>Get start vertex:</p>
  
  <pre><code>start=graph.query().has("name", C).vertices()
  </code></pre>
  
  <p>which due to the vertex index I created returns relatively quickly (after warm-up &lt; 1ms). Now to get the respective products I run this:</p>
  
  <pre><code>new GremlinPipeline(start).outE("BUYS").has("departmentId", D )
      .inV().has("name", new LowerCaseContainsPredicate(), P ).toList()
  </code></pre>
  
  <p>The response time for this against an HBase back-end (10 m3.xlarge nodes on AWS EMR) was incredibly long, with a single consumer averaging at about 1.5s per query (I picked random buyers, departments and product names and iterated 1000x), which returns around 260 product records. In order to take a possibly faulty HBase configuration out of the equation I ran it against a local BerkelyDB (4 CPUs, 8 GB VM memory, 16 GB total memory).</p>
  
  <p>This sped up the queries of course, returning in ~ 160ms for a single threaded application, which is not really a race car but still acceptable. Adding more parallel requests resulted in a quick degradation of response times, 10 parallel requests came in at avg 1.2s.</p>
  
  <p>So I ran a comparison with Neo4j 2.1.3 using this Cypher query:</p>
  
  <pre><code>start buyer=node:company(name=C) match buyer-[:BUYS {departmentId:D}]-&gt;(product) 
  where product.name =~ "(?i).*P.*" return product
  </code></pre>
  
  <p>which returns much faster (4-6x depending on number of parallel requests, ~ 50ms for single thread, ~270ms for 10 in parallel). Now there is a Blueprints implementation for Neo4j so I tried that as well to find out if it's the DB engine or the way I query that makes the difference.</p>
  
  <p>Turns out that running Gremlin queries against Neo4j is about as slow as running it against Titan - in fact it's even slightly slower.</p>
  
  <p>All tests were run as a Java application in a single VM with embedded graph DBs to avoid any networking impact. I also noticed that the very first query always takes a lot longer, so the application ran a random query first before starting the benchmark. The code is pure Java using the GremlinePipeline Java class, the snippet above is literally the Java code it is running (except for the predicate, which is only instantiated once). Cypher queries were run by using a parameterized constant query string and passing in the respective parameter map.</p>
  
  <p>This is the first time I'm using a graph DB so I'm wondering if I'm doing something fundamentally wrong with the Gremlin query or if Blueprints/Gremlin is just inherently slow.</p>