Tuning the Document API

This guide is specific for the Document Database. Please be sure to read the generic guide to the Performance-Tuning.

Massive Insertion

See Generic improvement on massive insertion.

Avoid document creation

You can avoid the creation of a new ODocument for each insertion by using the ODocument.reset() method that clears the instance making it ready for a new insert operation. Bear in mind that you will need to assign the document with the proper class after resetting as it is done in the code below.

NOTE: This trick works ONLY IN NON-TRANSACTIONAL contexts, because during transactions the documents could be kept in memory until commit.

Example:

  1. import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
  2. db.declareIntent( new OIntentMassiveInsert() );
  3. ODocument doc = new ODocument();
  4. for( int i = 0; i < 1000000; ++i ){
  5. doc.reset();
  6. doc.setClassName("Customer");
  7. doc.field("id", i);
  8. doc.field("name", "Jason");
  9. doc.save();
  10. }
  11. db.declareIntent( null );