Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting a weight for each item transported in a flow #1743

Open
dominiklohmann opened this issue Feb 4, 2024 · 0 comments
Open

Allow setting a weight for each item transported in a flow #1743

dominiklohmann opened this issue Feb 4, 2024 · 0 comments

Comments

@dominiklohmann
Copy link
Contributor

In the flow API's spsc_buffer<T> I can specify a capacity in terms of number of elements. In my application, I want to limit the buffer's memory usage. This can easily be implemented when all instances of T use the same amount of memory. However, as soon as instances of T vary in their memory usage, I can no longer restrict the buffer's memory usage.

The spsc_buffer is just one concrete example that I'm using to explain the problem, but I think this should have a much more general solution in CAF, as the ability to restrict a buffer's memory usage is mission-critical to many types of applications.

Instead of using the size of the internal buffers as an upper bound, I propose calculating the sum of the weights of all elements in the internal buffers, using that as an upper bound. This weight should default to 1, and have its own customization point.

Constantly recalculating the total weight may be very expensive, so the sum should likely be cached and updated whenever an element is added to or removed from the the buffer, ensuring that the weight customization point is called at most twice per element and buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant