azure-sdk-for-net icon indicating copy to clipboard operation
azure-sdk-for-net copied to clipboard

[ServiceBus] Buffer receive bodies

Open danielmarbach opened this issue 3 years ago • 4 comments
trafficstars

Builds on top of #31214

This brings back an approach discussed in https://github.com/Azure/azure-sdk-for-net/pull/20320 but with a twist to address the scenario that it is possible to hold on to ServiceBusReceivedMessage for longer than the lifetime of the processor callbacks. This is a hack to demonstrate the idea. Like discussed previously this could also be an opt-in feature exposed over the options.

This should also address the fact that Annotated Messages are mutable and the body can be exchanged. Once the body is replaced, it will get GCed and then the buffer is released by the finalizer.

Not immediately returning buffers should not be an issue according to the ArrayPool documentation. Alternatively, it would also be possible to expose an array pool over the options so that a different one can be used for the received messages.

Failure to return a rented buffer is not a fatal error. However, it may lead to decreased application performance, as the pool may need to create a new buffer to replace the lost one.

https://learn.microsoft.com/en-us/dotnet/api/system.buffers.arraypool-1.rent?view=net-6.0#System_Buffers_ArrayPool_1_Rent_System_Int32_

Let's discuss and shoot it down ;)

Contributing to the Azure SDK

Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.

For specific information about pull request etiquette and best practices, see this section.

danielmarbach avatar Sep 18 '22 16:09 danielmarbach

Thank you for your contribution @danielmarbach! We will review the pull request and get back to you soon.

ghost avatar Sep 18 '22 16:09 ghost

If only we had a way that we could observe a value in the weak table going out of scope and use that to deterministically tell the key to return the buffer.

jsquire avatar Sep 19 '22 17:09 jsquire

@jsquire it would only work by manually managing things via WeakReference and then having a cleanup thread periodically going through the tracked weak references, freeing the buffers of the ones that are no longer alive. So, essentially rebuilding parts of ConditionalWeakTable and finalizer of GC with manual infrastructure.

danielmarbach avatar Sep 19 '22 17:09 danielmarbach

Hi @danielmarbach. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.

ghost avatar Dec 30 '22 10:12 ghost

Closing this with a sad face :crying_cat_face: based on this comment

danielmarbach avatar Jan 05 '23 20:01 danielmarbach