Sitemap
idealo Tech Blog

👨‍💻👩‍💻 idealo tech and product folks writing about their work 💡⚙️💻 🛒 and their endeavour to build, ship and run a great user experience at https://idealo.de

Advanced MongoDB Performance Tuning

6 min readJun 14, 2021

--

Introduction

A brief overview of the architecture. Event Processor cannot increase the throughput (2K) without disrupting the API’s reading performance.

1. Index optimization

Not all fields in the query filter have a matching index.
All fields in the query filter have a matching index. Also the query is modified to match the compound index.
QueryPlan“planSummary”: “IXSCAN { productId: 1, siteId: 1, segments: 1}, IXSCAN { parentProductId: 1, siteId: 1, segments: 1}”,
“inputStage”: { . . . ,
“nReturned”: 20, “docsExamined”:20, . .}
Left: The bigger the green circle, the larger the occurrence of Slow Queries.
The higher the red circle, the slower the Slow Queries.
Right: 99% reduction on the occurrence while 1% rest under <~200ms.

2. Compressing the biggest JSON Field

P99 latency is 4X more than P90
JSON Document on average had 3000+ lines. More the offer a product has, bigger the offerList array.

We realised that a JSON Document this big cannot move any faster. We stretched the “self-contained” Document DB nature to its limit.

Compression done before writing & Decompression done after reading, all in app-level.
Left: Compression ratio, higher the better. Right: Decompression time taken, lower the better
{
"_id": "{...}",
"offerListId" : "XXXXXXXXXXX",
"parentProductId" : NumberLong(5380287),
"olBytes": BinData(0, "KLUv/WCRNv1KAFp23BU2MIu2AUBeWCiw......."),
"rawLen" : NumberInt(14225)
}
Compressed version beats plain version by 2X-3X faster in all percentiles.
99.96% of Slow Queries are gone with compression. The first 2 images are in daily mode & the last one in weekly mode.
API Response time P99 dropped to a constant <100ms
Reduce JVM heap usage by apps
Reduced network traffic between apps & MongoDB
DB queries completing in < 15ms

3. Kafka batching + MongoDB BulkOperations

BulkOperations bulkOps 
= mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED);
bulkOps.upsert(upsertList);
bulkOps.updateMulti(deletList);
return bulkOps.execute();

4. Controlled Deletes by Mark-Sweep

Implementing the Mark-Sweep

Left: Constant delete rate by scheduler irrespective of the count of incoming delete events. Right: Growing and shrinking ‘Delete’ marked Documents

Conclusion

--

--

Published in idealo Tech Blog

👨‍💻👩‍💻 idealo tech and product folks writing about their work 💡⚙️💻 🛒 and their endeavour to build, ship and run a great user experience at https://idealo.de

Responses (1)