tju-yxq opened a new issue, #1599:
URL: https://github.com/apache/rocketmq-dashboard/issues/1599

   ## Bug Report
   
   ### Before Creating the Bug Report
   
   - [x] I found a bug, not just asking a question, which should be created in 
[GitHub Discussions](https://github.com/apache/rocketmq/discussions).
   - [x] I have searched the [GitHub 
Issues](https://github.com/apache/rocketmq/issues) and [GitHub 
Discussions](https://github.com/apache/rocketmq/discussions) of this repository 
and believe that this is not a duplicate.
   - [x] I have confirmed that this bug belongs to the current repository, not 
other repositories of RocketMQ.
   
   ### Runtime platform environment
   
   OS: Ubuntu 20.04 / Any OS running RocketMQ Studio
   
   ### RocketMQ version
   
   branch: rocketmq-studio
   Git commit id: bce4b10
   
   ### JDK Version
   
   OpenJDK 21
   
   ### Describe the Bug
   
   `TencentInstanceProvider.countTopics()` calls `listTopics(instanceId, null, 
null, false).size()` to count topics. This fetches **all topics** via the 
Tencent Cloud OpenAPI (up to `MAX_PAGES` * `PAGE_SIZE` = 100 * 100 = 10,000 
topics), builds a `List<TopicVO>` for each, then returns `.size()`.
   
   ```java
   public int countTopics(String instanceId) {
       return listTopics(instanceId, null, null, false).size();
   }
   ```
   
   `countTopics` is called by `InstanceService.fillCounts()` during 
`listInstances()`, which runs for **every** Tencent instance. This means 
listing instances triggers a full topic scan for each Tencent instance, 
potentially making hundreds of API calls just to display topic counts on the 
instance list page.
   
   ### Impact
   
   - **Extremely slow instance list page** when Tencent instances have many 
topics (each topic page = 1 API call with network latency)
   - **Wasted API quota** — Tencent Cloud APIs have rate limits; fetching 
10,000 topics just to count them is wasteful
   - **Memory waste** — builds thousands of `TopicVO` objects just to discard 
them after counting
   
   ### Steps to Reproduce
   
   1. Configure a Tencent Cloud RocketMQ instance with 500+ topics.
   2. Open the Studio instance list page.
   3. Observe: the page takes a very long time to load because `countTopics` 
fetches all 500+ topics via 5+ API calls.
   
   ### What Did You Expect to See?
   
   `countTopics` should use a lightweight approach — either a dedicated count 
API, or fetch only 1 page and use the response's total count field if 
available, instead of iterating through all pages.
   
   ### What Did You See Instead?
   
   All topics are fetched and built into objects just to return a count.
   
   ### Additional Context
   
   **Affected file**: 
`server/src/main/java/org/apache/rocketmq/studio/provider/tencent/TencentInstanceProvider.java`,
 method `countTopics()` at line ~75.
   
   **Fix approach**:
   
   Fetch only the first page (limit=1) and use the total count from the 
response. If the Tencent API doesn't return a total count, fetch the first page 
with the normal page size and calculate: `total = (fullPages * PAGE_SIZE) + 
lastPageItems`, or simply use a single page with a large limit.
   
   ```java
   public int countTopics(String instanceId) {
       Context context = resolve(instanceId);
       DescribeTopicListRequest request = new DescribeTopicListRequest();
       request.setInstanceId(context.cloudInstanceId());
       request.setOffset(0L);
       request.setLimit(1L);  // Only need 1 item to get the total count
       DescribeTopicListResponse response = 
clientFactory.call(context.credentialId(), context.regionId(),
               client -> client.DescribeTopicList(request));
       if (response == null || response.getData() == null || 
response.getData().length == 0) {
           return 0;
       }
       // Use total count from response if available, otherwise fall back to 
full scan
       return response.getTotalCount() != null ? 
response.getTotalCount().intValue() : 
              listTopics(instanceId, null, null, false).size();
   }
   ```
   
   This reduces the API calls from potentially 100+ to just 1 per instance.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to