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

[controller][server] TopicManager refactoring and performance improvements #743

Merged
merged 8 commits into from
Feb 15, 2024

Conversation

sushantmane
Copy link
Contributor

@sushantmane sushantmane commented Nov 9, 2023

TopicManager Refactoring and Performance Improvements

Currently, we have three components that work together to fetch topic metadata,
such as endOffset and the timestamp of the last produced message. These
components are TopicManager, PartitionOffsetFetcher, and
CachedPubSubMetadataGetter. We create one TopicManager instance per broker
address/region, which is shared by all the components in the system.
PartitionOffsetFetcher is a part of the topic manager. There is one instance of
CachedPubSubMetadataGetter per StoreIngestionTask, which makes use of
TopicManager and PartitionOffsetFetcher to retrieve topic metadata.

PartitionOffsetFetcher uses pubsub admin and consumer clients to fetch offsets on
behalf of components like CachedPubSubMetadataGetter and other components. Each
PartitionOffsetFetcher has just one instance of a consumer, which is protected
with a consumer mutex since consumers are not thread-safe. This means that
PartitionOffsetFetcher can handle only one request at a time. The consumer mutex
is coarse-grained, which means it holds the lock even when making calls with the
admin client, which is unnecessary since admin clients are thread-safe.

Also, when the mutex is held for topics that do not exist or have metadata fetching
issues, we perform retries while holding the mutex. This results in the mutex being
held for a relatively longer time when there is an issue with one topic, directly
causing delays for other requests waiting for the lock. We have often observed high
contention on this mutex, leading to several issues.

The CachedPubSubMetadataGetter fetches offsets asynchronously using
TopicManager/PartitionOffsetFetcher, and caches them in a local cache. These
asynchronous requests are initiated when an entry is either not in the cache or
when it is stale. Currently, these asynchronous requests are served by the ForkJoin
common thread pool.

When there is an issue like a non-existent topic, we see high contention on the
consumer mutex, as discussed earlier. This results in ForkJoin threads being
blocked on the consumer lock for longer periods. When all the ForkJoin common
thread pools get blocked, other components in the system that rely on them are
starved, which affects their functionality.

To enhance the resiliency of TopicManager in the face of failures, this PR
introduces the following high-level changes:

  1. Admin operations during metadata fetch are now performed without holding any lock.
    This prevents bad topics from acquiring the consumer in the first place and reduces
    the chances of contention when getting the consumer.

  2. A configurable fetcher consumer pool is introduced for each topic manager. This
    allows us to process requests with other consumers even if one is busy.

  3. We have discontinued the use of the ForkJoin common thread pool for submitting
    async fetch offset requests. Instead, dedicated fetcher thread pools are used for this purpose.

Miscellaneous

  • This commit introduced the following configs:
    1. pubsub.topic.manager.metadata.fetcher.consumer.pool.size - A config to specify number of PubSub consumer clients to use per topic manager (default: 2)
    2. pubsub.topic.manager.metadata.fetcher.thread.pool.size - Controls the size of per TM thread-pool used for get offset async requests (default: 2).
  • The TopicManagerRepository.SSLPropertiesSupplier has been extracted into PubSubPropertiesSupplier.
  • The CachedPubSubMetadataGetter and PartitionOffsetFetcher have been merged to form TopicManagerMetadataFetcher.
  • The method getOffsetLagFor in AggKafkaConsumerService has been renamed to getConsumerLagBasedOnMetrics.
  • The method getPartitionOffsetLag in ActiveActiveStoreIngestionTask has been renamed to getPartitionOffsetLagBasedOnMetrics.
  • TopicManagerContext has been created/extracted from TopicManagerRepository.builder() to pass the required dependencies for TopicManagerRepository.

How was this PR tested?

CI, frankenwar testing

Does this PR introduce any user-facing changes?

  • No. You can skip the rest of this section.
  • Yes. Make sure to explain your proposed changes and call out the behavior change.

@sushantmane sushantmane force-pushed the li-pusub-TopicManager branch 4 times, most recently from 51c47fb to a839615 Compare January 11, 2024 22:06
Copy link
Contributor

@FelixGV FelixGV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments, all minor... looks great so far. I still have about half to review.

Copy link
Contributor

@lluwm lluwm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work and it makes a lot of sense to me to have a centralized place/class to coordinate the work of getting offset. Thank you @sushantmane!

Copy link
Contributor

@FelixGV FelixGV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finished first pass... a few more comments. Nothing dramatic, LG overall.

@sushantmane sushantmane force-pushed the li-pusub-TopicManager branch 5 times, most recently from c1bf1a5 to 9c02126 Compare February 12, 2024 22:37
Copy link
Contributor

@FelixGV FelixGV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment... probably good to go very soon! Thanks for continuing to iterate on this big change!

Copy link
Contributor

@gaojieliu gaojieliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall, and left some minor comments.

Copy link
Contributor

@FelixGV FelixGV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Sushant! Let's take this monster PR across the finish line 🚀🚢 !!!!!

@sushantmane
Copy link
Contributor Author

Thanks a lot @FelixGV, @lluwm, and @gaojieliu for the review, discussions, and help in improving this PR. 🙏 🚀

@sushantmane sushantmane enabled auto-merge (squash) February 15, 2024 02:59
@sushantmane sushantmane merged commit 13580a3 into linkedin:main Feb 15, 2024
32 checks passed
@sushantmane sushantmane deleted the li-pusub-TopicManager branch February 15, 2024 03:27
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

Successfully merging this pull request may close these issues.

4 participants