Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Per Magne Skuseth
May 29, 2013
  8611
(8 votes)

EPiServer Find: Bulks, please!

Are you using Find and index lots of custom data? Improve performance by Indexing lists of objects, instead of one by one, as shown in the example below.

   1: // Not optimal 
   2: List<MyObject> objects = GetObjectsFromSomeWhere();
   3: foreach (var o in objects)
   4: {
   5:     client.Index(o);
   6: }
   1: // Better! (obviously)
   2: List<MyObject> objects = GetObjectsFromSomeWhere(); 
   3: client.Index(objects);

 

By doing this, you will significantly reduce the number of calls sent to the Find index, thus increase the general performance and decrease time taken to index.

This is fine as long as your list of objects isn’t too large, (depending on object size), but what if you have a list of 10 000 items? Or 100 000 items? Trying to index all of them at once will most likely result in a timeout error from the service. To solve this, you should split up the list and index the objects in bulks.  A simple way to do this is to create an extension method, like so:

   1: public static void IndexBulks(this IClient client, IEnumerable<object> objects, int bulkSize)
   2: {
   3:     while (objects.Any())
   4:     {
   5:         client.Index(objects.Take(bulkSize));
   6:         objects = objects.Skip(bulkSize);
   7:     }
   8: }

The extension accept a list of objects and a bulksize, and is used like this:

   1: client.IndexBulks(objects, 50);

Numbers
Indexing 1000 objects –  time taken:

  • One by one: 8 minutes, 13 seconds.
  • Bulks of 50: 4 minutes, 29 seconds. 
  • Single large bulk : As expected, the service timed out.

 

Happy indexing!

May 29, 2013

Comments

Marcus Granström
Marcus Granström May 30, 2013 10:25 AM

Very nice post Per Magne.

Thanks for sharing

Frederik Vig
Frederik Vig Oct 31, 2013 03:56 PM

Tip from Henrik Lindström: the more the better
as long as you keep below 50mb per request.

This is when calling the index method.

Henrik Fransas
Henrik Fransas Sep 27, 2018 08:46 AM

Thanks for this!

Please login to comment.
Latest blogs
Solving the mystery of high memory usage

Sometimes, my work is easy, the problem could be resolved with one look (when I’m lucky enough to look at where it needs to be looked, just like th...

Quan Mai | Apr 22, 2024 | Syndicated blog

Search & Navigation reporting improvements

From version 16.1.0 there are some updates on the statistics pages: Add pagination to search phrase list Allows choosing a custom date range to get...

Phong | Apr 22, 2024

Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog