You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "Demogorgon314 (via GitHub)" <gi...@apache.org> on 2023/02/10 10:37:04 UTC
[GitHub] [pulsar] Demogorgon314 commented on a diff in pull request #19471: [improve][broker] PIP-192 Added broker and top-bundles load reporters
Demogorgon314 commented on code in PR #19471:
URL: https://github.com/apache/pulsar/pull/19471#discussion_r1102192880
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/reporter/BrokerLoadDataReporter.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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://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.pulsar.broker.loadbalance.extensions.reporter;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.loadbalance.BrokerHostUsage;
+import org.apache.pulsar.broker.loadbalance.extensions.data.BrokerLoadData;
+import org.apache.pulsar.broker.loadbalance.extensions.store.LoadDataStore;
+import org.apache.pulsar.broker.loadbalance.impl.GenericBrokerHostUsageImpl;
+import org.apache.pulsar.broker.loadbalance.impl.LinuxBrokerHostUsageImpl;
+import org.apache.pulsar.broker.loadbalance.impl.LoadManagerShared;
+import org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage;
+
+/**
+ * The broker load data reporter.
+ */
+@Slf4j
+public class BrokerLoadDataReporter implements LoadDataReporter<BrokerLoadData> {
+
+ private final PulsarService pulsar;
+
+ private final ServiceConfiguration conf;
+
+ private final LoadDataStore<BrokerLoadData> brokerLoadDataStore;
+
+ private final BrokerHostUsage brokerHostUsage;
+
+ private final String lookupServiceAddress;
+
+ @Getter
+ private final BrokerLoadData localData;
+
+ private final BrokerLoadData lastData;
+
+ public BrokerLoadDataReporter(PulsarService pulsar,
+ String lookupServiceAddress,
+ LoadDataStore<BrokerLoadData> brokerLoadDataStore) {
+ this.brokerLoadDataStore = brokerLoadDataStore;
+ this.lookupServiceAddress = lookupServiceAddress;
+ this.pulsar = pulsar;
+ this.conf = this.pulsar.getConfiguration();
+ if (SystemUtils.IS_OS_LINUX) {
+ brokerHostUsage = new LinuxBrokerHostUsageImpl(pulsar);
+ } else {
+ brokerHostUsage = new GenericBrokerHostUsageImpl(pulsar);
+ }
+ this.localData = new BrokerLoadData();
+ this.lastData = new BrokerLoadData();
+
+ }
+
+ @Override
+ public BrokerLoadData generateLoadData() {
+ final SystemResourceUsage systemResourceUsage = LoadManagerShared.getSystemResourceUsage(brokerHostUsage);
+ final var pulsarStats = pulsar.getBrokerService().getPulsarStats();
+ synchronized (pulsarStats) {
+ var brokerStats = pulsarStats.getBrokerStats();
+ localData.update(systemResourceUsage,
+ brokerStats.msgThroughputIn,
+ brokerStats.msgThroughputOut,
+ brokerStats.msgRateIn,
+ brokerStats.msgRateOut,
+ brokerStats.bundleCount,
+ pulsar.getConfiguration());
+
+ }
+ return this.localData;
+ }
+
+ @Override
+ public CompletableFuture<Void> reportAsync(boolean force) {
+ BrokerLoadData newLoadData = this.generateLoadData();
+ if (needBrokerDataUpdate() || force) {
+ log.info("publishing load report:{}", localData.toString(conf));
+ CompletableFuture<Void> future =
+ this.brokerLoadDataStore.pushAsync(this.lookupServiceAddress, newLoadData);
+ future.whenComplete((__, ex) -> {
+ if (ex == null) {
+ localData.setReportedAt(System.currentTimeMillis());
+ lastData.update(localData);
+ } else {
+ log.error("Failed to report the broker load data.", ex);
+ }
+ return;
Review Comment:
```suggestion
```
##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/extensions/reporter/BrokerLoadDataReporter.java:
##########
@@ -0,0 +1,156 @@
+/*
+ * 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://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.pulsar.broker.loadbalance.extensions.reporter;
+
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import lombok.Getter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.SystemUtils;
+import org.apache.pulsar.broker.PulsarService;
+import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.loadbalance.BrokerHostUsage;
+import org.apache.pulsar.broker.loadbalance.extensions.data.BrokerLoadData;
+import org.apache.pulsar.broker.loadbalance.extensions.store.LoadDataStore;
+import org.apache.pulsar.broker.loadbalance.impl.GenericBrokerHostUsageImpl;
+import org.apache.pulsar.broker.loadbalance.impl.LinuxBrokerHostUsageImpl;
+import org.apache.pulsar.broker.loadbalance.impl.LoadManagerShared;
+import org.apache.pulsar.policies.data.loadbalancer.SystemResourceUsage;
+
+/**
+ * The broker load data reporter.
+ */
+@Slf4j
+public class BrokerLoadDataReporter implements LoadDataReporter<BrokerLoadData> {
+
+ private final PulsarService pulsar;
+
+ private final ServiceConfiguration conf;
+
+ private final LoadDataStore<BrokerLoadData> brokerLoadDataStore;
+
+ private final BrokerHostUsage brokerHostUsage;
+
+ private final String lookupServiceAddress;
+
+ @Getter
+ private final BrokerLoadData localData;
+
+ private final BrokerLoadData lastData;
+
+ public BrokerLoadDataReporter(PulsarService pulsar,
+ String lookupServiceAddress,
+ LoadDataStore<BrokerLoadData> brokerLoadDataStore) {
+ this.brokerLoadDataStore = brokerLoadDataStore;
+ this.lookupServiceAddress = lookupServiceAddress;
+ this.pulsar = pulsar;
+ this.conf = this.pulsar.getConfiguration();
+ if (SystemUtils.IS_OS_LINUX) {
+ brokerHostUsage = new LinuxBrokerHostUsageImpl(pulsar);
+ } else {
+ brokerHostUsage = new GenericBrokerHostUsageImpl(pulsar);
+ }
+ this.localData = new BrokerLoadData();
+ this.lastData = new BrokerLoadData();
+
+ }
+
+ @Override
+ public BrokerLoadData generateLoadData() {
+ final SystemResourceUsage systemResourceUsage = LoadManagerShared.getSystemResourceUsage(brokerHostUsage);
+ final var pulsarStats = pulsar.getBrokerService().getPulsarStats();
+ synchronized (pulsarStats) {
+ var brokerStats = pulsarStats.getBrokerStats();
+ localData.update(systemResourceUsage,
+ brokerStats.msgThroughputIn,
+ brokerStats.msgThroughputOut,
+ brokerStats.msgRateIn,
+ brokerStats.msgRateOut,
+ brokerStats.bundleCount,
+ pulsar.getConfiguration());
+
+ }
+ return this.localData;
+ }
+
+ @Override
+ public CompletableFuture<Void> reportAsync(boolean force) {
+ BrokerLoadData newLoadData = this.generateLoadData();
+ if (needBrokerDataUpdate() || force) {
Review Comment:
```suggestion
if (force || needBrokerDataUpdate()) {
```
If `force` is true, we don't need to call the `needBrokerDataUpdate` method.
--
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: commits-unsubscribe@pulsar.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org