rebus-org / Rebus.RabbitMq

:bus: RabbitMQ transport for Rebus
https://mookid.dk/category/rebus
Other
62 stars 44 forks source link

1 second delay on .net framework when receiving messages #78

Closed zlepper closed 3 years ago

zlepper commented 3 years ago

There is something funky going on on .net framework when receiving messages, when there is nothing buffered in the queue. From my testing there seems to be about 1 second delay between the message being send from service A, to it being received in service B, provided service B is a .net framework application. I have not observed the same behavior on .net core.

Looking at the code in this library, the transport has a timeout of 2 seconds when receiving messages, which i what i suspect .net framework always waits, worst case scenario. I suspect it's the SharedQueue that doesn't notify the callling code that a new message has been received, causing the delay.

I have not done any carefull measures, but looking at the traces emitted from Rebus.OpenTelemetry, it certainly seems to be the case. I have tested everything on the same host, including Rabbit, so it really shouldn't be a network issue.

mookid8000 commented 3 years ago

The SharedQueue implementation found in the codebase of Rebus.RabbitMq comes from an older version of RabbitMq.Client, so it's basically something that was ported forward when it was removed from the official driver NuGet package.

I can see it's using DateTime.Now in its implementation of the timeout..... I would not believe that that could cause the behavior you're experiencing, but just for kicks I've changed it to use a Stopwatch instead. I've released it as Rebus.RabbitMq 7.3.1-b3 – could you try it and see if that makes a difference?

zlepper commented 3 years ago

That seems to have fixed it!

Or maybe not... It's quite difficult to see and measure..

mookid8000 commented 3 years ago

Yeah ok 😁 I'd be happy to hear about your results once you've had a chance to observe it for a while.