Farfetch / kafkaflow

Apache Kafka .NET Framework to create applications simple to use and extend.
https://farfetch.github.io/kafkaflow/
MIT License
653 stars 118 forks source link

[Feature Request]: Integrate RecyclableMemoryStream for Improved Memory Management and Performance #542

Open esskar opened 8 months ago

esskar commented 8 months ago

Is your request related to a problem you have?

No response

Describe the solution you'd like

The current implementation of KafkaFlow heavily relies on MemoryStream for processing messages. While MemoryStream is versatile and straightforward to use, it poses significant challenges in high-throughput environments, such as increased memory usage and garbage collection (GC) pressure. This feature request proposes the integration of RecyclableMemoryStream as a solution to mitigate these issues, enhancing the performance and efficiency of KafkaFlow applications.

Feature Motivation and Context

KafkaFlow is designed to handle large volumes of messages efficiently. However, the extensive use of MemoryStream for in-memory data storage does not optimally support scenarios with frequent memory allocations and deallocations, common in high-volume messaging. This can lead to:

RecyclableMemoryStream offers a pool of reusable memory segments, significantly reducing the need for new memory allocations and minimizing GC overhead. Integrating RecyclableMemoryStream into KafkaFlow could provide a more efficient way to manage memory, leading to lower memory consumption and improved application performance.

Expected Benefits

Potential Challenges

Are you able to help bring it to life and contribute with a Pull Request?

Yes

Additional context

https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream