JMSPublishFilter: improve memory footprint and impose a limit #142
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
The JMSPublishFilter can allocate an unbounded amount of memory (especially String objects), this can lead to OutOfMemory errors.
Changes:
This is a refactor that reduces the amount of memory retained to handle the queue of messages in the JMSPublishFilter.
Previously the queue contained MessageMetadata, with all the properties as Strings, now we keep only 1 Netty ByteBuf, and the parsing of the Metadata is done on the processing thread, 1 message at a time per subscription.
Therefore there is a limit on the amount of memory retained for the queue, when the limit is reached the producers start to be throttled.
pulsar_jmsfilter_processing_memory
: bytes used for MessageMetadata waiting for processingpulsar_jmsfilter_processing_pending_operations
: number of pending operationsjmsFiltersOnPublishMaxMemoryMB
, this is the maximum amount of memory to retain for the operations in the queue, this is heap memory