Write speed degrades with pure writes and a few threads, client/server OrientDB 1.3.0

Note: Issue #1202 may have the same underlying cause.
See attached performance plot / story board. Test code also attached. Server/client info is at the bottom.
OrientDB server was started with default config (except for root password). OrientDB server was started in a shell via ./bin/server.sh. Restarts used CTRL-C to shutdown.
The client was setup to execute 50 loops per run. Each loop spawns 5 threads. Each thread saves 10000 ODocuments (10 txns with 1000 odocs/txn and TXTYPE.NOTX). 2.5 million documents were saved per run. Each loop waited for all threads to complete via join() before continuing.
The client created a connection pool for the threads with the pool class from OrientDB. The pool was set up for min=100, max=200. Each thread got its database connection from the pool and called db.close() after completion of its task.
Performance was approx (avg) 15-20k saves/sec on a freshly-started OrientDB database. Degradation in performance (0-5k saves/sec) occurred that correlated to the server's memory usage.
Memory usage was observed via the 'top' command in a shell. The server process was observed to be increasing memory usage (normal) during the client's run. Upon, hitting an apparent memory usage limit (~1.3G) the performance degraded to 0-5k saves/sec. Warnings on lost/reconnected connections occurred sporadically during the performance degradation.
Re-run of client (new JVM) did not improve the degradation. Restart of server brought performance back to original level but it then degraded again when memory usage saturated.
Server: OrientDB 1.3.0, Debian Linux 64bit kernel 2.6.32-5-amd64, Intel Q9550, 4GB RAM java version "1.6.0_18" OpenJDK Runtime Environment (IcedTea6 1.8.13) (6b18-1.8.13-0+squeeze2) OpenJDK 64-Bit Server VM (build 14.0-b16, mixed mode)
Client: OrientDB 1.3.0, Windows 2003 Server Enterprise x64 Service Pack 2, Intel Q9550, 6GB RAM java version "1.7.0_09" Java(TM) SE Runtime Environment (build 1.7.0_09-b05) Java HotSpot(TM) Client VM (build 23.5-b02, mixed mode)
Client code
Edit: this is the original posted code and has the following errors. These errors have not been shown as significant to the problem at hand. See later comments on code-fixes in the thread.
- Each loop of the 5-thread test re-creates the connection pool
- Each thread does 10000 saves/txn instead of 1000 saves in 10 txns
package com.sandboxorientdb;
import java.util.ArrayList;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentPool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
public class OrientDbWriteLotsOfDataTest {
private static final String DBURI = "remote:server/database";
private static final String DBUSR = "admin";
private static final String DBPWD = "admin";
private static final String CLASSNAME = "WriteLotsTestClass";
private static final String PROPKEY = "key";
private static final String PROPVAL = "value";
public static void main(String[] args) throws InterruptedException {
OrientDbWriteLotsOfDataTest test = new OrientDbWriteLotsOfDataTest();
//loop: for each loop, a set of threads writes to the database
//each thread writes 10000 odocs to the database with 1000 odocs/txn
for (int k = 0; k < 50; k++) {
test.testThreaded(5,TXTYPE.NOTX);
System.out.printf("finished run %d:\n", k);
}
}
public void testThreaded(int numthreads,TXTYPE txtype) throws InterruptedException {
//create document pool
ODatabaseDocumentPool pool = new ODatabaseDocumentPool(DBURI, DBUSR, DBPWD);
pool.setup(100, 200);
//create the schema for the test class if it doesn't exist
ODatabaseDocumentTx db = pool.acquire();
try {
OSchema schema = db.getMetadata().getSchema();
if (!schema.existsClass(CLASSNAME)) {
OClass oc = schema.createClass(CLASSNAME);
oc.createProperty(PROPKEY, OType.STRING);
oc.setStrictMode(true);
schema.save();
}
}
finally {
db.close();
}
//create threads and execute
try {
//create threads, put into list
ArrayList<RunTest> threads = new ArrayList<RunTest>(1000);
for (int numth = 0; numth < numthreads; numth++) {
threads.add(new RunTest(pool,txtype));
}
//run test: start each thread and wait for all threads to complete with join
long a = System.currentTimeMillis();
for (RunTest t : threads) {
t.start();
}
for (RunTest t : threads) {
t.join();
}
long b = System.currentTimeMillis();
//collect from each thread
int savesum = 0;
int txnsum = 0;
for (RunTest t : threads) {
t.printStats();
savesum += t.getTotalSaves();
txnsum += t.getTotalTxns();
}
//print out cummulative stats
double secs = 1.0E-3D * (b - a);
System.out.printf("TOTAL: [%4.2f secs %d tx, %d save] %.2f tx/sec %.2f save/sec \n", secs, txnsum, savesum, txnsum
/ secs, savesum / secs);
}
finally {
pool.close();
}
}
class RunTest extends Thread {
private ODatabaseDocumentTx db;
private int statTotalTxn;
private int statTotalSaves;
private double statTotalSecs;
private TXTYPE txtype;
public RunTest(ODatabaseDocumentPool pool, TXTYPE txtype) {
this.txtype = txtype;
this.db = pool.acquire();
}
public int getTotalTxns() {
return this.statTotalTxn;
}
public int getTotalSaves() {
return this.statTotalSaves;
}
public double getTotalSecs() {
return this.statTotalSecs;
}
public void printStats() {
long thid = this.getId();
int ntx = this.getTotalTxns();
int nsave = this.getTotalSaves();
double secs = this.getTotalSecs();
System.out.printf("Thd%2d: [%4.2f secs %d tx, %d save] %.2f tx/sec %.2f save/sec \n", thid, secs, ntx, nsave, ntx
/ secs, nsave / secs);
}
@Override
public void run() {
try {
int savecount = 0;
int txncount = 0;
long t0, t1;
switch (this.txtype) {
case NOTX: {
t0 = System.currentTimeMillis();
final ODocument foo = new ODocument();
db.begin(TXTYPE.NOTX);
int ktxn;
for (ktxn = 0; ktxn < 10; ktxn++) {
int ksave;
for (ksave = 0; ksave < 1000; ++ksave) {
foo.reset();
foo.setClassName(CLASSNAME);
foo.field(PROPKEY,PROPVAL);
db.save(foo);
}
savecount += ksave;
}
db.commit();
txncount += ktxn;
t1 = System.currentTimeMillis();
break;
}
case OPTIMISTIC: {
t0 = System.currentTimeMillis();
db.begin(TXTYPE.OPTIMISTIC);
int ktxn;
for (ktxn = 0; ktxn < 10; ktxn++) {
int ksave;
for (ksave = 0; ksave < 1000; ++ksave) {
ODocument foo = new ODocument(CLASSNAME);
foo.field(PROPKEY,PROPVAL);
db.save(foo);
}
savecount += ksave;
// this.totalcounter.addAndGet(ksave);
}
db.commit();
txncount += ktxn;
t1 = System.currentTimeMillis();
break;
}
default:
throw new Error("unknown txtype: " + txtype);
}
this.statTotalSaves = savecount;
this.statTotalTxn = txncount;
this.statTotalSecs = 1.0E-3 * (t1 - t0);
}
catch (Exception e) {
db.rollback();
throw e;
}
finally {
db.close();
}
}
}
}
I wonder if you are hitting the same performance degradation issue that I hit, or something different. In my case, I only used a single thread, but I was doing a massive insert of a couple GB of binary data. My problem seemed to be due to Orient or my machine running out of memory mapping space. I found that orient's OFileMMap.map() was spending the bulk of its time sleeping inside of sun.nio.ch.FileChannelImpl.map(), just waiting for memory space to free up. See https://github.com/nuvolabase/orientdb/issues/1202
Yep, I saw your issue #1202 and figured it could be the same underlying problem. I am not familiar with the ORecordBytes functionality. I already had the plots of performance for what I figured was a more "vanilla" usage (simple db.save(ODocument)) so I posted this issue. The OrientDB team can decide to join the issues if they find them to have the same underlying cause. I'm going to update my issue to point to yours.
Also, #1202 states that a 1.3.0-SNAPSHOT and local build/compile was being used. This issue is against the released version.
I've also seen some errors being reported from OMemoryWatchdog (might not be the right name, though 'Watchdog' is right).
In addition, after this test is performed to the point that the server just stops accepting connections, the server stops responding through localhost (on server) console access via ./bin/console.sh.
Hey thanks for the so detailed report and test case! We're started a deep analysis to fix it asap.
Could you try the same test with this option in jvm: -Dfile.mmap.strategy=4 ?
OrientDB 3.1.0: started server with default config (except root password). start console ./bin/console.sh
connect remote:localhost/mydatabase root mypassword
drop mydatabase
create database local:../databases/mydatabase admin admin local document
shutdown server in shell with CTRL-C
copied ./bin/server.sh to ./bin/server-issue1339a.sh
modified ./bin/server-issue1339a.sh as follows
FROM:
ORIENTDB_SETTINGS="-Dprofiler.enabled=true -Dcache.level1.enabled=false -Dcache.level2.strategy=1"
TO:
ORIENTDB_SETTINGS="-Dprofiler.enabled=true -Dcache.level1.enabled=false -Dcache.level2.strategy=1 -Dfile.mmap.strategy=4"
started server in shell with ./bin/server-issue1339a.sh
connected with ./bin/console.sh --> empty database as expected
running test code via eclipse juno SR1
..waiting..
Initial loops are showing about 60% saves/sec of original performance (10k saves/sec vs. 15-20k)
Performance degradation is still observed near end of test run.

Hey, I run your test case against my Mac Book Pro using default settings. Client and server both on localhost.
Thd368: [1,48 secs 10 tx, 10000 save] 6,77 tx/sec 6765,90 save/sec Thd369: [1,48 secs 10 tx, 10000 save] 6,76 tx/sec 6761,33 save/sec Thd370: [1,48 secs 10 tx, 10000 save] 6,77 tx/sec 6770,48 save/sec Thd371: [1,49 secs 10 tx, 10000 save] 6,73 tx/sec 6734,01 save/sec Thd372: [1,48 secs 10 tx, 10000 save] 6,76 tx/sec 6761,33 save/sec TOTAL: [1,49 secs 50 tx, 50000 save] 33,67 tx/sec 33670,03 save/sec finished run 49:
I noticed that is I re-run the test after short time the previous one is finished the performance drop down, otherwise are always constant. I think this is how MMAP works but the strange is that happens even without the usage of mmap.
By the way I never restarted the server, but just waited 2 minutes.
FYI, I found an error in the posted test code. It was creating a new connection pool during each 5-thread loop instead of re-using the pool for each run of 50 loops. I fixed it and re-ran the test. It did not fix the write-speed degradation previously observed. Just wanted to let all know.
Hi WG,
Thank you for the interesting test case. I have got 2 comments for you: 1. I have spotted a difference between the test scenario description and the actual implementation. Just to let you know. It seems you commit only once per thread: 1txn with 10kdocs (not 10txns x 1000 docs/txn as you expected) Note that the docs creation loops are enclosed in a single transaction...
- Concerning memory utilization. I have evaluated the OrientDB for a some time and I noticed the persistence layer cache (cache level2) could be a devil for a heap memory size. Especially if embedded on the application with intensive write/read operations.
Level2 cache is turned on in out-of-the box installation with the unspecified limit for its size . What you could do, I believe, to reduce memory usage is setting the cache2 limit on the server side (-Dcache.level2.size=?) or even better disabling it (-Dcache.level2.enabled=false) in order to measure the core performance of the server (without cache support). Hope it could help.
Regards, Dan.
Bugs in the test code were fixed; test was re-run
I fixed the errors in the posted test code and re-ran the test. I observed similar degradation in speed (loops 251-400). Performance prior to the degradation was not really affected by the code fixes. Slightly lower write speed was observed than previously when using the default server.sh start-up script (loop 351-400).
Level 2 cache was disabled on the server; test was re-run
I then disabled level2 cache as recommended by @dm-ordb. The degradation was not observed (loops 401-500). The server's res memory usage was smaller: 500MB vs 1.3GB.
Plot of changes' impacts on performance
The bug fixes and level 2 cache disable occurred when shown in the plot.

Change notes
Errors were fixed in the following versions of the test code:
- v2: connection pool was being created for each test loop (per @wgtthompson)
- v3: test code was doing 10k saves in 1 txn instead of 1k saves in 10 txns (per @dm-ordb)
The server start-up script was modified to disable level 2 cache. Modifications to server-issue1339b.sh (from default server.sh) are shown below.
FROM: ORIENTDB_SETTINGS="-Dprofiler.enabled=true -Dcache.level1.enabled=false -Dcache.level2.strategy=1"
TO: ORIENTDB_SETTINGS="-Dprofiler.enabled=true -Dcache.level1.enabled=false -Dcache.level2.enabled=false -Dfile.mmap.strategy=4"
Good you found the solution. We've almost ready a off-heap cache to use in OrientDB and it will be released with 1.4.0. I think it will solve all the problems about speed and memory.
Hi WG,
Would you be so kind to re-run your test once more with the memory mapping settings reverted (just remove -Dfile.mmap.strategy=4 to turn memory mapping on again). If we are lucky the performance speed would be higher (~16-22k) hopefully without degradation in time.
Regards, Dan.
Per @dm-ordb request, I created server-issue1339c.sh and removed -Dfile.mmap.strategy=4. I ran 4 50-loop runs. Performance almost returned to earlier levels. No degradation occurred.

