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. Data Engineering
  3. IoT
  4. RavenDB Bulk Inserts

RavenDB Bulk Inserts

Oren Eini user avatar by
Oren Eini
·
Jan. 02, 13 · Interview
Like (0)
Save
Tweet
Share
3.29K Views

Join the DZone community and get the full member experience.

Join For Free

with ravendb bulk inserts, we significantly improved the time we take to insert a boat load of documents to ravendb. by over an order of magnitude, in fact.

how did we do that? by doing a whole bunch of things, but mostly by being smart in utilizing the resources on both client & server.

here is how a standard request timeline looks like:

image

as you can see, there are several factors that hold us up here. we need to prepare (in memory) all of the data to send. on the server side ,we wait until we have the entire dataset before we can start processing the data. just that aspect cost us a lot.

and because there is finite amount of memory we can use, it means that we have to split things to batches, and each batch is a separate request , requiring the same song and dance just on the network layer.

that doesn’t count what we have to do on the server end once we actually have the data, which is to get the data, process it, flush it to disk, register it for indexing,  call fsync, etc. that isn’t too much, unless you are trying to shove as much data s you can, as fast as you can.

in contrast, this is how the bulk insert looks like on the network:

image

we stream the results to the server directly, so while the client is still sending results , we are already flushing them to disk.

to make things even more interesting, we aren’t using standard gzip compression over the whole request. instead, each batch is compressed independently, which means we don’t have a dependency on the internals of the compression routine internal buffering system, etc. it also means that we get each batch much faster.

there are, of course, rate limits built in, to protect ourselves from flooding the buffers, but for the most part, you will have hard time hitting them.

in addition to that, because we are in the context of a single request, we can apply additional optimizations, we can do lazy flushes (not have to wait for a full fsync for each batch) because we do the final fsync at the end of the final request.

finally, we actually created an optimized code path that skips doing a lot of the things that we do in the normal path. for example, by default we assume you are doing an insert only (saves checking the disk, and will throw if not true), we don’t populate the indexing prefetching queue, etc. all in all, it means that we got more than an order of magnitude improvement.

Data (computing) Requests Memory (storage engine) Network optimization Magnitude (astronomy) Dependency Document

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

  • Best Practices for Writing Clean and Maintainable Code
  • Tech Layoffs [Comic]
  • Core Machine Learning Metrics
  • The 31 Flavors of Data Lineage and Why Vanilla Doesn’t Cut It

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: