title: Neo4J Java Bolt CREATE Node is slow. How to improve it?
body: <p>I'm trying to insert a bunch of nodes Neo4J using the following code:</p>
  
  <pre><code>import org.neo4j.driver.v1.*;
  
  public class BoltClass
  {
      public static void minimalWorkingExample() throws Exception
      {
          Driver driver = GraphDatabase.driver( "bolt://localhost", AuthTokens.basic( "neo4j", "admin4j" ) );
          Session session = driver.session();
  
          int k=0;
  
          for (int i = 0; i &lt; 1000; i++) {
              int count = 1000;
              long begin = System.currentTimeMillis();
              for (int j = 0; j &lt; count; j ++) {
                  session.run("CREATE (a:Person {id:" + k + ", name:'unknown'})");
              }
              long end = System.currentTimeMillis();
              System.out.print("Inserting " + (double)count/((double)(end-begin)/count) + " nodes per second.\n");
              k++;
          }
  
          session.close();
          driver.close();
      }
  
      public static void main(String[] args)
      {
          try {
              minimalWorkingExample();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>Inserting 58.8235294117647 nodes per second.
  Inserting 76.92307692307692 nodes per second.
  Inserting 50.0 nodes per second.
  Inserting 76.92307692307692 nodes per second.
  Inserting 55.55555555555556 nodes per second.
  Inserting 62.5 nodes per second.
  Inserting 66.66666666666667 nodes per second.
  Inserting 55.55555555555556 nodes per second.
  Inserting 62.5 nodes per second.
  Inserting 55.55555555555556 nodes per second.
  Inserting 47.61904761904762 nodes per second.
  Inserting 45.45454545454545 nodes per second.
  Inserting 58.8235294117647 nodes per second.
  Inserting 83.33333333333333 nodes per second.
  </code></pre>
  
  <p>I'm using Neo4j 3.0.3 and org.neo4j.driver 1.0.4. 
  The graph was blank before the insertions.
  The machine used has an i5 2-2.6GHz CPU and 8GB RAM.</p>
  
  <p>LE: I've just discovered transactions:</p>
  
  <pre><code>public static void TransactionExample() throws Exception
  {
      Driver driver = GraphDatabase.driver( "bolt://localhost", AuthTokens.basic( "neo4j", "admin4j" ) );
      Session session = driver.session();
  
      int k=0;
      for (int i = 0; i &lt; 1000; i++) {
          int count = 1000;
          long begin = System.currentTimeMillis();
  
          try ( Transaction tx = session.beginTransaction() )
          {
              for (int j = 0; j &lt; count; j ++) {
                  tx.run("CREATE (a:Person {id:" + k + ", name:'unknown'})");
              }
              tx.success();
          }
          long end = System.currentTimeMillis();
          System.out.print("Inserting " + (double)count/((double)(end-begin)/count) + " nodes per second.\n");
          k++;
      }
      session.close();
      driver.close();
  }
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>Inserting 20000.0 nodes per second.
  Inserting 17857.142857142855 nodes per second.
  Inserting 18867.924528301886 nodes per second.
  Inserting 15384.615384615385 nodes per second.
  Inserting 19607.843137254902 nodes per second.
  Inserting 16666.666666666668 nodes per second.
  Inserting 16393.44262295082 nodes per second.
  </code></pre>
  
  <p>Nice performance boost. Can it be improved even more?</p>