#random

Optimal batchSize for Typesense Imports/Upserts

TLDR Nathan asked about increasing batchSize for imports/upserts. Jason recommended keeping server-side batchSize to default 40, and suggested parallel imports up to the number of CPU cores for optimal performance.

Powered by Struct AI

2

2

typesense

2

1

6
4mo
Solved
Join the chat
May 15, 2023 (4 months ago)
Nathan
Photo of md5-aa846ac80f1164f0d27b340467fd28e2
Nathan
04:52 PM
Hello! I see the default batchSize for imports/upserts is 40. If we have more than 40 documents to upload, how should we decide between increasing batch size and making mulitple API calls?
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
05:06 PM
In general I would recommend not changing the server-side batching setting (which is the default 40 you mentioned), because what that controls is essentially how many documents need to be processed by Typesense in a single go, before it switched back to processing search requests.

So the larger the server-side batch size, the lesser priority your search requests get
05:07
Jason
05:07 PM
So if you have very low traffic and want to index as fast as possible, then setting it to a high value will help. But if you have high search traffic, then I would just let it be at the default of 40
Nathan
Photo of md5-aa846ac80f1164f0d27b340467fd28e2
Nathan
05:08 PM
Thank you!

1

07:59
Nathan
07:59 PM
Is there a benefit to running multiple imports in parallel? e.g. is 3 parallel imports of 40 documents better than a single import of 120?

Your explanation above makes me think that parallel is better, but I want to double check.
Jason
Photo of md5-8813087cccc512313602b6d9f9ece19f
Jason
08:03 PM
Yeah, parallel is better, roughly up to the number of CPU cores you have

2

2

typesense

2