DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Performance
  4. The Last RavenDB Feature of the Year: Bulk Inserts

The Last RavenDB Feature of the Year: Bulk Inserts

Oren Eini user avatar by
Oren Eini
·
Dec. 31, 12 · Interview
Like (0)
Save
Tweet
Share
2.30K Views

Join the DZone community and get the full member experience.

Join For Free

one of the most exciting new features that got into ravendb 2.0 is the notion of bulk inserts. unlike the “do batches in a loop” approach, we actually created an optimized approach and a hand crafted code path that reduce the time of the standard ravendb saves (which does a lot, but come at a cost).

in particular, we made sure that we can parallelize the operation between the client and the server, so we don’t have to build the entire request in memory on the client and then wait for it all to be in memory on the server before we can start operation. instead, we have a fully streamed operation from end to end.

here is what the api looks like:

   using (var bulkinsert = store.bulkinsert())

   {

       for (int i = 0; i < 1000*1000; i++)

       {

           bulkinsert.store(new user {name = "users #" + i});

       }

   }

this uses a single request to the server to do all the work. and here are the results:

image

this api has several limitations:

  • you must provide the id at the client side (in this case, generated via hilo).
  • it can't take part of dtc transactions
  • if you want updates, you need to explicitly state (other would throw).
  • put triggers will execute, but the aftercommit will not.
  • this bypass the indexing memory pre fetching layer.
  • changes() will not be raised for documents inserted using bulk-insert.
  • there isn't a single transaction for the entire operation, rather, this is done in batches and each batch is transactional on its own.

this is explicitly meant to drop a very large number of records to ravendb very fast, and it does this very well, typically an order of magnitude or more faster than the “batches in a loop”  approach.

a note about the last limitation, though. the whole idea here it to reduce, as much as possible, the costs of actually doing a bulk insert. that means that we can’t keep a transaction of millions of item open. instead, we periodically flush the transaction buffer throughout the process. assuming the default batch size of 512 documents, that means that an error in one of those documents will result in the entire batch of 512 being rolled back, but will not roll back previously committed batches.

this is done to reduce transaction log size and to make sure that even during a bulk insert operation, we can index the incoming documents while they are being stream in.


Document Transaction log Memory (storage engine) Requests Drops (app) Notion (music software) Build (game engine) optimization

Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Utilize OpenAI API to Extract Information From PDF Files
  • Agile Transformation With ChatGPT or McBoston?
  • What Is Policy-as-Code? An Introduction to Open Policy Agent
  • What Was the Question Again, ChatGPT?

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: