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

Add metrics to SingleThreadedChunker #740

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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 @@ -16,6 +16,10 @@

package io.reactivex.mantis.network.push;

import io.mantisrx.common.metrics.Counter;
import io.mantisrx.common.metrics.Metrics;
import io.mantisrx.common.metrics.MetricsRegistry;
import io.mantisrx.common.metrics.spectator.MetricGroupId;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
Expand All @@ -33,6 +37,11 @@ public class SingleThreadedChunker<T> implements Callable<Void> {
int iteration = 0;
private int index = 0;

private final Counter numEventsDrained;
private final Counter drainTriggeredByTimer;
private final Counter drainTriggeredByBatch;


public SingleThreadedChunker(ChunkProcessor<T> processor, MonitoredQueue<T> iQ, int chunkSize, long maxChunkInterval, ConnectionManager<T> connMgr) {
this.inputQueue = iQ;
this.chunkSize = chunkSize;
Expand All @@ -41,6 +50,17 @@ public SingleThreadedChunker(ChunkProcessor<T> processor, MonitoredQueue<T> iQ,
this.connectionManager = connMgr;
chunk = new Object[this.chunkSize];

MetricGroupId metricsGroup = new MetricGroupId("SingleThreadedChunker");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add an index from ctor to help identify between threads.

Metrics metrics = new Metrics.Builder()
.id(metricsGroup)
.addCounter("numEventsDrained")
.addCounter("drainTriggeredByTimer")
.addCounter("drainTriggeredByBatch")
.build();
numEventsDrained = metrics.getCounter("numEventsDrained");
drainTriggeredByTimer = metrics.getCounter("drainTriggeredByTimer");
drainTriggeredByBatch = metrics.getCounter("drainTriggeredByBatch");
MetricsRegistry.getInstance().registerAndGet(metrics);
}

private boolean stopCondition() {
Expand All @@ -58,6 +78,7 @@ public Void call() throws Exception {

long currTime = System.currentTimeMillis();
if (currTime - maxChunkInterval > chunkStartTime) {
drainTriggeredByTimer.increment();
drain();
}
iteration = 0;
Expand All @@ -73,6 +94,7 @@ public Void call() throws Exception {
chunk[index++] = ele;
}
} else {
drainTriggeredByBatch.increment();
drain();
chunkStartTime = System.currentTimeMillis();
if (stopCondition()) {
Expand All @@ -93,6 +115,7 @@ private void drain() {
}

processor.process(connectionManager, copy);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if the "copy" list can be converted to be an immutable list.

numEventsDrained.increment(copy.size());
index = 0;
}
}
Expand Down
Loading