Visitar URL original
PIP-183: Reduce unnecessary REST call in broker · Issue #16422 · apache/pulsar · GitHub
Skip to content

PIP-183: Reduce unnecessary REST call in broker #16422

Closed as not planned
Closed as not planned

Description

@AnonHxy

Motivation

The design of admin API now is such that: when handle a partitioned topic request, the broker will query the topic's partition meta, and then use the internal admin client to query all the non-partitioned topics (I.e. the suffix of the topic name is -partition-),
even if the non-partitioned topic is owned by the broker, which will cause unnecessary REST call in the broker.

we can call the methods directlly, who handle the non-partitioned topic, to reduce the unnecessary REST call.

Goal

  • Try to call the methods directlly if the non-partitioned topic is owned by the broker

Implementation

  • We need to check all the place where org.apache.pulsar.broker.PulsarService#getAdminClient is invoked in org.apache.pulsar.broker.admin.impl.PersistentTopicsBase

  • take internalGetPartitionedStats for example:

    • Original:
   for (int i = 0; i < partitionMetadata.partitions; i++) {
                try {
                    topicStatsFutureList
                            .add(pulsar().getAdminClient().topics().getStatsAsync(
                                    (topicName.getPartition(i).toString()), getPreciseBacklog, subscriptionBacklogSize,
                                    getEarliestTimeInBacklog));
                } catch (PulsarServerException e) {
                    asyncResponse.resume(new RestException(e));
                    return;
                }
            }
  • Suggest to do like this:
for (int i = 0; i < partitionMetadata.partitions; i++) {
             TopicName topicNamePartition = topicName.getPartition(i);
             topicStatsFutureList.add(
                 pulsar().getNamespaceService().isServiceUnitOwnedAsync(topicName)
                     .thenCompose(owned -> {
                         if (owned) {
                             // local call
                             return getTopicReferenceAsync(topicNamePartition)
                                 .thenCompose(topic ->
                                     topic.asyncGetStats(getPreciseBacklog, subscriptionBacklogSize,
                                         getEarliestTimeInBacklog));
                         } else {
                             // call from admin client
                             try {
                                 pulsar().getAdminClient().topics().getStatsAsync(topicNamePartition.toString()),
                                     getPreciseBacklog, subscriptionBacklogSize, getEarliestTimeInBacklog)
                             } catch (PulsarServerException e) {
                                 throw new RestException(e);
                             }
                         }
                     })
             );

Activity

  1. changed the title [-]PIP-181: Reduce unnecessary REST call between brokers[/-] [+]PIP-181: Reduce unnecessary REST call in broker[/+] on Jul 6, 2022
  2. HQebupt commented on Jul 7, 2022

    @HQebupt
    Contributor

    @AnonHxy We have a conflict in the PIP number here. Could you please change the number ?
    #16274
    #16250

  3. changed the title [-]PIP-181: Reduce unnecessary REST call in broker[/-] [+]PIP-183: Reduce unnecessary REST call in broker[/+] on Jul 7, 2022
  4. Jason918 commented on Jul 7, 2022

    @Jason918
    Contributor

    @AnonHxy changed to 183

  5. AnonHxy commented on Jul 7, 2022

    @AnonHxy
    ContributorAuthor
  6. github-actions commented on Aug 7, 2022

    @github-actions

    The issue had no activity for 30 days, mark with Stale label.

  7. merlimat commented on Oct 24, 2026

    @merlimat
    Contributor

    Thanks @AnonHxy for the proposal. PIP-183 was discussed on dev@ (https://lists.apache.org/thread/4p8wh57c8tlx7gn95z30nyvf9d3dg56v) but never went to a vote. Part of the idea landed as regular improvements: #16916 (partitioned stats) and #16946 (replicated subscription status) call the topic directly when the broker owns the partition. Since there has been no activity on the broader change since 2022, I'm closing this as not planned. Anyone is welcome to restart it as a pip/ document following pip/README.md, or to send further improvements of this kind as regular PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions