-
Notifications
You must be signed in to change notification settings - Fork 502
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ISSUE #68]Use multithreading for topic data collection in collectTask (
#69) * [ISSUE #68]Use multithreading for topic data collection in collectTask * modify ut * Optimize exception log printing Co-authored-by: zhangjidi <[email protected]>
- Loading branch information
1 parent
d2da9ca
commit 653332d
Showing
8 changed files
with
271 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/main/java/org/apache/rocketmq/dashboard/config/CollectExecutorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.rocketmq.dashboard.config; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.LinkedBlockingDeque; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@ConfigurationProperties(prefix = "threadpool.config") | ||
@Data | ||
public class CollectExecutorConfig { | ||
private int coreSize = 20; | ||
private int maxSize = 20; | ||
private long keepAliveTime = 3000L; | ||
private int queueSize = 1000; | ||
|
||
@Bean(name = "collectExecutor") | ||
public ExecutorService collectExecutor(CollectExecutorConfig collectExecutorConfig) { | ||
ExecutorService collectExecutor = new ThreadPoolExecutor( | ||
collectExecutorConfig.getCoreSize(), | ||
collectExecutorConfig.getMaxSize(), | ||
collectExecutorConfig.getKeepAliveTime(), | ||
TimeUnit.MILLISECONDS, | ||
new LinkedBlockingDeque<>(collectExecutorConfig.getQueueSize()), | ||
new ThreadFactory() { | ||
private final AtomicLong threadIndex = new AtomicLong(0); | ||
|
||
@Override | ||
public Thread newThread(Runnable r) { | ||
return new Thread(r, "collectTopicThread_" + this.threadIndex.incrementAndGet()); | ||
} | ||
}, | ||
new ThreadPoolExecutor.DiscardOldestPolicy() | ||
); | ||
return collectExecutor; | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
src/main/java/org/apache/rocketmq/dashboard/task/CollectTaskRunnble.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.rocketmq.dashboard.task; | ||
|
||
import com.google.common.base.Throwables; | ||
import com.google.common.collect.Lists; | ||
import java.math.BigDecimal; | ||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.apache.rocketmq.common.MixAll; | ||
import org.apache.rocketmq.common.protocol.body.BrokerStatsData; | ||
import org.apache.rocketmq.common.protocol.body.GroupList; | ||
import org.apache.rocketmq.common.protocol.route.BrokerData; | ||
import org.apache.rocketmq.common.protocol.route.TopicRouteData; | ||
import org.apache.rocketmq.dashboard.service.DashboardCollectService; | ||
import org.apache.rocketmq.store.stats.BrokerStatsManager; | ||
import org.apache.rocketmq.tools.admin.MQAdminExt; | ||
import org.apache.rocketmq.tools.command.stats.StatsAllSubCommand; | ||
|
||
@Slf4j | ||
public class CollectTaskRunnble implements Runnable { | ||
|
||
private String topic; | ||
|
||
private MQAdminExt mqAdminExt; | ||
|
||
private DashboardCollectService dashboardCollectService; | ||
|
||
public CollectTaskRunnble(String topic, MQAdminExt mqAdminExt, | ||
DashboardCollectService dashboardCollectService) { | ||
this.topic = topic; | ||
this.mqAdminExt = mqAdminExt; | ||
this.dashboardCollectService = dashboardCollectService; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
Date date = new Date(); | ||
try { | ||
TopicRouteData topicRouteData = mqAdminExt.examineTopicRouteInfo(topic); | ||
GroupList groupList = mqAdminExt.queryTopicConsumeByWho(topic); | ||
double inTPS = 0; | ||
long inMsgCntToday = 0; | ||
double outTPS = 0; | ||
long outMsgCntToday = 0; | ||
for (BrokerData bd : topicRouteData.getBrokerDatas()) { | ||
String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID); | ||
if (masterAddr != null) { | ||
try { | ||
BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.TOPIC_PUT_NUMS, topic); | ||
inTPS += bsd.getStatsMinute().getTps(); | ||
inMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd); | ||
} catch (Exception e) { | ||
log.warn("Exception caught: mqAdminExt get broker stats data TOPIC_PUT_NUMS failed", e.getMessage()); | ||
} | ||
} | ||
} | ||
if (groupList != null && !groupList.getGroupList().isEmpty()) { | ||
for (String group : groupList.getGroupList()) { | ||
for (BrokerData bd : topicRouteData.getBrokerDatas()) { | ||
String masterAddr = bd.getBrokerAddrs().get(MixAll.MASTER_ID); | ||
if (masterAddr != null) { | ||
try { | ||
String statsKey = String.format("%s@%s", topic, group); | ||
BrokerStatsData bsd = mqAdminExt.viewBrokerStatsData(masterAddr, BrokerStatsManager.GROUP_GET_NUMS, statsKey); | ||
outTPS += bsd.getStatsMinute().getTps(); | ||
outMsgCntToday += StatsAllSubCommand.compute24HourSum(bsd); | ||
} catch (Exception e) { | ||
log.warn("Exception caught: mqAdminExt get broker stats data GROUP_GET_NUMS failed", e.getMessage()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
List<String> list; | ||
try { | ||
list = dashboardCollectService.getTopicMap().get(topic); | ||
} catch (ExecutionException e) { | ||
throw Throwables.propagate(e); | ||
} | ||
if (null == list) { | ||
list = Lists.newArrayList(); | ||
} | ||
|
||
list.add(date.getTime() + "," + new BigDecimal(inTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + inMsgCntToday + "," + new BigDecimal(outTPS).setScale(5, BigDecimal.ROUND_HALF_UP) + "," + outMsgCntToday); | ||
dashboardCollectService.getTopicMap().put(topic, list); | ||
} catch (Exception e) { | ||
log.error("Failed to collect topic: {} data", topic, e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.