actor-framework / actor-framework/actor-framework
Allow setting a weight for each item transported in a flow
- Dominant language
- C++
- Stars
- 3.4k
- Forks
- 572
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 3
Description
In the flow API's `spsc_buffer` 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.
Contributor guide
Assessment
This issue has not been assessed yet.