Memory Mapping Issue - performance degrades suddenly and severely to about 500 ms per insert after inserting enough data [moved]
This is Issue 1202 moved from a Google Code project. Added by 2012-12-06T14:15:21.000Z by PatrickJMcCarty. Please review that bug for more context and additional comments, but update this bug.
Original labels: Type-Defect, Priority-Medium, Release
Original description
<b>OrientDB release? (If you're using a SNAPSHOT please attach also the build</b>
number found in "build.number" file):
Using local build of svn revision 7321, orientdb-1.3.0-SNAPSHOT, running on Oracle Java JDK 1.7.0_09. Problem still exists in svn revision 7367.
<b>What steps will reproduce the problem?</b>
1. Create a document database class that stores raw data using ORecordBytes.
2. Insert a lot of raw data, broken into smaller chunks. I used 2GiB of data with a chunk size of 81920 bytes, on machines with 2 GiB and 3.2 GiB of RAM.
<b>If you're using custom settings please provide them below (to dump all the</b>
<b>settings run the application using the JVM argument</b>
<b>-Denvironment.dumpCfgAtStartup=true):</b>
Using default settings.
<b>What is the expected output? What do you see instead?</b>
Expect each insert to take negligible time, like it does for the majority of the file. On a machine with 2GiB RAM, I instead see that performance degrades suddenly and severely starting at exactly chunk #16531 and recovers at about chunk #25593. While degraded each insert takes about 500ms.
<b>If you're describing a performance or memory problem the profiler dump can</b>
<b>be very useful (to dump it run the application using the JVM arguments</b>
<b>-Dprofiler.autoDump.reset=true -Dprofiler.autoDump.interval=10</b>
<b>-Dprofiler.enabled=true):</b>
<b>Please use labels and text to provide additional information.</b>
Details posted to the mailing list here: https://groups.google.com/d/topic/orient-database/NRnGYp4_DME/discussion
File attached that reproduces the problem on both Windows and Linux machines. Note that the problem seems related to memory mapping, and occurs at a different percentage in the file probably depending on the amount of RAM the machine has. If you use a machine with more than the 3.2 GiB of RAM that I tested with, you may need to use a larger binary file to reproduce the problem. Suggest using 3.2GiB or less of RAM and a 2 GiB file.
Pausing the application with a debugger shows the stack trace:
"pool-3-thread-1" prio=6 tid=0x034c2400 nid=0xdfc waiting on condition [0x0479e000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:841)
at com.orientechnologies.orient.core.storage.fs.OFileMMap.map(OFileMMap.java:519)
at com.orientechnologies.orient.core.storage.fs.OMMapManagerNew.mapNew(OMMapManagerNew.java:351)
at com.orientechnologies.orient.core.storage.fs.OMMapManagerNew.acquire(OMMapManagerNew.java:125)
at com.orientechnologies.orient.core.storage.fs.OFileMMap.writeShort(OFileMMap.java:378)
at com.orientechnologies.orient.core.storage.impl.local.ODataLocal.writeRecord(ODataLocal.java:654)
at com.orientechnologies.orient.core.storage.impl.local.ODataLocal.addRecord(ODataLocal.java:207)
at com.orientechnologies.orient.core.storage.impl.local.OStorageLocal.createRecord(OStorageLocal.java:1537)
at com.orientechnologies.orient.core.storage.impl.local.OStorageLocal.createRecord(OStorageLocal.java:966)
at com.orientechnologies.orient.core.db.raw.ODatabaseRaw.save(ODatabaseRaw.java:255)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.executeSaveRecord(ODatabaseRecordAbstract.java:686)
at com.orientechnologies.orient.core.tx.OTransactionNoTx.saveRecord(OTransactionNoTx.java:73)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:224)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:205)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.save(ODatabaseRecordTx.java:35)
at com.orientechnologies.orient.core.record.ORecordAbstract.save(ORecordAbstract.java:280)
at com.orientechnologies.orient.core.record.ORecordAbstract.save(ORecordAbstract.java:272)
at <my application code>
Hi, Did you use index in this test case ?
No, I did not create any index, just a very simple document database class with 3 fields, one of those being a LINKLIST of ORecordBytes. Please see the code if you want; it is pretty straightforward and is attached to the google code issue at: http://code.google.com/p/orient/issues/detail?id=1202
I think we have possible solution for given problem. We are going to create couple of types of direct memory (off - heap) caches one for new hash index and one for caching disk content (as mmap replacement). Will update you about results of our performance tests as we are done with them.
I've been working on issue #1339 which sees degradation in write speed when writing lots of data. I've found that L2 cache is hogging system RAM when writing large amounts of data. In OrientDB 1.3.0, by default, the L2 cache size is unlimited with a dynamic scheme that is supposed to drain away cached items when memory usage is detected to be too high. You may find better results if your code does this before opening a database connection.
OGlobalConfiguration.CACHE_LEVEL2_ENABLED.setValue(false);
//you could also set L2 cache to a fixed size with a different OGlobalConfiguration setting
Your example code runs OrientDB locally. If you run as server/client, then a similar issue will occur on the server. It can be fixed in OrientDB 1.3.0 by modifying the start-up scripts ($ORIENTROOT/bin/server.sh, etc) with different parameters. (See #1339)
In issue #1339, @lvca commented on a better fix coming in OrientDB 1.4.0. I think this is what @laa is talking about. (or maybe @laa commented first and this is what @lvca is talking about :-)
Hi, I tested your test case https://gist.github.com/laa/6139211 on https://github.com/orientechnologies/orientdb/wiki/plocal-storage-engine storage and it seems was fixed. You can find your case here com.orientechnologies.orient.test.database.speed.GiantFileTest in wow-cache brunch .
Fixed in develop branch for plocal storage.