Calculating the Size of an Apache Geode GatewaySender Queue

Barry Oglesby
4 min readJan 19, 2021

Introduction

The in-memory size of an Apache Geode GatewaySender queue can be used to determine the amount of queue memory to allocate for that GatewaySender. The ObjectGraphSizer can be used to calculate the size of any object in bytes and also to create a histogram of the object being sized. It does this by recursively traversing each field of the object. An ObjectFilter can be used in conjunction with the ObjectGraphSizer to accept or reject each object as it is traversed. Its basic use is to reject objects that shouldn’t be included in the size.

This article describes how to use the ObjectGraphSizer to calculate the size of a GatewaySender queue.

Note: See this section in my article on logging GatewaySender queue events for details on the architecture of GatewaySenders.

Implementation

All source code described in this article as well as an example usage is available here.

The implementation consists of a CalculateGatewaySenderQueueEntrySizesFunction, a number of GatewaySenderQueueEntrySizers and a GatewayQueueEventRegionEntryObjectFilter.

For each input GatewaySender id, the CalculateGatewaySenderQueueEntrySizesFunction:

  • gets the GatewaySender for the input identifier
  • creates the appropriate GatewaySenderQueueEntrySizer based on the type of GatewaySender
  • invokes the GatewaySenderQueueEntrySizer calculateEntrySizes method

The supported types of GatewaySenderQueueEntrySizer are:

The GatewayQueueEventRegionEntryObjectFilter is used by ObjectGraphSizer to include or exclude specific objects from the entry size.

Serial GatewaySender

The SerialGatewaySenderQueueEntrySizer is used to size serial GatewaySender entries. It:

  • gets and sorts the replicated Regions implementing the GatewaySender queue (one per dispatcher thread)
  • streams each Region sorted by name and calculates the size of its entries sorted by key
  • adds a summary of total sizes
  • logs the results

Get Queue Regions

The getRegions method gets a sorted list of the serial GatewaySender’s Regions like:

Calculate Queue Region Sizes

The addAndReturnSizes method streams the queue Region’s entries, sorts them by long key, invokes addAndReturnSize for each and sums their sizes like:

The addAndReturnSize method calculates the size of an entry using the ObjectGraphSizer and GatewayQueueEventRegionEntryObjectFilter like:

Accept or Reject Objects

The accept method rejects objects with specific conditions like:

Example Output

The primary server’s log file will contain a message for the serial GatewaySender’s primary entries like:

Any secondary server’s log file will contain a message for the serial GatewaySender’s secondary events like:

Parallel GatewaySender

The ParallelGatewaySenderQueueEntrySizer is used to size parallel GatewaySender entries. It:

  • gets the PartitionedRegion implementing the GatewaySender’s queue
  • gets the PartitionedRegion’s local primary entries
  • streams the primary entries sorted by key and calculates its size
  • repeats the previous two steps for the local secondary entries
  • adds a summary of total sizes
  • logs the results

Get Queue Region

The PartitionedRegion implementing the parallel GatewaySender’s queue is retrieved using code like:

Get Primary Queue Entries

The set of local primary BucketRegions is retrieved from the PartitionedRegion using code like:

The getEntries method gets a list of all the primary entries by streaming the set of BucketRegions and flat-mapping their entries like:

Get Secondary Queue Entries

There isn’t an existing method to get the set of local secondary BucketRegions like the getAllLocalPrimaryBucketRegions method for primary BucketRegions. The getLocalSecondaryBucketRegions method gets the set of local secondary BucketRegions like:

The getEntries method above gets a list of all the secondary entries.

Calculate Sizes of the Queue Entries

The addAndReturnSizes method streams the list of entries, sorts them by long key, invokes addAndReturnSize for each and sums their sizes like:

The addAndReturnSize method in the serial case above is used to calculate size of an entry.

Example Output

Each server’s log file will contain a message for the parallel GatewaySender’s primary and secondary queues like:

Parallel GatewaySender Grouped By Bucket

The ParallelGatewaySenderQueueByBucketEntrySizer is used to size parallel GatewaySender entries grouped by bucket. It:

  • gets the PartitionedRegion implementing the GatewaySender’s queue
  • gets the PartitionedRegion’s local primary BucketRegions
  • streams the local primary BucketRegions sorted by id and calculates its size
  • streams each BucketRegion’s entries sorted by long key and calculates its size
  • repeats the previous three steps for the local secondary BucketRegions
  • adds a summary of total sizes
  • logs the results

Get Queue Region

The PartitionedRegion implementing the parallel GatewaySender’s queue is retrieved using code like above.

Get Primary BucketRegions

The set of local primary BucketRegions is retrieved from the PartitionedRegion using code like above.

Get Secondary BucketRegions

The set of local secondary BucketRegions is retrieved from the PartitionedRegion using the getLocalSecondaryBucketRegions method above.

Calculate Sizes of the BucketRegions

The addAndReturnSizes method streams the set of BucketRegions, sorts them by id, invokes addAndReturnSizes for each and sums their sizes like:

Calculate Size of the Entries in a BucketRegion

The addAndReturnSizes method streams a BucketRegion’s entries, sorts them by long key, invokes addAndReturnSize for each and sums their sizes like:

The addAndReturnSize method in the serial case above is used to calculate size of an entry.

Example Output

Each server’s log file will contain a message for the parallel GatewaySender’s primary and secondary queues like:

Future

A GatewaySender API that uses the ObjectGraphSizer to calculate its size in bytes would be a very useful addition to Apache Geode.

--

--