Java – Orient DB slow write
The official website of orientdb says:
However, executing the following code can show that it takes 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:
>Dell OptiPlex 780 > Intel (R) core (TM) 2 Duo CPU E7500 @ 2.93GHz > 8GB ram > Windows 7 64 bit
What on earth did I do wrong?
Split and save in 10 concurrent threads to minimize the overhead of Java and make it run at about 13000s It is still far below what orientdb said on its home page
Solution
You can use "flat database" and orientdb as embedded libraries in Java
You use the server mode and send many requests to the orientdb server. According to your benchmark judgment, you can get ~ 10000 inserts per second, which is good. For example, I think 10000 requests are very good performance for any web server (and the orientdb server is actually a web server. You can query it through HTTP, but I think Java is using binary mode)