Change Notes
Server start-up script modification
FROM: (server-issue1339b.sh)
ORIENTDB_SETTINGS="-Dprofiler.enabled=true -Dcache.level1.enabled=false -Dcache.level2.enabled=false -Dfile.mmap.strategy=4"
TO: (server-issue1339c.sh)
ORIENTDB_SETTINGS="-Dprofiler.enabled=true -Dcache.level1.enabled=false -Dcache.level2.enabled=false"
Similar problem with L2 cache on client-side
I tried to modify my test class to 500 loop/run from 50 loop/run. The test start to fail/degrade on the 100th loop (+/- 30 loops). After restarting the test (client: new JVM, server: untouched), the performance came back to normal and then degraded again around the 100th loop. I think this will depend on how much memory you have on your system and the memory settings of the JVM.
I did a memory dump a bit before the error messages started to appear. I isolated the problem to L2 cache on the client via VisualVM (painfully).
By default, the L2 cache is enabled, has unlimited size, and has a "pop" strategy (remove object from cache when requested from the cache). Since my test never reads, the L2 cache just fills up and up ... and up. The memory dump showed about 4M object in L2 when the performance started to degrade. There is a LowMemoryWatchdog that is supposed to drain L2 when memory is low but I guess that's not working so well?
So I disabled L2 cache on client as well.
OGlobalConfiguration.CACHE_LEVEL2_ENABLED.setValue(false);
Here's some results. Doing 500 loops/run worked fine, ~20k saves/sec.
BTW, this is with all of the previous changes described on this thread issue #1339.
Memory analysis (lots and lots of cached objects, L2 enabled, )

Memory profile (with Orient 1.3.0 client defaults, P.S. client L2 cache is enabled by default)

Memory profile (with Orient 1.3.0 client defaults, EXCEPT client L2 cache disabled)

Here is the plot from the previous comment concerning 500 loop/run and client L2 cache being disabled.

Hi WG,
Thank you very much. Nice, I am in a hurry to disable L2 cache on client side of our application too... ;-)
Well the problem is that soon or a later the cache L2 should be turned on for massive reads. Maybe OrientDB fellows could drop a line on how L2 cache could be optimized to combine both writes and reads efficiency without performance degradation.
Regards, Dan.
Hi Dan, we've at 90% the new cache that works out of heap. That will replace the current one asap, so L2 cache will do the job it was designed!
Lvc@
On 13 February 2013 12:51, dm-ordb [email protected] wrote:
Hi WG,
Thank you very much. Nice, I am in a hurry to disable L2 cache on client side of our application too... ;-)
Well the problem is that soon or a later the cache L2 should be turned on for massive reads. Maybe OrientDB fellows could drop a line on how L2 cache could be optimized to combine both writes and reads efficiency without performance degradation.
Regards, Dan.
— Reply to this email directly or view it on GitHubhttps://github.com/nuvolabase/orientdb/issues/1339#issuecomment-13487409.
Fixed log time ago with plocal and new indexes.