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. Testing, Deployment, and Maintenance
  3. Deployment
  4. Solr update performance

Solr update performance

Bas De Nooijer user avatar by
Bas De Nooijer
·
Apr. 11, 11 · News
Like (0)
Save
Tweet
Share
14.25K Views

Join the DZone community and get the full member experience.

Join For Free
When I started working with Solr I issued updates just like I was used to do with databases: a single command followed by a commit. Later I discovered this was far from optimal, and started using different update strategies.

To demonstrate the differences I’ve done some simple benchmarks with three different update strategies, and as you will see the performance difference can be huge. I will also give some tips on how to easily optimize the updates in your application.

The benchmark scripts were built in PHP with Solarium. I’ve left out the setup part in the tests, see the Solarium wiki for more info about using Solarium.
I used two systems on a local network, one running Solr and one running the PHP client. This adds some network latency, so results for a local Solr might vary.
The Solr index has just over 100K documents. Each of the test scripts will add 1000 documents to this index.

First test: adding and committing each document

This test commits each single document. A very common scenario. Normally this would be spread out over time, but for the benchmark I do a thousand add/commits in a loop:

$start = microtime(true);

for ($id = 8000000; $id < 8001000; $id++) {
    $document = new Solarium_Document_ReadWrite;
    $document->id = $id;
    $document->name = 'test';

    $query = new Solarium_Query_Update;
    $query->addDocument($document);
    $query->addCommit();
    $client->update($query);
}

echo round(microtime(true)-$start, 2);

Result: 12.04 seconds (83 documents per second)

The performance difference is caused by Solr having to do only a single commit instead of a thousand. This test issues the same number of Solr requests (actually +1 for the commit) so network latency should be the same.

Third test: adding and committing all documents in a single request

The final test combines the complete update into a single Solr request. While the commands are now issues in a single request, it is still the exact same set of commands as used in the second test.

$start = microtime(true);

$query = new Solarium_Query_Update;
for ($id = 8002000; $id < 8003000; $id++) {
    $document = new Solarium_Document_ReadWrite;
    $document->id = $id;
    $document->name = 'test';
    $query->addDocument($document);
}

$query->addCommit();
$client->update($query);

echo round(microtime(true)-$start, 2);

Result: 0.45 seconds (2220 documents per second)

The performance difference is caused by a lower number of requests. A lower number of requests is more optimal in multiple layers. Most importantly network latency, but less requests also mean less overhead in Solarium and Solr.

How to optimize updates

As you can see from the results the performance difference can be huge. The most optimal update strategy for your application will depend on multiple factors. First of all you need to determine how you are going to update:

  • batch updates, e.g. a nightly update cron or other fixed interval
  • continuous (maybe even concurrent) updates, e.g. based on user input
  • or maybe a combination of both

For batch updates you will probably get the best performance with a solution similar to the third test. For very big updates you might need to break it up into several requests, followed by a single commit. How to implement this depends on the Solr client library you use. As you can see it is quite easy using Solarium.

If you have continuous updates you should prevent issuing commits with each update. This can cause a high number of commits or even concurrent commits.
The easiest solution for this scenario is using the Solr ‘autoCommit’ feature. This way you can add documents without worrying about when to commit. You only need to a a single setting to your Solr config and remove commits.

Disclaimer
The results of these benchmarks are influenced by many factors: index size, document size, index schema, update frequency, hardware, network, solr configuration and many more factors. The tests are a worst-case scenario, if you use single update+commits but they are spread out enough it might not be an issue at all.
You should really run your own tests in your own environment with a realistic workload to validate the results.

Testing Commit (data management) Document Requests

Published at DZone with permission of Bas De Nooijer, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Create a Real-Time Scalable Streaming App Using Apache NiFi, Apache Pulsar, and Apache Flink SQL
  • Implementing Infinite Scroll in jOOQ
  • Promises, Thenables, and Lazy-Evaluation: What, Why, How
  • How to Rescue Your Magento 2 Project

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: