Thiago Negri
Thiago Negri

Reputation: 5351

OrientDB slow write

OrientDB official site says:

On common hardware stores up to 150.000 documents per second, 10 billions of documents per day. Big Graphs are loaded in few milliseconds without executing costly JOIN such as the Relational DBMSs.

But, executing the following code shows that it's taking ~17000ms to insert 150000 simple documents.

import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.record.impl.ODocument;

public final class OrientDBTrial {

    public static void main(String[] args) {
        ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/foo");
        try {
            db.open("admin", "admin");

            long a = System.currentTimeMillis();
            for (int i = 1; i < 150000; ++i) {
                final ODocument foo = new ODocument("Foo");
                foo.field("code", i);
                foo.save();
            }
            long b = System.currentTimeMillis();
            System.out.println(b - a + "ms");

            for (ODocument doc : db.browseClass("Foo")) {
                doc.delete();
            }
        } finally {
            db.close();
        }
    }

}

My hardware:

What am I doing wrong?

Splitting the saves in 10 concurrent threads to minimize Java's overhead made it run in ~13000ms. Still far slower than what OrientDB front page says.

Upvotes: 11

Views: 3886

Answers (3)

Krisztian Kocsis
Krisztian Kocsis

Reputation: 39

Read the documentation first on how to achive the best performance!

Few tips:

-> Do NOT instantiate ODocument always:

  final ODocument doc;
  for (...) {
    doc.reset();
    doc.setClassName("Class");
    // Put data to fields
    doc.save();
  }

-> Do NOT rely on System.currentTimeMillis() - use perf4j or similar tool to measure times, because the first one measures global system times hence includes execution time of all other programs running on your system!

Upvotes: 3

gusto2
gusto2

Reputation: 12075

The numbers from the OrientDB site are benchmarked for a local database (with no network overhead), so if you use a remote protocol, expect some delays.

As Krisztian pointed out, reuse objects if possible.

Upvotes: 3

user781903
user781903

Reputation: 153

You can achieve that by using 'Flat Database' and orientdb as an embedded library in java see more explained here http://code.google.com/p/orient/wiki/JavaAPI

what you use is server mode and it sends many requests to orientdb server, judging by your benchmark you got ~10 000 inserts per seconds which is not bad, e.g I think 10 000 requests/s is very good performance for any webserver (and orientdb server actually is a webserver and you can query it through http, but I think java is using binary mode)

Upvotes: 4

Related Questions