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

[improve] : Optimize queues to obtain data and prevent cpu idling #2466

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void startCalculate() {
calculate(metricsData);
}
} catch (InterruptedException ignored) {

Thread.currentThread().interrupt();
} catch (Exception e) {
log.error("calculate alarm error: {}.", e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.hertzbeat.common.entity.alerter.Alert;
import org.apache.hertzbeat.common.entity.message.CollectRep;
Expand Down Expand Up @@ -67,22 +66,22 @@ public void sendAlertsData(Alert alert) {

@Override
public Alert pollAlertsData() throws InterruptedException {
return alertDataQueue.poll(2, TimeUnit.SECONDS);
return alertDataQueue.take();
}

@Override
public CollectRep.MetricsData pollMetricsDataToAlerter() throws InterruptedException {
return metricsDataToAlertQueue.poll(2, TimeUnit.SECONDS);
return metricsDataToAlertQueue.take();
}

@Override
public CollectRep.MetricsData pollMetricsDataToPersistentStorage() throws InterruptedException {
return metricsDataToPersistentStorageQueue.poll(2, TimeUnit.SECONDS);
return metricsDataToPersistentStorageQueue.take();
}

@Override
public CollectRep.MetricsData pollMetricsDataToRealTimeStorage() throws InterruptedException {
return metricsDataToRealTimeStorageQueue.poll(2, TimeUnit.SECONDS);
return metricsDataToRealTimeStorageQueue.take();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public void run() {
}
} catch (IgnoreException ignored) {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
Yanshuming1 marked this conversation as resolved.
Show resolved Hide resolved
log.error(e.getMessage());
} catch (Exception exception) {
log.error(exception.getMessage(), exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ private void startRealTimeDataStorage() {
continue;
}
realTimeDataWriter.saveData(metricsData);
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand All @@ -78,8 +80,9 @@ protected void startPersistentDataStorage() {
if (metricsData == null) {
continue;
}

historyDataWriter.ifPresent(dataWriter -> dataWriter.saveData(metricsData));
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
Expand Down
Loading