rebus-org / Rebus.SqlServer

:bus: Microsoft SQL Server transport and persistence for Rebus
https://mookid.dk/category/rebus
Other
44 stars 45 forks source link

Question: Do I have to do any work to optimize sending multiple messages. #96

Open macchmie3 opened 2 years ago

macchmie3 commented 2 years ago

Hi, my question is simple - Let's assume I want to send 10000 messages, while being in a message handler already. Can I do optimization in any way? I see no API methods for sending a collection of messages and I was wondering if there are any ways to optimize work in such case. Current code would be something of a sort:

foreach (var message in messages)
{
     await _bus.Send(message);
}

I'm not sure if it helps, but I use SqlServer in leased mode as transport layer.

macchmie3 commented 2 years ago

I have checked with sql profiler that all messages are sent in a single transaction, but are done via single insert operations, is there a way to insert multiple rows in a single db operation?

mookid8000 commented 2 years ago

Not at the moment, no.

But it would definitely be possible for the SQL transport to optimize this, simply by storing messages to be sent in the transaction context, and then do the insertion when committing the message transaction.

mookid8000 commented 2 years ago

I can take a look at this myself when my summer holiday is over 😎 or if anyone feels like fixing it and submit a PR, I'll be happy to be here with guidance.

mookid8000 commented 1 year ago

I left a half implementation here: https://github.com/rebus-org/Rebus.SqlServer/tree/feature/batching

Will come back to it soon. 🙂