Skip to content

Commit

Permalink
Change the policy of the queue(DataCarrier) L1 in the metric aggregat…
Browse files Browse the repository at this point in the history
…e worker to IF_POSSIBLE mode (#11554)
  • Loading branch information
wu-sheng authored Nov 16, 2023
1 parent 798c55c commit 257684a
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 88 deletions.
3 changes: 3 additions & 0 deletions docs/en/changes/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
* Fix `limit` doesn't work for `findEndpoint` API in ES storage.
* Isolate MAL CounterWindow cache by metric name.
* Fix JDBC Log query order.
* Change the DataCarrier IF_POSSIBLE strategy to use ArrayBlockingQueue implementation.
* Change the policy of the queue(DataCarrier) in the L1 metric aggregate worker to IF_POSSIBLE mode.
* Add self-observability metric `metrics_aggregator_abandon` to count the number of abandon metrics.

#### UI

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.skywalking.oap.server.core.analysis.metrics.Metrics;
import org.apache.skywalking.oap.server.core.worker.AbstractWorker;
import org.apache.skywalking.oap.server.library.datacarrier.DataCarrier;
import org.apache.skywalking.oap.server.library.datacarrier.buffer.BufferStrategy;
import org.apache.skywalking.oap.server.library.datacarrier.consumer.BulkConsumePool;
import org.apache.skywalking.oap.server.library.datacarrier.consumer.ConsumerPoolFactory;
import org.apache.skywalking.oap.server.library.datacarrier.consumer.IConsumer;
Expand All @@ -46,6 +47,7 @@ public class MetricsAggregateWorker extends AbstractWorker<Metrics> {
private AbstractWorker<Metrics> nextWorker;
private final DataCarrier<Metrics> dataCarrier;
private final MergableBufferedData<Metrics> mergeDataCache;
private CounterMetrics abandonCounter;
private CounterMetrics aggregationCounter;
private long lastSendTime = 0;

Expand All @@ -68,7 +70,7 @@ public class MetricsAggregateWorker extends AbstractWorker<Metrics> {
queueBufferSize = 1_000;
}
this.dataCarrier = new DataCarrier<>(
"MetricsAggregateWorker." + modelName, name, queueChannelSize, queueBufferSize);
"MetricsAggregateWorker." + modelName, name, queueChannelSize, queueBufferSize, BufferStrategy.IF_POSSIBLE);

BulkConsumePool.Creator creator = new BulkConsumePool.Creator(
name, BulkConsumePool.Creator.recommendMaxSize() * 2, 20);
Expand All @@ -82,6 +84,11 @@ public class MetricsAggregateWorker extends AbstractWorker<Metrics> {
MetricsCreator metricsCreator = moduleDefineHolder.find(TelemetryModule.NAME)
.provider()
.getService(MetricsCreator.class);
abandonCounter = metricsCreator.createCounter(
"metrics_aggregator_abandon", "The abandon number of rows received in aggregation",
new MetricsTag.Keys("metricName", "level", "dimensionality"),
new MetricsTag.Values(modelName, "1", "minute")
);
aggregationCounter = metricsCreator.createCounter(
"metrics_aggregation", "The number of rows in aggregation",
new MetricsTag.Keys("metricName", "level", "dimensionality"),
Expand All @@ -95,7 +102,9 @@ public class MetricsAggregateWorker extends AbstractWorker<Metrics> {
*/
@Override
public final void in(Metrics metrics) {
dataCarrier.produce(metrics);
if (!dataCarrier.produce(metrics)) {
abandonCounter.inc();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ public class ArrayBlockingQueueBuffer<T> implements QueueBuffer<T> {

@Override
public boolean save(T data) {
//only BufferStrategy.BLOCKING
try {
if (BufferStrategy.IF_POSSIBLE.equals(strategy)) {
return queue.offer(data);
}
queue.put(data);
} catch (InterruptedException e) {
// Ignore the error
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ public Channels(int channelSize, int bufferSize, IDataPartitioner<T> partitioner
this.strategy = strategy;
bufferChannels = new QueueBuffer[channelSize];
for (int i = 0; i < channelSize; i++) {
if (BufferStrategy.BLOCKING.equals(strategy)) {
bufferChannels[i] = new ArrayBlockingQueueBuffer<>(bufferSize, strategy);
} else {
bufferChannels[i] = new Buffer<>(bufferSize, strategy);
}
bufferChannels[i] = new ArrayBlockingQueueBuffer<>(bufferSize, strategy);
}
// noinspection PointlessArithmeticExpression
size = 1L * channelSize * bufferSize; // it's not pointless, it prevents numeric overflow before assigning an integer to a long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.util.ArrayList;
import java.util.List;
import org.apache.skywalking.oap.server.library.datacarrier.buffer.Buffer;
import org.apache.skywalking.oap.server.library.datacarrier.buffer.QueueBuffer;

public class ConsumerThread<T> extends Thread {
Expand Down Expand Up @@ -88,9 +87,6 @@ void shutdown() {
running = false;
}

/**
* DataSource is a refer to {@link Buffer}.
*/
class DataSource {
private QueueBuffer<T> sourceBuffer;

Expand Down

0 comments on commit 257684a

Please sign in to comment.