You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "jtuglu-netflix (via GitHub)" <gi...@apache.org> on 2025/03/30 05:02:14 UTC
[PR] Enhance message gap metric to include min/max/avg aggregations (druid)
jtuglu-netflix opened a new pull request, #17847:
URL: https://github.com/apache/druid/pull/17847
<!-- Thanks for trying to help us make Apache Druid be the best it can be! Please fill out as much of the following information as is possible (where relevant, and remove it when irrelevant) to help make the intention and scope of this PR clear in order to ease review. -->
<!-- Please read the doc for contribution (https://github.com/apache/druid/blob/master/CONTRIBUTING.md) before making this PR. Also, once you open a PR, please _avoid using force pushes and rebasing_ since these make it difficult for reviewers to see what you've changed in response to their reviews. See [the 'If your pull request shows conflicts with master' section](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#if-your-pull-request-shows-conflicts-with-master) for more details. -->
Fixes #XXXX.
<!-- Replace XXXX with the id of the issue fixed in this PR. Remove this section if there is no corresponding issue. Don't reference the issue in the title of this pull-request. -->
<!-- If you are a committer, follow the PR action item checklist for committers:
https://github.com/apache/druid/blob/master/dev/committer-instructions.md#pr-and-issue-action-item-checklist-for-committers. -->
### Description
<!-- Describe the goal of this PR, what problem are you fixing. If there is a corresponding issue (referenced above), it's not necessary to repeat the description here, however, you may choose to keep one summary sentence. -->
<!-- Describe your patch: what did you change in code? How did you fix the problem? -->
<!-- If there are several relatively logically separate changes in this PR, create a mini-section for each of them. For example: -->
#### Fixed the bug ...
#### Renamed the class ...
#### Added a forbidden-apis entry ...
<!--
In each section, please describe design decisions made, including:
- Choice of algorithms
- Behavioral aspects. What configuration values are acceptable? How are corner cases and error conditions handled, such as when there are insufficient resources?
- Class organization and design (how the logic is split between classes, inheritance, composition, design patterns)
- Method organization and design (how the logic is split between methods, parameters and return types)
- Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
-->
<!-- It's good to describe an alternative design (or mention an alternative name) for every design (or naming) decision point and compare the alternatives with the designs that you've implemented (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
<!-- If there was a discussion of the design of the feature implemented in this PR elsewhere (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), link to that discussion from this PR description and explain what have changed in your final design compared to your original proposal or the consensus version in the end of the discussion. If something hasn't changed since the original discussion, you can omit a detailed discussion of those aspects of the design here, perhaps apart from brief mentioning for the sake of readability of this PR description. -->
<!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
#### Release note
<!-- Give your best effort to summarize your changes in a couple of sentences aimed toward Druid users.
If your change doesn't have end user impact, you can skip this section.
For tips about how to write a good release note, see [Release notes](https://github.com/apache/druid/blob/master/CONTRIBUTING.md#release-notes).
-->
<hr>
##### Key changed/added classes in this PR
* `MyFoo`
* `OurBar`
* `TheirBaz`
<hr>
<!-- Check the items by putting "x" in the brackets for the done things. Not all of these items apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items from the checklist below are strictly necessary, but it would be very helpful if you at least self-review the PR. -->
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066791245
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -288,6 +295,15 @@ public Object startJob()
initializeExecutors();
resetNextFlush();
sinkSchemaAnnouncer.start();
+
+ if (timeExecutor != null) {
+ timeExecutor.scheduleAtFixedRate(
+ () -> currTimeMs = System.currentTimeMillis(),
+ 0,
+ 1,
+ TimeUnit.MILLISECONDS
+ );
Review Comment:
This was the simplest way to avoid the performance overhead of calling the time function in the main loop. On Linux, this adds a significant performance penalty (24ns/row/call). I indicated this in the PR description.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "samarthjain (via GitHub)" <gi...@apache.org>.
samarthjain commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067067971
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
+1 to moving to another PR. The change is unrelated to the new metrics implementation.
Also, another option would have been to just initialize the list with minCapacity with some buffer for reasons to be added in the future. So something like `new ArrayList<>(10)` .
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377644
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
Review Comment:
This doesn't make much sense. There's a free clock read in the calling function StreamAppenderator::add() that I cached already for this purpose. Not using that cached value is just additional overhead...
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377644
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
Review Comment:
This doesn't make much sense to me. There's a free clock read in the calling function StreamAppenderator::add() that I cached already for this purpose and is free/not stale to use. Not using that cached value is just additional overhead...
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2870689720
@jtuglu-netflix , is this PR ready for review now?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094610674
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Not sure I understand. This codepath does already have multi-threaded write access. See `reset()`.
1. Not only is it making the code faster, it's also making removing an incorrect, racy pattern.
2. See below benchmarks that it also provides a performance boost:
5 warmup/5 measurement on 10k calls
Old:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 22755.902 ± 80.865 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 22768.625 ± 63.275 ns/op
```
New:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 6254.388 ± 319.197 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap avgt 5 32911.301 ± 21.004 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 6252.912 ± 222.810 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "bsyk (via GitHub)" <gi...@apache.org>.
bsyk commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2023350568
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -110,6 +116,14 @@ public void reportMessageMaxTimestamp(long messageMaxTimestamp)
this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
}
+ public void reportMessageGapAggregate(long messageGap)
+ {
+ final long newNumEvents = this.numMessageGapEvents.incrementAndGet();
+ this.minMessageGap.getAndAccumulate(messageGap, Math::min);
+ this.maxMessageGap.getAndAccumulate(messageGap, Math::max);
+ this.messageGapAvg.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / newNumEvents));
Review Comment:
Should we compute and store the running average as a Double to avoid rounding losses when `newNumEvents` gets large? The metric can still be reported as a Long when accessed.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2777642757
> I am not sure I see how the new metrics add any value.
This message gap is the message gap of the most recent row emitted in the default 30s emission period. That's not ideal for getting the spread of message gaps across the emission period, understanding what the min/max message gaps were, say for late data.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2023373748
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -110,6 +116,14 @@ public void reportMessageMaxTimestamp(long messageMaxTimestamp)
this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
}
+ public void reportMessageGapAggregate(long messageGap)
+ {
+ final long newNumEvents = this.numMessageGapEvents.incrementAndGet();
+ this.minMessageGap.getAndAccumulate(messageGap, Math::min);
+ this.maxMessageGap.getAndAccumulate(messageGap, Math::max);
+ this.messageGapAvg.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / newNumEvents));
Review Comment:
Sure, although it should always be to the nearest `ms`. I mainly kept as long since that's easier to work with atomically(it's also a bit slower per call). I'd need to interpret as raw bits if I want to use float/double atomically.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2027838257
##########
extensions-contrib/rabbit-stream-indexing-service/src/main/java/org/apache/druid/indexing/rabbitstream/RabbitStreamIndexTaskTuningConfig.java:
##########
@@ -233,35 +237,36 @@
getRecordBufferSizeConfigured(),
getRecordBufferOfferTimeout(),
getMaxRecordsPerPollConfigured(),
- getMaxColumnsToMerge()
- );
+ getMaxColumnsToMerge(),
+ getMessageGapStatsEnabled()
+ );
}
@Override
public String toString()
{
return "RabbitStreamIndexTaskTuningConfig{" +
- "maxRowsInMemory=" + getMaxRowsInMemory() +
- ", maxRowsPerSegment=" + getMaxRowsPerSegment() +
- ", maxTotalRows=" + getMaxTotalRows() +
- ", maxBytesInMemory=" + getMaxBytesInMemory() +
- ", skipBytesInMemoryOverheadCheck=" + isSkipBytesInMemoryOverheadCheck() +
- ", intermediatePersistPeriod=" + getIntermediatePersistPeriod() +
- ", maxPendingPersists=" + getMaxPendingPersists() +
- ", indexSpec=" + getIndexSpec() +
- ", indexSpecForIntermediatePersists=" + getIndexSpecForIntermediatePersists() +
- ", reportParseExceptions=" + isReportParseExceptions() +
- ", handoffConditionTimeout=" + getHandoffConditionTimeout() +
- ", resetOffsetAutomatically=" + isResetOffsetAutomatically() +
- ", segmentWriteOutMediumFactory=" + getSegmentWriteOutMediumFactory() +
- ", intermediateHandoffPeriod=" + getIntermediateHandoffPeriod() +
- ", logParseExceptions=" + isLogParseExceptions() +
- ", maxParseExceptions=" + getMaxParseExceptions() +
- ", maxSavedParseExceptions=" + getMaxSavedParseExceptions() +
- ", numPersistThreads=" + getNumPersistThreads() +
- ", maxRecordsPerPole=" + getMaxRecordsPerPollConfigured() +
- ", maxColumnsToMerge=" + getMaxColumnsToMerge() +
- '}';
+ "maxRowsInMemory=" + getMaxRowsInMemory() +
+ ", maxRowsPerSegment=" + getMaxRowsPerSegment() +
+ ", maxTotalRows=" + getMaxTotalRows() +
+ ", maxBytesInMemory=" + getMaxBytesInMemory() +
+ ", skipBytesInMemoryOverheadCheck=" + isSkipBytesInMemoryOverheadCheck() +
+ ", intermediatePersistPeriod=" + getIntermediatePersistPeriod() +
+ ", maxPendingPersists=" + getMaxPendingPersists() +
Review Comment:
## Deprecated method or constructor invocation
Invoking [SeekableStreamIndexTaskTuningConfig.getMaxPendingPersists](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8796)
##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
public void testSnapshotBeforeProcessing()
{
SegmentGenerationMetrics snapshot = metrics.snapshot();
- Assert.assertEquals(0L, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// invalid value
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
@Test
public void testSnapshotAfterProcessingOver()
{
- metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+ metrics.reportMessageGapAggregates(20L);
+ metrics.reportMessageMaxTimestamp(20L);
metrics.reportMaxSegmentHandoffTime(7L);
SegmentGenerationMetrics snapshot = metrics.snapshot();
+
Assert.assertTrue(snapshot.messageGap() >= 20L);
+ Assert.assertEquals(20L, snapshot.minMessageGap());
+ Assert.assertEquals(20L, snapshot.maxMessageGap());
+ Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+ Assert.assertEquals(20L, snapshot.avgMessageGap());
Assert.assertEquals(7, snapshot.maxSegmentHandoffTime());
}
@Test
public void testProcessingOverAfterSnapshot()
{
metrics.reportMessageMaxTimestamp(10);
+ metrics.reportMessageGapAggregates(1);
metrics.reportMaxSegmentHandoffTime(7L);
// Should reset to invalid value
metrics.snapshot();
metrics.markProcessingDone();
SegmentGenerationMetrics snapshot = metrics.snapshot();
- // Message gap must be invalid after processing is done
- Assert.assertTrue(0 > snapshot.messageGap());
+
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// value must be invalid
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
+
+ @Test
+ public void testMessageGapAggregateMetrics()
+ {
+ for (int i = 0; i < 5; ++i) {
+ metrics.reportMessageGapAggregates(i * 30);
+ }
+ metrics.reportMessageMaxTimestamp(10L);
+ metrics.reportMaxSegmentHandoffTime(7L);
+ metrics.markProcessingDone();
+ SegmentGenerationMetrics snapshot = metrics.snapshot();
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+
+ Assert.assertEquals(5, snapshot.numMessageGapEvent());
+ Assert.assertEquals(0, snapshot.minMessageGap());
+ Assert.assertEquals(120, snapshot.maxMessageGap());
+ Assert.assertEquals(60, snapshot.avgMessageGap());
+
+ Assert.assertEquals(7L, snapshot.maxSegmentHandoffTime());
+ }
+
+ private static void assertMetricsReset(final SegmentGenerationMetrics metrics)
+ {
+ Assert.assertEquals(0, metrics.numMessageGapEvent());
+ Assert.assertEquals(0, metrics.maxMessageGap());
+ Assert.assertEquals(Long.MAX_VALUE, metrics.minMessageGap());
+ Assert.assertEquals(0, metrics.avgMessageGap());
Review Comment:
## Deprecated method or constructor invocation
Invoking [Assert.assertEquals](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8799)
##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
public void testSnapshotBeforeProcessing()
{
SegmentGenerationMetrics snapshot = metrics.snapshot();
- Assert.assertEquals(0L, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// invalid value
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
@Test
public void testSnapshotAfterProcessingOver()
{
- metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+ metrics.reportMessageGapAggregates(20L);
+ metrics.reportMessageMaxTimestamp(20L);
metrics.reportMaxSegmentHandoffTime(7L);
SegmentGenerationMetrics snapshot = metrics.snapshot();
+
Assert.assertTrue(snapshot.messageGap() >= 20L);
+ Assert.assertEquals(20L, snapshot.minMessageGap());
+ Assert.assertEquals(20L, snapshot.maxMessageGap());
+ Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+ Assert.assertEquals(20L, snapshot.avgMessageGap());
Assert.assertEquals(7, snapshot.maxSegmentHandoffTime());
}
@Test
public void testProcessingOverAfterSnapshot()
{
metrics.reportMessageMaxTimestamp(10);
+ metrics.reportMessageGapAggregates(1);
metrics.reportMaxSegmentHandoffTime(7L);
// Should reset to invalid value
metrics.snapshot();
metrics.markProcessingDone();
SegmentGenerationMetrics snapshot = metrics.snapshot();
- // Message gap must be invalid after processing is done
- Assert.assertTrue(0 > snapshot.messageGap());
+
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// value must be invalid
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
+
+ @Test
+ public void testMessageGapAggregateMetrics()
+ {
+ for (int i = 0; i < 5; ++i) {
+ metrics.reportMessageGapAggregates(i * 30);
+ }
+ metrics.reportMessageMaxTimestamp(10L);
+ metrics.reportMaxSegmentHandoffTime(7L);
+ metrics.markProcessingDone();
+ SegmentGenerationMetrics snapshot = metrics.snapshot();
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+
+ Assert.assertEquals(5, snapshot.numMessageGapEvent());
+ Assert.assertEquals(0, snapshot.minMessageGap());
+ Assert.assertEquals(120, snapshot.maxMessageGap());
+ Assert.assertEquals(60, snapshot.avgMessageGap());
Review Comment:
## Deprecated method or constructor invocation
Invoking [Assert.assertEquals](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8798)
##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
public void testSnapshotBeforeProcessing()
{
SegmentGenerationMetrics snapshot = metrics.snapshot();
- Assert.assertEquals(0L, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// invalid value
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
@Test
public void testSnapshotAfterProcessingOver()
{
- metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+ metrics.reportMessageGapAggregates(20L);
+ metrics.reportMessageMaxTimestamp(20L);
metrics.reportMaxSegmentHandoffTime(7L);
SegmentGenerationMetrics snapshot = metrics.snapshot();
+
Assert.assertTrue(snapshot.messageGap() >= 20L);
+ Assert.assertEquals(20L, snapshot.minMessageGap());
+ Assert.assertEquals(20L, snapshot.maxMessageGap());
+ Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+ Assert.assertEquals(20L, snapshot.avgMessageGap());
Review Comment:
## Deprecated method or constructor invocation
Invoking [Assert.assertEquals](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8797)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066782035
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,6 +123,14 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ final long numEvent = this.numMessageGap.incrementAndGet();
+ this.avgMessageGap.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / numEvent));
Review Comment:
> Just keep a AtomicDouble totalMessageGap (to avoid the overflow problem)
Afaik, this doesn't avoid the overflow problem. You can still have Double overflow (will just wrap to infinity).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094768978
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
> Hmm, I don't think we should worry about multi-threaded access until we actually need to handle it.
@jtuglu-netflix , sorry for the confusion. This was a general response to your comment on
> guarding against future multi-threaded access patterns to this class
Thanks for sharing the clarification!
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2889497416
Thanks for your patience on this PR, @jtuglu-netflix !
Please update the PR description with the current set of the changes in the patch
so that it doesn't cause confusion to future readers.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094417935
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Hmm, I don't think we should worry about multi-threaded access until we actually need to handle it.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen in the cold reporting thread while the add() is using protected writes on the same object in the hot Appenderator thread. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy of the original object to be made during snapshot, instead of passing a reference along. It's a small race condition which I'm fine with keeping if makes things simpler.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094768978
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
> Hmm, I don't think we should worry about multi-threaded access until we actually need to handle it.
@jtuglu-netflix , sorry for the confusion. This was a general response to your comment on
> guarding against future multi-threaded access patterns to this class
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094400109
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I'll remove for now and add a javadoc, we can revisit later.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "samarthjain (via GitHub)" <gi...@apache.org>.
samarthjain commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067099214
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
If there is a single writer and potentially multiple readers, then these fields can be made volatile as well.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2023373748
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -110,6 +116,14 @@ public void reportMessageMaxTimestamp(long messageMaxTimestamp)
this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
}
+ public void reportMessageGapAggregate(long messageGap)
+ {
+ final long newNumEvents = this.numMessageGapEvents.incrementAndGet();
+ this.minMessageGap.getAndAccumulate(messageGap, Math::min);
+ this.maxMessageGap.getAndAccumulate(messageGap, Math::max);
+ this.messageGapAvg.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / newNumEvents));
Review Comment:
Sure, although it should always be to the nearest `ms`. I mainly kept as long since that's easier to work with atomically(it's also a bit slower). I'd need to interpret as raw bits if I want to use float/double atomically.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094783233
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Yeah, since the reference only guards access to the pointer to the object itself, you don't get thread safety on operations within that object (why the only "thread-safe" pattern with AtomicReference is a new object creation every time, which is slow; slower than a plain 'ol lock in hot loop). Even with a `getAndUpdate` that would just affect the pointer to the object, not the object itself, hence why I added the `synchronize` annotations to avoid ([this](https://github.com/apache/druid/pull/17847#discussion_r2094612845)). The case I mentioned above should only happen on a single reporting call.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2888068261
> Thanks for the details, @maytasm ! Will do a final review of this PR tomorrow.
@kfaraz did you get a chance to look here? I've now removed the Appenderator benchmarks.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094382467
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
Review Comment:
Agreed
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I would like to keep these synchronized as even though they are currently accessed from a single-threaded context (AND the values do not change in the snapshot), those are 2 big assumptions that may not hold in the future. It's bad practice to not leave them unguarded, since like you said, this class could have future use elsewhere. Additionally – given the current state of the code – this adds no additional overhead to the ingest path – only the reporting path.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I would like to keep these synchronized as even though they are currently accessed from a single-threaded context (AND the values do not change in the snapshot), those are 2 big assumptions that may not hold in the future. It's bad practice to not leave them unguarded, since like you said, this class could have future use elsewhere. Additionally – given the current state of the code – this adds no additional overhead to the ingest path, only the reporting path.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I would like to keep these synchronized as even though they are currently accessed from a single-threaded context (where the values do not change in the snapshot), it's bad practice to not leave them unguarded, since like you said, this class could have future use elsewhere.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2889292955
@kfaraz all good here?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2777632104
@jtuglu-netflix , thanks for the PR.
I am not sure I see how the new metrics add any value.
The metric `ingest/events/messageGap` is already emitted with `taskId` as a dimension.
You could just look at the interval in question and find the max, avg, min values across task IDs and even for a single task ID.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "maytasm (via GitHub)" <gi...@apache.org>.
maytasm commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2779705752
@kfaraz
We want to be able to measure and ensure that our e2e streaming ingestion latency is within some x latency (for SLA). For example, we may have a use case that we need to make sure data is available within x time after it is produced to Kafka. Currently, Druid calculates ingest/events/messageGap as Time gap in milliseconds between the latest ingested event timestamp (during that emission period) and the current system timestamp of metrics emission. This results in the **minimum** gap and is not very useful. We cannot measure, track, or ensure our SLA with how the ingest/events/messageGap is currently being calculated.
Here is an example:
Emission period of 5secs between t0 to t4:
At t0, we have a message arriving with timestamp of t-500
At t1, we have a message arriving with timestamp of t-499
At t2, we have a message arriving with timestamp of t-499
At t3, we have a message arriving with timestamp of t-499
At t4, we have a message arriving with timestamp of t3
The above is an example where we process 5 rows of data. t3 is the latest ingested event timestamp in this period
When we emits the metric at t4, we would calculate message gap as t4 - t3 = 1 sec gap.
This disregards all the earlier late messages.
For example, in the above, if our SLA to our users is 5 secs, the ingest/events/messageGap reported as 1 sec gap would seems like we are within SLA but in fact 80% of our messages are more than 500seconds late!
We want to improve it by:
- Calculate the messageGap for each message individually
- i.e. At t0, we have a message arriving with timestamp of t-500. This should be record as a 500sec messageGap
- Report either a distribution (not sure if this is possible with Druid metric system) or a min/max/avg of the messageGaps we saw in an emission period (min/max/avg would still be useful)
- The above, we saw the messageGap of 500seconds, 500seconds, 501seconds, 502seconds, 1 second. We should report min of 1s, max of 502s, avg 400.8s
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066999877
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
If you do write your own class, you can also skip using an `AtomicReference` and just add a `synchronized update` method on the class and a `synchronized reset` method.
I hope it would perform better compared to an `AtomicReference` of pair.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066985508
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
Hmm, odd, I would have thought the pair would be faster.
Do you still have the snippet for the pair code?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2082579807
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -52,9 +47,49 @@ public class SegmentGenerationMetrics
private final AtomicLong messageMaxTimestamp = new AtomicLong(0);
private final AtomicLong messageGap = new AtomicLong(0);
private final AtomicBoolean processingDone = new AtomicBoolean(false);
-
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
+ }
+
+ public long getMinMessageGap()
+ {
+ return minMessageGap;
+ }
+
+ public long getMaxMessageGap()
+ {
+ return maxMessageGap;
+ }
+
+ public long getNumMessageGap()
+ {
+ return numMessageGap;
+ }
+
+ public MessageGapStats copyOf()
+ {
+ final MessageGapStats copy = new MessageGapStats();
+ copy.minMessageGap = minMessageGap;
+ copy.maxMessageGap = maxMessageGap;
+ copy.numMessageGap = numMessageGap;
+ copy.totalMessageGap = totalMessageGap;
+ return copy;
+ }
+ }
+
+ private final MessageGapStats messageGapStats = new MessageGapStats();
+ private final ReentrantLock lock = new ReentrantLock();
Review Comment:
> Calls that access messageGapStats can be locked by using the internal object lock itself.
Yeah, I tried this and `synchronized` was a lot slower compared to just using regular lock wrapper around the class. This approach was the cheapest out of all locking ones that I did.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2051631739
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,6 +123,14 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ final long numEvent = this.numMessageGap.incrementAndGet();
+ this.avgMessageGap.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / numEvent));
Review Comment:
> Won't it be more efficient to just keep a running sum? Then only calculate the avg using numEvent when we get the average
In short, given the emission period is variable, we could overflow on the sum. I figured the simplest solution was taking the performance penalty of floating pt division. Other offline alternatives seemed a bit more complicated like sampling/caching the gap values in a ring buffer and moving the avg calculation to emission-time, etc.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2789628001
Thanks for the details, @maytasm ! I will try to take a look at this soon.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378587
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -337,6 +337,9 @@ public AppenderatorAddResult add(
throw e;
}
+ final long currTs = System.currentTimeMillis();
+ metrics.reportMessageGap(currTs - row.getTimestampFromEpoch());
Review Comment:
I'd argue against this if we care about performance. This function already does a clock read in a hot-loop. Doing another call just slows down the function even more.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377644
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
Review Comment:
This doesn't make much sense to me. There's a free clock read in the calling function StreamAppenderator::add() that I cached already for this purpose and is free/not stale to use. Not using that cached value is just additional overhead...See the above comment
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094826737
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Aah, I see what you mean. Thanks for the explanation, @jtuglu-netflix !
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
I have been under the impression that the object will not need to be accessed by multiple threads,
but since that is clearly not the case, let's fix it up.
Your first approach probably made most sense as there is no point using both
`AtomicReference` and `synchronized` methods.
Please create a follow up PR as you see fit.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094783233
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Yeah, since the reference only guards access to the pointer to the object itself, you don't get thread safety on operations within that object (why the only "thread-safe" pattern with AtomicReference is a new object creation every time, which is slow). Even with a `getAndUpdate` that would just affect the pointer to the object, not the object itself, hence why I added the `synchronize` annotations to avoid ([this](https://github.com/apache/druid/pull/17847#discussion_r2094612845)). The case I mentioned above should only happen on a single reporting call.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen in the cold reporting thread while the add() is using protected writes on the same object in the hot Appenderator thread. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy of the original object to be made during snapshot, instead of passing a reference along. I'm fine with this approach if you think it makes things simpler.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067129281
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
Yeah. In c++ std::array is guaranteed stack allocation whereas the resizable equivalent is heap-based (slower). I guess in Java this distinction isn't as stark since you can't actually control where the memory is allocated. The difference showed up in the profile, but:
> The downside of using arrays is that future maintainers will have to resize the array when they want to add reasons.
We can leave for now due to this^
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
Yeah. In c++ std::array is guaranteed stack allocation whereas the resizable equivalent vector is heap-based (slower). I guess in Java this distinction isn't as stark since you can't actually control where the memory is allocated. The difference showed up in the profile, but:
> The downside of using arrays is that future maintainers will have to resize the array when they want to add reasons.
We can leave for now due to this^
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066822234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
> If we keep two separate atomic fields, the snapshotting can potentially be inconsistent due to race conditions.
Actually, from my understanding, this should never happen. There is a single writer to these fields(a task is single threaded, and has 1 row appenderator), and potentially multiple readers (at the moment it's a single reader). The reader threads simply look at the latter of these atomic fields. The "worst" case is the avg computation will be 1-step behind.
That being said, I did try your suggestion before and it was a bit slower, so I opted for this approach:
pair:
```
Benchmark (enableMessageGapMetrics) Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime true avgt 2 1.688 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime false avgt 2 1.701 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap true avgt 2 11.681 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap false avgt 2 11.836 ns/op
```
two atomics:
```
Benchmark (enableMessageGapMetrics) Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime true avgt 2 1.690 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime false avgt 2 1.687 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap true avgt 2 8.816 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap false avgt 2 8.824 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066782035
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,6 +123,14 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ final long numEvent = this.numMessageGap.incrementAndGet();
+ this.avgMessageGap.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / numEvent));
Review Comment:
> Just keep a AtomicDouble totalMessageGap (to avoid the overflow problem)
Afaik, this doesn't avoid the overflow problem. You can still have Double overflow (will just wrap to infinity).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067087420
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
> So something like new ArrayList<>(10) .
Yeah. Default ArrayList allocation is already 10, but even doing `new ArrayList<>(4);` was slower. I think there's some additional overhead under-the-hood (a bit like std::array vs std::vector in c++).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378018
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
This is a faster pattern than doing a blind get/set. This value isn't monotonically increasing, hence you avoid the cache exclusive MESI ownership change in the case where it isn't larger than the previously recorded value. Same reasoning for the other similar change.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094381121
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
It's also guarding against future multi-threaded access patterns to this class, where the current code would have a race.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094356094
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
Review Comment:
```suggestion
private long min = Long.MAX_VALUE;
private long max = Long.MIN_VALUE;
private long count = 0;
double total = 0;
```
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
+ }
+
+ public synchronized long getMinMessageGap()
+ {
+ return minMessageGap;
+ }
+
+ public synchronized long getMaxMessageGap()
+ {
+ return maxMessageGap;
+ }
+
+ public synchronized long getNumMessageGap()
+ {
+ return numMessageGap;
+ }
+
+ public synchronized void add(final long messageGap)
+ {
+ totalMessageGap += messageGap;
+ ++numMessageGap;
+ if (minMessageGap > messageGap) {
+ minMessageGap = messageGap;
+ }
+ if (maxMessageGap < messageGap) {
+ maxMessageGap = messageGap;
+ }
+ }
+
+ public MessageGapStats getAndReset()
+ {
+ final MessageGapStats copy = new MessageGapStats();
+ synchronized (this) {
+ copy.totalMessageGap = totalMessageGap;
+ copy.numMessageGap = numMessageGap;
+ copy.minMessageGap = minMessageGap;
+ copy.maxMessageGap = maxMessageGap;
+
+ totalMessageGap = 0;
+ numMessageGap = 0;
+ minMessageGap = Long.MAX_VALUE;
+ maxMessageGap = Long.MIN_VALUE;
+ }
+ return copy;
+ }
+ }
+
+ private final MessageGapStats messageGapStats = new MessageGapStats();
Review Comment:
```suggestion
private final AtomicReference<MessageGapStats> messageGapStats = new AtomicReference<>(new MessageGapStats());
```
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
```suggestion
public double avg()
```
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -337,6 +337,9 @@ public AppenderatorAddResult add(
throw e;
}
+ final long currTs = System.currentTimeMillis();
+ metrics.reportMessageGap(currTs - row.getTimestampFromEpoch());
Review Comment:
We should just send the message timestamp here. `SegmentGenerationMetrics` can decide what to do with it, same way we currently do for the max message timestamp.
```suggestion
metrics.reportMessageTimestamp(row.getTimestampFromEpoch());
```
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
Review Comment:
```suggestion
return total / count;
```
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
+ }
+
+ public synchronized long getMinMessageGap()
+ {
+ return minMessageGap;
+ }
+
+ public synchronized long getMaxMessageGap()
+ {
+ return maxMessageGap;
+ }
+
+ public synchronized long getNumMessageGap()
+ {
+ return numMessageGap;
+ }
+
+ public synchronized void add(final long messageGap)
+ {
+ totalMessageGap += messageGap;
+ ++numMessageGap;
+ if (minMessageGap > messageGap) {
+ minMessageGap = messageGap;
+ }
+ if (maxMessageGap < messageGap) {
+ maxMessageGap = messageGap;
+ }
+ }
+
+ public MessageGapStats getAndReset()
Review Comment:
This method should not be needed, use an `AtomicReference` in `SegmentGenerationMetrics` instead.
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/stats/TaskRealtimeMetricsMonitor.java:
##########
@@ -132,6 +132,21 @@ public boolean doMonitor(ServiceEmitter emitter)
emitter.emit(builder.setMetric("ingest/events/messageGap", messageGap));
}
+ final SegmentGenerationMetrics.MessageGapStats messageGapStats = metrics.getMessageGapStats();
+ final long minMessageGap = messageGapStats.getMinMessageGap();
+ final long maxMessageGap = messageGapStats.getMaxMessageGap();
+ final double avgMessageGap = messageGapStats.avgMessageGap();
+ // Best-effort way to ensure parity amongst emitted metrics
+ if (minMessageGap != Long.MAX_VALUE) {
+ emitter.emit(builder.setMetric("ingest/events/minMessageGap", minMessageGap));
+ }
+ if (maxMessageGap != Long.MIN_VALUE) {
+ emitter.emit(builder.setMetric("ingest/events/maxMessageGap", maxMessageGap));
+ }
+ if (!Double.isNaN(avgMessageGap)) {
+ emitter.emit(builder.setMetric("ingest/events/avgMessageGap", avgMessageGap));
+ }
Review Comment:
```suggestion
if (messageGap.count() > 0) {
emitter.emit(builder.setMetric("ingest/events/minMessageGap", messageGap.min()));
emitter.emit(builder.setMetric("ingest/events/maxMessageGap", messageGap.max()));
emitter.emit(builder.setMetric("ingest/events/avgMessageGap", messageGap.avg()));
}
```
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
+ }
+
+ public synchronized long getMinMessageGap()
Review Comment:
Why do these methods need to be synchronized?
Also, use method names `min`, `max`, `avg`, `count` instead for simplicity.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
Review Comment:
```suggestion
public void reportMessageTimestamp(final long messageTimestamp)
{
messageGapStats.get().add(System.currentTimeMillis() - messageTimestamp);
}
```
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Why is this change needed?
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
Review Comment:
Note: I feel this class can have other applications too, but for now we can just leave it here.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -220,20 +294,26 @@ public SegmentGenerationMetrics snapshot()
retVal.persistCpuTime.set(persistCpuTime.get());
retVal.handOffCount.set(handOffCount.get());
retVal.sinkCount.set(sinkCount.get());
- retVal.messageMaxTimestamp.set(messageMaxTimestamp.get());
retVal.maxSegmentHandoffTime.set(maxSegmentHandoffTime.get());
retVal.mergedRows.set(mergedRows.get());
retVal.pushedRows.set(pushedRows.get());
long messageGapSnapshot = 0;
- final long maxTimestamp = retVal.messageMaxTimestamp.get();
+ final long maxTimestamp = messageMaxTimestamp.get();
+ retVal.messageMaxTimestamp.set(maxTimestamp);
if (processingDone.get()) {
messageGapSnapshot = NO_EMIT_MESSAGE_GAP;
} else if (maxTimestamp > 0) {
messageGapSnapshot = System.currentTimeMillis() - maxTimestamp;
}
retVal.messageGap.set(messageGapSnapshot);
+ final MessageGapStats gapStatsCopy = messageGapStats.getAndReset();
+ retVal.messageGapStats.totalMessageGap = gapStatsCopy.totalMessageGap;
+ retVal.messageGapStats.numMessageGap = gapStatsCopy.numMessageGap;
+ retVal.messageGapStats.maxMessageGap = gapStatsCopy.maxMessageGap;
+ retVal.messageGapStats.minMessageGap = gapStatsCopy.minMessageGap;
Review Comment:
```suggestion
retVal.messageGapStats.set(messageGapStats.getAndSet(new MessageGapStats()));
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen in the cold reporting thread while the add() is using protected writes on the same object in the hot Appenderator thread. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy of the original object to be made during snapshot, instead of passing a reference along. Atomic reference isn't thread-safety if you're not using new values every time the atomic pointer is updated.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094783233
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Yeah, since the reference only guards access to the pointer to the object itself, you don't get mutual exclusion assurances on operations within that object (why the only "thread-safe" pattern for writes with AtomicReference is a new object creation every time, which is slow; slower than a plain 'ol lock in hot loop). Even with a `getAndUpdate` that would just affect the pointer to the object, not the object itself, hence why I added the `synchronize` annotations to avoid ([this](https://github.com/apache/druid/pull/17847#discussion_r2094612845)). The case I mentioned above should only happen on a single reporting call.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "bsyk (via GitHub)" <gi...@apache.org>.
bsyk commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2023304322
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -53,6 +53,12 @@ public class SegmentGenerationMetrics
private final AtomicLong messageGap = new AtomicLong(0);
private final AtomicBoolean processingDone = new AtomicBoolean(false);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(0);
+ private final AtomicLong messageGapAvg = new AtomicLong(0); // millisecond-level precision
Review Comment:
Should this be `avgMessageGap` to align with the others?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2027756849
##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
public void testSnapshotBeforeProcessing()
{
SegmentGenerationMetrics snapshot = metrics.snapshot();
- Assert.assertEquals(0L, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// invalid value
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
@Test
public void testSnapshotAfterProcessingOver()
{
- metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+ metrics.reportMessageGapAggregates(20L);
+ metrics.reportMessageMaxTimestamp(20L);
metrics.reportMaxSegmentHandoffTime(7L);
SegmentGenerationMetrics snapshot = metrics.snapshot();
+
Assert.assertTrue(snapshot.messageGap() >= 20L);
+ Assert.assertEquals(20L, snapshot.minMessageGap());
+ Assert.assertEquals(20L, snapshot.maxMessageGap());
+ Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+ Assert.assertEquals(20L, snapshot.messageGapAvg());
Assert.assertEquals(7, snapshot.maxSegmentHandoffTime());
}
@Test
public void testProcessingOverAfterSnapshot()
{
metrics.reportMessageMaxTimestamp(10);
+ metrics.reportMessageGapAggregates(1);
metrics.reportMaxSegmentHandoffTime(7L);
// Should reset to invalid value
metrics.snapshot();
metrics.markProcessingDone();
SegmentGenerationMetrics snapshot = metrics.snapshot();
- // Message gap must be invalid after processing is done
- Assert.assertTrue(0 > snapshot.messageGap());
+
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// value must be invalid
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
+
+ @Test
+ public void testMessageGapAggregateMetrics()
+ {
+ for (int i = 0; i < 5; ++i) {
+ metrics.reportMessageGapAggregates(i * 30);
+ }
+ metrics.reportMessageMaxTimestamp(10L);
+ metrics.reportMaxSegmentHandoffTime(7L);
+ metrics.markProcessingDone();
+ SegmentGenerationMetrics snapshot = metrics.snapshot();
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+
+ Assert.assertEquals(5, snapshot.numMessageGapEvent());
+ Assert.assertEquals(0, snapshot.minMessageGap());
+ Assert.assertEquals(120, snapshot.maxMessageGap());
+ Assert.assertEquals(60, snapshot.messageGapAvg());
Review Comment:
## Deprecated method or constructor invocation
Invoking [Assert.assertEquals](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8794)
##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
public void testSnapshotBeforeProcessing()
{
SegmentGenerationMetrics snapshot = metrics.snapshot();
- Assert.assertEquals(0L, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// invalid value
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
@Test
public void testSnapshotAfterProcessingOver()
{
- metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+ metrics.reportMessageGapAggregates(20L);
+ metrics.reportMessageMaxTimestamp(20L);
metrics.reportMaxSegmentHandoffTime(7L);
SegmentGenerationMetrics snapshot = metrics.snapshot();
+
Assert.assertTrue(snapshot.messageGap() >= 20L);
+ Assert.assertEquals(20L, snapshot.minMessageGap());
+ Assert.assertEquals(20L, snapshot.maxMessageGap());
+ Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+ Assert.assertEquals(20L, snapshot.messageGapAvg());
Review Comment:
## Deprecated method or constructor invocation
Invoking [Assert.assertEquals](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8793)
##########
server/src/test/java/org/apache/druid/segment/realtime/SegmentGenerationMetricsTest.java:
##########
@@ -37,33 +37,73 @@
public void testSnapshotBeforeProcessing()
{
SegmentGenerationMetrics snapshot = metrics.snapshot();
- Assert.assertEquals(0L, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// invalid value
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
@Test
public void testSnapshotAfterProcessingOver()
{
- metrics.reportMessageMaxTimestamp(System.currentTimeMillis() - 20L);
+ metrics.reportMessageGapAggregates(20L);
+ metrics.reportMessageMaxTimestamp(20L);
metrics.reportMaxSegmentHandoffTime(7L);
SegmentGenerationMetrics snapshot = metrics.snapshot();
+
Assert.assertTrue(snapshot.messageGap() >= 20L);
+ Assert.assertEquals(20L, snapshot.minMessageGap());
+ Assert.assertEquals(20L, snapshot.maxMessageGap());
+ Assert.assertEquals(snapshot.minMessageGap(), snapshot.maxMessageGap());
+ Assert.assertEquals(20L, snapshot.messageGapAvg());
Assert.assertEquals(7, snapshot.maxSegmentHandoffTime());
}
@Test
public void testProcessingOverAfterSnapshot()
{
metrics.reportMessageMaxTimestamp(10);
+ metrics.reportMessageGapAggregates(1);
metrics.reportMaxSegmentHandoffTime(7L);
// Should reset to invalid value
metrics.snapshot();
metrics.markProcessingDone();
SegmentGenerationMetrics snapshot = metrics.snapshot();
- // Message gap must be invalid after processing is done
- Assert.assertTrue(0 > snapshot.messageGap());
+
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+ assertMetricsReset(snapshot);
+ assertMetricsReset(metrics);
// value must be invalid
Assert.assertTrue(0 > snapshot.maxSegmentHandoffTime());
}
+
+ @Test
+ public void testMessageGapAggregateMetrics()
+ {
+ for (int i = 0; i < 5; ++i) {
+ metrics.reportMessageGapAggregates(i * 30);
+ }
+ metrics.reportMessageMaxTimestamp(10L);
+ metrics.reportMaxSegmentHandoffTime(7L);
+ metrics.markProcessingDone();
+ SegmentGenerationMetrics snapshot = metrics.snapshot();
+ // Latest message gap must be invalid after processing is done
+ Assert.assertEquals(-1, snapshot.messageGap());
+
+ Assert.assertEquals(5, snapshot.numMessageGapEvent());
+ Assert.assertEquals(0, snapshot.minMessageGap());
+ Assert.assertEquals(120, snapshot.maxMessageGap());
+ Assert.assertEquals(60, snapshot.messageGapAvg());
+
+ Assert.assertEquals(7L, snapshot.maxSegmentHandoffTime());
+ }
+
+ private static void assertMetricsReset(final SegmentGenerationMetrics metrics)
+ {
+ Assert.assertEquals(0, metrics.numMessageGapEvent());
+ Assert.assertEquals(0, metrics.maxMessageGap());
+ Assert.assertEquals(Long.MAX_VALUE, metrics.minMessageGap());
+ Assert.assertEquals(0, metrics.messageGapAvg());
Review Comment:
## Deprecated method or constructor invocation
Invoking [Assert.assertEquals](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8795)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2777654968
> Is the metric tracking the avg, min, max message gap within every emission period or in the entire lifecycle of the task so far?
I think it would make sense to leave the values for the duration of the task considering the min/max/avg aggregations might make more sense trended over time. Right now I reset them every emission window.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378018
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
This is a faster pattern than doing a blind get/set. This value isn't monotonically increasing with every function call, hence you avoid the cache exclusive MESI ownership change in the (likely frequent) case where it isn't larger than the previously recorded value. Same reasoning for the other similar change.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094783233
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Yeah, since the reference only guards access to the pointer to the object itself, you don't get mutual exclusion assurances on operations within that object (why the only "thread-safe" pattern for multi-value writes with AtomicReference is a new object creation every time, which is slow; slower than a plain 'ol lock in hot loop). Even with a `getAndUpdate` that would just affect the pointer to the object, not the object itself, hence why I added the `synchronize` annotations to avoid ([this](https://github.com/apache/druid/pull/17847#discussion_r2094612845)). The case I mentioned above should only happen on a single reporting call (never multiple in succession).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094783233
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Yeah, since the reference only guards access to the pointer to the object itself, you don't get mutual exclusion assurances on operations within that object (why the only "thread-safe" pattern with AtomicReference is a new object creation every time, which is slow; slower than a plain 'ol lock in hot loop). Even with a `getAndUpdate` that would just affect the pointer to the object, not the object itself, hence why I added the `synchronize` annotations to avoid ([this](https://github.com/apache/druid/pull/17847#discussion_r2094612845)). The case I mentioned above should only happen on a single reporting call.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094418948
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Sure, but why not just keep them all thread-safe?
Because then we would always end up making all classes and methods synchronized, which doesn't add value if it is not really needed.
> Personally, it makes the code more confusing if I see an unprotected read and a protected write on the same values in the same class (e.g add() vs avg()).
Agreed. I don't see why the `add` needs to be synchronized either. Can it be accessed by multiple threads?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen in the cold reporting thread while the add() is using protected writes on the same object in the hot Appenderator thread. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy of the original object to be made during snapshot, instead of passing a reference along.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094395821
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Sure, but why not just keep them all thread-safe? It currently adds overhead to the "cold" reporting path only(which is negligible), and is less work for potential maintenance in the future. Personally it makes the code more confusing if I see an unprotected read and a protected write in the same class (e.g add vs avg()).
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Sure, but why not just keep them all thread-safe? It currently adds overhead to the "cold" reporting path only(which is negligible), and is less work for potential maintenance in the future. Personally, it makes the code more confusing if I see an unprotected read and a protected write in the same class (e.g add vs avg()).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094395821
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Sure, but why not just keep them all thread-safe? It currently adds overhead to the "cold" metric reporting loop only(which is negligible), and is less work for potential maintenance in the future. Personally, it makes the code more confusing if I see an unprotected read and a protected write on the same values in the same class (e.g add() vs avg()).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066822234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
> If we keep two separate atomic fields, the snapshotting can potentially be inconsistent due to race conditions.
Actually, from my understanding, this should never happen. There is a single writer to these fields(a task is single threaded, and has 1 row appenderator), and potentially multiple readers (at the moment it's a single reader). The reader threads simply look at the latter of these atomic fields. The "worst" case is the avg computation will be 1 row behind.
That being said, I did try your suggestion before and it was a bit slower, so I opted for this approach:
pair:
```
Benchmark (enableMessageGapMetrics) Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime true avgt 2 1.688 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime false avgt 2 1.701 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap true avgt 2 11.681 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap false avgt 2 11.836 ns/op
```
two atomics:
```
Benchmark (enableMessageGapMetrics) Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime true avgt 2 1.690 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime false avgt 2 1.687 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap true avgt 2 8.816 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap false avgt 2 8.824 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066776310
##########
benchmarks/src/test/java/org/apache/druid/benchmark/indexing/StreamAppenderatorBenchmark.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.druid.benchmark.indexing;
+
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.segment.incremental.SimpleRowIngestionMeters;
+import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
+import org.apache.druid.segment.realtime.appenderator.StreamAppenderatorTester;
+import org.apache.druid.segment.realtime.sink.Committers;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.io.IOException;
+
+@Warmup(iterations = 15)
+@Measurement(iterations = 15)
+public class StreamAppenderatorBenchmark extends AppenderatorBenchmark
Review Comment:
The new metrics added overhead to the loop. Adding the perf improvements + benchmarks remove this overhead, so I figured I'd keep them in the same PR. I'll remove.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066777962
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/stats/TaskRealtimeMetricsMonitor.java:
##########
@@ -132,6 +132,19 @@ public boolean doMonitor(ServiceEmitter emitter)
emitter.emit(builder.setMetric("ingest/events/messageGap", messageGap));
}
+ final long minMessageGap = metrics.minMessageGap();
+ final long maxMessageGap = metrics.maxMessageGap();
+ // Best-effort way to ensure parity amongst emitted metrics
+ if (metrics.isMessageGapAggStatsEnabled()) {
+ if (minMessageGap != Long.MAX_VALUE) {
+ emitter.emit(builder.setMetric("ingest/events/minMessageGap", minMessageGap));
Review Comment:
> And since these are only two new metrics reported in every metric emission period, I think we should not need to add a new config.
These new metrics add overhead to the loop, not sure if that's something people want to "opt-in" to.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2043168813
##########
extensions-contrib/rabbit-stream-indexing-service/src/main/java/org/apache/druid/indexing/rabbitstream/supervisor/RabbitStreamSupervisorTuningConfig.java:
##########
@@ -189,33 +192,34 @@
public String toString()
{
return "RabbitStreamSupervisorTuningConfig{" +
- "maxRowsInMemory=" + getMaxRowsInMemory() +
- ", maxRowsPerSegment=" + getMaxRowsPerSegment() +
- ", maxTotalRows=" + getMaxTotalRows() +
- ", maxBytesInMemory=" + getMaxBytesInMemoryOrDefault() +
- ", skipBytesInMemoryOverheadCheck=" + isSkipBytesInMemoryOverheadCheck() +
- ", intermediatePersistPeriod=" + getIntermediatePersistPeriod() +
- ", maxPendingPersists=" + getMaxPendingPersists() +
- ", indexSpec=" + getIndexSpec() +
- ", reportParseExceptions=" + isReportParseExceptions() +
- ", handoffConditionTimeout=" + getHandoffConditionTimeout() +
- ", resetOffsetAutomatically=" + isResetOffsetAutomatically() +
- ", segmentWriteOutMediumFactory=" + getSegmentWriteOutMediumFactory() +
- ", workerThreads=" + workerThreads +
- ", chatRetries=" + chatRetries +
- ", httpTimeout=" + httpTimeout +
- ", shutdownTimeout=" + shutdownTimeout +
- ", recordBufferSize=" + getRecordBufferSizeConfigured() +
- ", recordBufferOfferTimeout=" + getRecordBufferOfferTimeout() +
- ", offsetFetchPeriod=" + offsetFetchPeriod +
- ", intermediateHandoffPeriod=" + getIntermediateHandoffPeriod() +
- ", logParseExceptions=" + isLogParseExceptions() +
- ", maxParseExceptions=" + getMaxParseExceptions() +
- ", maxSavedParseExceptions=" + getMaxSavedParseExceptions() +
- ", numPersistThreads=" + getNumPersistThreads() +
- ", maxRecordsPerPoll=" + getMaxRecordsPerPollConfigured() +
- ", maxColumnsToMerge=" + getMaxColumnsToMerge() +
- '}';
+ "maxRowsInMemory=" + getMaxRowsInMemory() +
+ ", maxRowsPerSegment=" + getMaxRowsPerSegment() +
+ ", maxTotalRows=" + getMaxTotalRows() +
+ ", maxBytesInMemory=" + getMaxBytesInMemoryOrDefault() +
+ ", skipBytesInMemoryOverheadCheck=" + isSkipBytesInMemoryOverheadCheck() +
+ ", intermediatePersistPeriod=" + getIntermediatePersistPeriod() +
+ ", maxPendingPersists=" + getMaxPendingPersists() +
Review Comment:
## Deprecated method or constructor invocation
Invoking [SeekableStreamIndexTaskTuningConfig.getMaxPendingPersists](1) should be avoided because it has been deprecated.
[Show more details](https://github.com/apache/druid/security/code-scanning/8910)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067799818
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
Yeah, I considered the same, but since all the other existing fields are atomic primitives, it seemed best to stick to that pattern.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067087420
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
> So something like new ArrayList<>(10) .
Yeah. Default ArrayList allocation is already 10, but even doing `new ArrayList<>(4);` was slower. I think there's some additional overhead under-the-hood (a bit like std::array vs std::vector).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094395821
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Sure, but why not just keep them all thread-safe? It currently adds overhead to the "cold" reporting path only(which is negligible), and is less work for potential maintenance in the future. Personally, it makes the code more confusing if I see an unprotected read and a protected write on the same values in the same class (e.g add() vs avg()).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378018
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
This is a faster pattern than doing a blind get/set. This value isn't monotonically increasing, hence you avoid the cache exclusive MESI ownership change.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378587
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -337,6 +337,9 @@ public AppenderatorAddResult add(
throw e;
}
+ final long currTs = System.currentTimeMillis();
+ metrics.reportMessageGap(currTs - row.getTimestampFromEpoch());
Review Comment:
I'd argue against this if we care about performance. The calling function already does a clock read in a hot-loop. Doing another call just slows down the function even more (+24ns per call).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094380226
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
+ }
+
+ public synchronized long getMinMessageGap()
Review Comment:
See my comment above.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094610674
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Not sure I understand. This codepath does already have multi-threaded write access (for `maxSegmentHandoffTime`). See `reset()`.
1. Not only is it making the code faster in the common case, it's also making removing an incorrect, racy pattern.
2. See below benchmarks that it also provides a performance boost(3.5x+ faster):
5 warmup/5 measurement on 10k calls
Old:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 22755.902 ± 80.865 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 22768.625 ± 63.275 ns/op
```
New:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 6254.388 ± 319.197 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap avgt 5 32911.301 ± 21.004 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 6252.912 ± 222.810 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen while the add() is using protected writes on the same object. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy to be made during snapshot.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378018
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
This is a faster pattern than doing a blind get/set. This value isn't monotonically increasing with every function call, hence you avoid the cache-exclusive MESI ownership change in the (likely frequent) case where it isn't larger than the previously-recorded value. Same reasoning for the other similar change.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094400109
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I'll remove for now, we can revisit later.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094610674
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Not sure I understand. This codepath does already have multi-threaded write access (for `maxSegmentHandoffTime`). See `reset()`.
1. Not only is it making the code faster, it's also making removing an incorrect, racy pattern.
2. See below benchmarks that it also provides a performance boost:
5 warmup/5 measurement on 10k calls
Old:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 22755.902 ± 80.865 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 22768.625 ± 63.275 ns/op
```
New:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 6254.388 ± 319.197 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap avgt 5 32911.301 ± 21.004 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 6252.912 ± 222.810 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2777662031
Even without the metrics additions, this PR has some small changes in `StreamAppenderator` which shaves a good chunk of time from a single row iteration, speeding up throughput.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "maytasm (via GitHub)" <gi...@apache.org>.
maytasm commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2051609982
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,6 +123,14 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ final long numEvent = this.numMessageGap.incrementAndGet();
+ this.avgMessageGap.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / numEvent));
Review Comment:
Won't it be more efficient to just keep a running sum? Then only calculate the avg using numEvent when we get the average
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378018
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
This is a faster pattern than doing a blind get/set. This value isn't monotonically increasing, hence you avoid the cache exclusive MESI ownership change in the (likely frequent) case where it isn't larger than the previously recorded value. Same reasoning for the other similar change.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378018
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
This is a faster pattern than doing a blind get/set. This value isn't monotonically increasing, hence you avoid the cache exclusive MESI ownership change in the case where it isn't larger than the previously recorded value.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I would like to keep these synchronized as even though they are currently accessed from a single-threaded context (AND the values do not change in the snapshot), those are 2 big assumptions that may not hold in the future. It's bad practice to not leave them unguarded, since like you said, this class could have future use elsewhere.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378587
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -337,6 +337,9 @@ public AppenderatorAddResult add(
throw e;
}
+ final long currTs = System.currentTimeMillis();
+ metrics.reportMessageGap(currTs - row.getTimestampFromEpoch());
Review Comment:
I'd argue against this if we care about performance. The calling function already does a clock read in a hot-loop. Doing another call just slows down the function even more (+24ns per call). At high row/s, this added overhead shows up in benchmarks (exactly what I've been trying to avoid since the beginning).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377644
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
Review Comment:
This doesn't make much sense to me. There's a free clock read in the calling function StreamAppenderator::add() that I cached already for this purpose. Not using that cached value is just additional overhead...
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094395821
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Sure, but why not just keep them all thread-safe? It currently adds overhead to the "cold" reporting path only(which is negligible), and is less work for potential maintenance in the future.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen in the cold reporting thread while the add() is using protected writes on the same object in the hot Appenderator thread. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy of the original object to be made during snapshot, instead of passing a reference along. That being said, I'm fine with this approach if you think it makes things simpler.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz merged PR #17847:
URL: https://github.com/apache/druid/pull/17847
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094610674
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Not sure I understand. This codepath does already have multi-threaded write access (for `maxSegmentHandoffTime`). See `reset()`.
1. Not only is it making the code faster, it's also making removing an incorrect, racy pattern.
2. See below benchmarks that it also provides a performance boost(3.5x+):
5 warmup/5 measurement on 10k calls
Old:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 22755.902 ± 80.865 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 22768.625 ± 63.275 ns/op
```
New:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 6254.388 ± 319.197 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap avgt 5 32911.301 ± 21.004 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 6252.912 ± 222.810 ns/op
```
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Not sure I understand. This codepath does already have multi-threaded write access (for `maxSegmentHandoffTime`). See `reset()`.
1. Not only is it making the code faster, it's also making removing an incorrect, racy pattern.
2. See below benchmarks that it also provides a performance boost(3.5x+ faster):
5 warmup/5 measurement on 10k calls
Old:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 22755.902 ± 80.865 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 22768.625 ± 63.275 ns/op
```
New:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 6254.388 ± 319.197 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap avgt 5 32911.301 ± 21.004 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 6252.912 ± 222.810 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066980701
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/stats/TaskRealtimeMetricsMonitor.java:
##########
@@ -132,6 +132,19 @@ public boolean doMonitor(ServiceEmitter emitter)
emitter.emit(builder.setMetric("ingest/events/messageGap", messageGap));
}
+ final long minMessageGap = metrics.minMessageGap();
+ final long maxMessageGap = metrics.maxMessageGap();
+ // Best-effort way to ensure parity amongst emitted metrics
+ if (metrics.isMessageGapAggStatsEnabled()) {
+ if (minMessageGap != Long.MAX_VALUE) {
+ emitter.emit(builder.setMetric("ingest/events/minMessageGap", minMessageGap));
Review Comment:
If we use the impl suggested in [this comment](https://github.com/apache/druid/pull/17847#discussion_r2066975828), the overheap would be negligible I feel.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066978948
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
Okay, let's move it to the separate PR with the benchmarks. Then we can take a call on whether the change really adds value.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066822234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
> If we keep two separate atomic fields, the snapshotting can potentially be inconsistent due to race conditions.
Of course, but given these are metrics I figured an approximation would be fine. After benchmarking with atomic reference the performance seems to be about the same so should be fine to switch.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066766349
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
From the benchmarks, array allocation is faster, see the PR description above.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2020472501
##########
benchmarks/src/test/java/org/apache/druid/benchmark/indexing/StreamAppenderatorBenchmark.java:
##########
@@ -0,0 +1,183 @@
+/*
+ * 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.druid.benchmark.indexing;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.data.input.MapBasedInputRow;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.incremental.SimpleRowIngestionMeters;
+import org.apache.druid.segment.realtime.appenderator.Appenderator;
+import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
+import org.apache.druid.segment.realtime.appenderator.StreamAppenderatorTester;
+import org.apache.druid.segment.realtime.sink.Committers;
+import org.apache.druid.timeline.partition.LinearShardSpec;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.TimeUnit;
+
+@BenchmarkMode({Mode.AverageTime, Mode.Throughput})
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Thread)
+@Fork(value = 1, jvmArgs = {
+ "-Xms4G",
+ "-Xmx4G",
+ "--add-opens=java.base/sun.nio.ch=ALL-UNNAMED"
+})
+@Warmup(iterations = 1)
+@Measurement(iterations = 3)
+public class StreamAppenderatorBenchmark
+{
+ private static final int NUM_ROWS = 10_000;
+ private static final int BATCH_SIZE = 1_000;
+ private static final int UNIQUE_DIMS = 500;
+ private static final int NUM_SEGMENTS = 5;
+ private static final String SEGMENT_INTERVAL = "2020-01-01/2020-02-01";
+
+ private Appenderator appenderator;
+ private List<SegmentIdWithShardSpec> identifiers;
+ private File tempDir;
+
+ // Pre-generated values
+ private long[] timestamps;
+ private String[] dimensionValues;
+ private int[] metricValues;
+
+ @Setup
+ public void setup() throws IOException
+ {
+ tempDir = File.createTempFile("druid-stream-appenderator-benchmark", "tmp");
+ if (!tempDir.delete()) {
+ throw new IOException("Could not delete " + tempDir);
+ }
+ if (!tempDir.mkdir()) {
+ throw new IOException("Could not create directory " + tempDir);
+ }
Review Comment:
## Local information disclosure in a temporary directory
Local information disclosure vulnerability due to use of file readable by other local users.
[Show more details](https://github.com/apache/druid/security/code-scanning/8777)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2020518862
##########
benchmarks/src/test/java/org/apache/druid/benchmark/indexing/AppenderatorBenchmark.java:
##########
@@ -0,0 +1,136 @@
+/*
+ * 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.druid.benchmark.indexing;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.data.input.MapBasedInputRow;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.segment.realtime.appenderator.Appenderator;
+import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
+import org.apache.druid.segment.realtime.appenderator.StreamAppenderatorTester;
+import org.apache.druid.timeline.partition.LinearShardSpec;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.TearDown;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ThreadLocalRandom;
+
+public abstract class AppenderatorBenchmark
+{
+ protected static final int NUM_ROWS = 10_000;
+ protected static final int BATCH_SIZE = 1_000;
+ protected static final int UNIQUE_DIMS = 500;
+ protected static final int NUM_SEGMENTS = 5;
+ protected static final String SEGMENT_INTERVAL = "2020-01-01/2020-02-01";
+
+ protected Appenderator appenderator;
+ protected List<SegmentIdWithShardSpec> identifiers;
+ protected File tempDir;
+
+ // Pre-generated values
+ protected long[] timestamps;
+ protected String[] dimensionValues;
+ protected int[] metricValues;
+
+ @Setup
+ public void setup() throws IOException
+ {
+ tempDir = File.createTempFile("druid-appenderator-benchmark", "tmp");
Review Comment:
## Local information disclosure in a temporary directory
Local information disclosure vulnerability due to use of file readable by other local users.
[Show more details](https://github.com/apache/druid/security/code-scanning/8778)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066822234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
> If we keep two separate atomic fields, the snapshotting can potentially be inconsistent due to race conditions.
Actually, this should never happen. There is a single writer to these fields, and potentially multiple readers (at the moment it's a single reader). The reader thread simply looks at one of these atomic fields. The "worst" case is the avg computation will be 1-step behind.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066994487
##########
benchmarks/src/test/java/org/apache/druid/benchmark/indexing/StreamAppenderatorBenchmark.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.druid.benchmark.indexing;
+
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.segment.incremental.SimpleRowIngestionMeters;
+import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
+import org.apache.druid.segment.realtime.appenderator.StreamAppenderatorTester;
+import org.apache.druid.segment.realtime.sink.Committers;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.io.IOException;
+
+@Warmup(iterations = 15)
+@Measurement(iterations = 15)
+public class StreamAppenderatorBenchmark extends AppenderatorBenchmark
Review Comment:
Yeah, we can keep the `SegmentGenerationMetricsBenchmark` in this PR since it is related.
If we create a separate PR for the other benchmarks, we can review and merge that PR first.
Then we will be able to better evaluate the changes in this PR against the already added benchmarks.
It will also keep the reviews and the commit history more straightforward.
Let me know if that sounds good.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066988222
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
```
this.avgGapStats.getAndUpdate(oldValue ->
new Pair<>(oldValue.lhs + messageGap, oldValue.rhs + 1)
);
```
since pair values are final I didn't see a way of doing modification in-place. The ctor might be the overhead there.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
```java
this.avgGapStats.getAndUpdate(oldValue ->
new Pair<>(oldValue.lhs + messageGap, oldValue.rhs + 1)
);
```
since pair values are final I didn't see a way of doing modification in-place. The ctor might be the overhead there.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066988222
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
The below would be called per-row:
```java
private final AtomicReference<Pair<Double, Long>> avgGapStats = new AtomicReference<>(new Pair<>(0.0, 0L));
.....
this.avgGapStats.getAndUpdate(oldValue ->
new Pair<>(oldValue.lhs + messageGap, oldValue.rhs + 1)
);
```
since pair members are final I didn't see a way of doing modification in-place. The ctor might be the overhead there.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066980701
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/stats/TaskRealtimeMetricsMonitor.java:
##########
@@ -132,6 +132,19 @@ public boolean doMonitor(ServiceEmitter emitter)
emitter.emit(builder.setMetric("ingest/events/messageGap", messageGap));
}
+ final long minMessageGap = metrics.minMessageGap();
+ final long maxMessageGap = metrics.maxMessageGap();
+ // Best-effort way to ensure parity amongst emitted metrics
+ if (metrics.isMessageGapAggStatsEnabled()) {
+ if (minMessageGap != Long.MAX_VALUE) {
+ emitter.emit(builder.setMetric("ingest/events/minMessageGap", minMessageGap));
Review Comment:
If we use the impl suggested in [this comment](https://github.com/apache/druid/pull/17847#discussion_r2066975828), the overhead would be negligible I feel.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066997342
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
Yeah, I agree, creation of the new object could be the reason for the overhead.
You can write up your own nested class in `SegmentGenerationMetrics` and try to benchmark that if you feel up to it 😃 .
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066975828
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -288,6 +295,15 @@ public Object startJob()
initializeExecutors();
resetNextFlush();
sinkSchemaAnnouncer.start();
+
+ if (timeExecutor != null) {
+ timeExecutor.scheduleAtFixedRate(
+ () -> currTimeMs = System.currentTimeMillis(),
+ 0,
+ 1,
+ TimeUnit.MILLISECONDS
+ );
Review Comment:
There are other cleaner ways to avoid invoking the `System.currentTimeMillis()` call.
They could be somewhat less accurate but good enough for the use case here.
Just initialize the start time once when the message gap is being reset in `SegmentGenerationMetrics`.
Maintain a `Stopwatch`.
When calling `recordMessageLag`, compute message gap as follows:
```
messageGap = startTimestamp + stopwatch.millisElapsed() - rowTimestamp
```
Let me know if that would work.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094783233
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Yeah, since the reference only guards access to the pointer to the object itself, you don't get mutual exclusion assurances on operations within that object (why the only "thread-safe" pattern for multi-value writes with AtomicReference is a new object creation every time, which is slow; slower than a plain 'ol lock in hot loop). Even with a `getAndUpdate` that would just affect the pointer to the object, not the object itself, hence why I added the `synchronize` annotations to avoid ([this](https://github.com/apache/druid/pull/17847#discussion_r2094612845)). The case I mentioned above should only happen on a single reporting call.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378587
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -337,6 +337,9 @@ public AppenderatorAddResult add(
throw e;
}
+ final long currTs = System.currentTimeMillis();
+ metrics.reportMessageGap(currTs - row.getTimestampFromEpoch());
Review Comment:
I'd argue against this if we care about performance. The calling function already does a clock read in a hot-loop. Doing another call just slows down the function even more (+24ns per call). At high row/s, this added overhead shows up in benchmarks (exactly what I've been trying to avoid since the beginning). Let's keep.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377644
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
Review Comment:
This doesn't make much sense. There's a free clock read in the calling function StreamAppenderator::add(). Not using that cached value is just additional overhead
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen while the add() is using protected writes on the same object. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy to be made during snapshot. Atomic reference isn't thread-safe if you're not using new values every time the atomic pointer is updated.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen while the add() is using protected writes on the same object. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy to be made during snapshot. Atomic reference isn't thread-safe if you're not using new object every time the atomic pointer is updated.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2777651706
> @jtuglu-netflix , thanks for the PR.
>
> I am not sure I see how the new metrics add any value. The metric `ingest/events/messageGap` is already emitted with `taskId` as a dimension. You could just look at the interval in question and find the max, avg, min values across task IDs and even for a single task ID.
Adding to the above, if you have gaps of 5,4,3,2,1 in sequence (with timestamps increasing) we would only emit 1. That's not a great indicator of how big (on avg) the gap was and/or any min/max values. To get a better view of such things, one would need to significantly lower the emission period, but this has its limits.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "bsyk (via GitHub)" <gi...@apache.org>.
bsyk commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2027764412
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,13 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(0);
Review Comment:
Did you find `new LongAccumulator(Math::max, Long.MIN_VALUE)` to be slower or no different from AtomicLong here?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2082580314
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -52,9 +47,49 @@ public class SegmentGenerationMetrics
private final AtomicLong messageMaxTimestamp = new AtomicLong(0);
private final AtomicLong messageGap = new AtomicLong(0);
private final AtomicBoolean processingDone = new AtomicBoolean(false);
-
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
+ }
+
+ public long getMinMessageGap()
+ {
+ return minMessageGap;
+ }
+
+ public long getMaxMessageGap()
+ {
+ return maxMessageGap;
+ }
+
+ public long getNumMessageGap()
+ {
+ return numMessageGap;
+ }
+
+ public MessageGapStats copyOf()
+ {
+ final MessageGapStats copy = new MessageGapStats();
+ copy.minMessageGap = minMessageGap;
+ copy.maxMessageGap = maxMessageGap;
+ copy.numMessageGap = numMessageGap;
+ copy.totalMessageGap = totalMessageGap;
+ return copy;
+ }
+ }
+
+ private final MessageGapStats messageGapStats = new MessageGapStats();
+ private final ReentrantLock lock = new ReentrantLock();
Review Comment:
I'll post my updated benchmarks when I mark this ready for re-review.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +140,32 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ lock.lock();
+ try {
Review Comment:
See above
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094377234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I would like to keep these synchronized as even though they are currently accessed from a single threaded context (where the values do not change in the snapshot), it's bad practice to not leave them unguarded, since like you said, this class could have future use elsewhere.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094394766
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
That's true, but it does make the code confusing. Instead, add a javadoc to the class mentioning that it is currently not thread safe.
We will make it thread safe only when the application requires it.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378587
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -337,6 +337,9 @@ public AppenderatorAddResult add(
throw e;
}
+ final long currTs = System.currentTimeMillis();
+ metrics.reportMessageGap(currTs - row.getTimestampFromEpoch());
Review Comment:
I'd argue against this if we care about performance. This function already does a clock read in a hot-loop. Doing another call just slows down the function even more (+24ns per call).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094610674
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
Not sure I understand. This codepath does already have multi-threaded write access (for `maxSegmentHandoffTime`). See `reset()`.
1. Not only is it making the code faster in the average case, it's also making removing an incorrect, racy pattern.
2. See below benchmarks that it also provides a performance boost(3.5x+ faster):
5 warmup/5 measurement on 10k calls
Old:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 22755.902 ± 80.865 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 22768.625 ± 63.275 ns/op
```
New:
```
Benchmark Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime avgt 5 6254.388 ± 319.197 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap avgt 5 32911.301 ± 21.004 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageMaxTimestamp avgt 5 6252.912 ± 222.810 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094612845
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
> Agreed. I don't see why the add needs to be synchronized either. Can it be accessed by multiple threads?
Your atomic reference suggestions can allow a dangling reference to the "old" gap statistics value that's being modified by the add() to leak into the reporting loop's snapshot (in TaskRealtimeMetricsMonitor). This means unsafe reads can happen in the cold reporting thread while the add() is using protected writes on the same object in the hot Appenderator thread. This is why I originally didn't want to use a reference, and added a thread-safe `copyAndReset` to allow clean copy to be made during snapshot. Atomic reference isn't thread-safety if you're not using new values every time the atomic pointer is updated.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094378018
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +164,23 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ messageGapStats.add(messageGap);
+ }
+
public void reportMessageMaxTimestamp(long messageMaxTimestamp)
{
- this.messageMaxTimestamp.set(Math.max(messageMaxTimestamp, this.messageMaxTimestamp.get()));
+ if (this.messageMaxTimestamp.get() < messageMaxTimestamp) {
+ this.messageMaxTimestamp.getAndAccumulate(messageMaxTimestamp, Math::max);
+ }
}
public void reportMaxSegmentHandoffTime(long maxSegmentHandoffTime)
{
- this.maxSegmentHandoffTime.set(Math.max(maxSegmentHandoffTime, this.maxSegmentHandoffTime.get()));
+ if (this.maxSegmentHandoffTime.get() < maxSegmentHandoffTime) {
+ this.maxSegmentHandoffTime.getAndAccumulate(maxSegmentHandoffTime, Math::max);
Review Comment:
This is a faster pattern than doing a blind get/set. This value isn't monotonically increasing with every function call, hence you avoid the cache exclusive MESI ownership change in the (likely frequent) case where it isn't larger than the previously-recorded value. Same reasoning for the other similar change.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094395821
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
Sure, but why not just keep them all thread-safe? It currently adds overhead to the "cold" reporting path only(which is negligible), and is less work for potential maintenance in the future. Personally, it makes the code more confusing if I see an unprotected read and a protected write in the same class (e.g add() vs avg()).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2094779052
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +55,65 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public synchronized double avgMessageGap()
Review Comment:
I suppose we could just use some atomic method of `AtomicReference` like `getAndUpdate` to ensure that a reader doesn't get an inconsistent state of the object.
My concern was that we shouldn't need synchronized methods on an object that is already behind an `AtomicReference`. Please feel free to create a follow up PR for this.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066483481
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/IndexTask.java:
##########
@@ -819,13 +819,13 @@ private TaskStatus generateAndPublishSegments(
final PartitionAnalysis partitionAnalysis
) throws IOException, InterruptedException
{
- final SegmentGenerationMetrics buildSegmentsSegmentGenerationMetrics = new SegmentGenerationMetrics();
+ final IndexTuningConfig tuningConfig = ingestionSchema.getTuningConfig();
+ final SegmentGenerationMetrics buildSegmentsSegmentGenerationMetrics = new SegmentGenerationMetrics(tuningConfig.getMessageGapAggStatsEnabled());
Review Comment:
The message gap will only ever be emitted for streaming tasks. It should not be a part of `IndexTuningConfig` and we should always pass false to the `SegmentGenerationMetrics` here.
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -288,6 +295,15 @@ public Object startJob()
initializeExecutors();
resetNextFlush();
sinkSchemaAnnouncer.start();
+
+ if (timeExecutor != null) {
+ timeExecutor.scheduleAtFixedRate(
+ () -> currTimeMs = System.currentTimeMillis(),
+ 0,
+ 1,
+ TimeUnit.MILLISECONDS
+ );
Review Comment:
This doesn't seem like the right approach. We shouldn't need a separate executor just to update the `currTimeMs`.
##########
benchmarks/src/test/java/org/apache/druid/benchmark/indexing/StreamAppenderatorBenchmark.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * 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.druid.benchmark.indexing;
+
+import org.apache.druid.data.input.InputRow;
+import org.apache.druid.segment.incremental.SimpleRowIngestionMeters;
+import org.apache.druid.segment.realtime.appenderator.SegmentIdWithShardSpec;
+import org.apache.druid.segment.realtime.appenderator.StreamAppenderatorTester;
+import org.apache.druid.segment.realtime.sink.Committers;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.infra.Blackhole;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+import java.io.IOException;
+
+@Warmup(iterations = 15)
+@Measurement(iterations = 15)
+public class StreamAppenderatorBenchmark extends AppenderatorBenchmark
Review Comment:
@jtuglu-netflix , would you mind moving the benchmarks to a separate PR and keeping this PR solely for the new metrics?
I am assuming that the benchmarks don't have anything to do with these metrics in particular. Please correct me if I am missing something.
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/stats/TaskRealtimeMetricsMonitor.java:
##########
@@ -132,6 +132,19 @@ public boolean doMonitor(ServiceEmitter emitter)
emitter.emit(builder.setMetric("ingest/events/messageGap", messageGap));
}
+ final long minMessageGap = metrics.minMessageGap();
+ final long maxMessageGap = metrics.maxMessageGap();
+ // Best-effort way to ensure parity amongst emitted metrics
+ if (metrics.isMessageGapAggStatsEnabled()) {
+ if (minMessageGap != Long.MAX_VALUE) {
+ emitter.emit(builder.setMetric("ingest/events/minMessageGap", minMessageGap));
Review Comment:
Does the min message gap really add any value?
I don't imagine any SLAs relying on the min message gap.
I think just average and max should be enough.
And since these are only two new metrics reported in every metric emission period, I think we should not need to add a new config. It is fine to emit new metrics as long as we are not changing values of any of the existing metrics.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,6 +123,14 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ final long numEvent = this.numMessageGap.incrementAndGet();
+ this.avgMessageGap.getAndUpdate(oldAvg -> oldAvg + ((messageGap - oldAvg) / numEvent));
Review Comment:
I would agree with @maytasm on this.
Just keep a `AtomicDouble totalMessageGap` (to avoid the overflow problem)
and the total number of events.
Do not compute the average until it needs to be reported.
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -337,6 +353,12 @@ public AppenderatorAddResult add(
throw e;
}
+ // cache volatile locally so it's likely to be a register read later
+ final long systemTime = currTimeMs;
+ if (messageGapAggStats) {
+ metrics.reportMessageGap(systemTime - row.getTimestampFromEpoch());
Review Comment:
The logic of computing the actual message gap should live inside `SegmentGenerationMetrics` itself. The code here should just pass the row timestamp.
##########
indexing-service/src/main/java/org/apache/druid/indexing/common/task/IndexTask.java:
##########
@@ -1291,7 +1293,8 @@ public IndexTuningConfig(
@JsonProperty("maxSavedParseExceptions") @Nullable Integer maxSavedParseExceptions,
@JsonProperty("maxColumnsToMerge") @Nullable Integer maxColumnsToMerge,
@JsonProperty("awaitSegmentAvailabilityTimeoutMillis") @Nullable Long awaitSegmentAvailabilityTimeoutMillis,
- @JsonProperty("numPersistThreads") @Nullable Integer numPersistThreads
+ @JsonProperty("numPersistThreads") @Nullable Integer numPersistThreads,
+ @JsonProperty("messageGapAggStatsEnabled") @Nullable Boolean messageGapAggStatsEnabled
Review Comment:
`IndexTask` and `IndexTuningConfig` should not have this field as it is relevant only for streaming tasks.
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
Why does this need to be changed to an array?
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
Instead of these two, I would advise keeping an AtomicReference of a pair of total sum (double) and total number of events.
If we keep two separate atomic fields, the snapshotting can potentially be inconsistent due to race conditions.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2829263740
@maytasm , @jtuglu-netflix , thanks for the patience on this.
I will review the PR later today.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "samarthjain (via GitHub)" <gi...@apache.org>.
samarthjain commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2082568948
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -40,9 +37,7 @@ public class SegmentGenerationMetrics
private final AtomicLong persistBackPressureMillis = new AtomicLong(0);
private final AtomicLong failedPersists = new AtomicLong(0);
private final AtomicLong failedHandoffs = new AtomicLong(0);
- // Measures the number of rows that have been merged. Segments are merged into a single file before they are pushed to deep storage.
Review Comment:
nit: doesn't look related.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -23,14 +23,11 @@
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.locks.ReentrantLock;
-/**
Review Comment:
nit: doesn't look related.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -105,14 +140,32 @@ public void setSinkCount(long sinkCount)
this.sinkCount.set(sinkCount);
}
+ public void reportMessageGap(final long messageGap)
+ {
+ lock.lock();
+ try {
Review Comment:
This block of could be moved to inside MessageGapStats class.
And once you do that, I think a better approach would be to simply make MessageGapStats class thread safe i.e. add synchronized on all the methods inside the class. I would also then mark the class as @ThreadSafe.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -40,9 +37,7 @@ public class SegmentGenerationMetrics
private final AtomicLong persistBackPressureMillis = new AtomicLong(0);
private final AtomicLong failedPersists = new AtomicLong(0);
private final AtomicLong failedHandoffs = new AtomicLong(0);
- // Measures the number of rows that have been merged. Segments are merged into a single file before they are pushed to deep storage.
private final AtomicLong mergedRows = new AtomicLong(0);
- // Measures the number of rows that have been pushed to deep storage.
Review Comment:
nit: doesn't look related.
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -52,9 +47,49 @@ public class SegmentGenerationMetrics
private final AtomicLong messageMaxTimestamp = new AtomicLong(0);
private final AtomicLong messageGap = new AtomicLong(0);
private final AtomicBoolean processingDone = new AtomicBoolean(false);
-
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ public static class MessageGapStats
+ {
+ long minMessageGap = Long.MAX_VALUE;
+ long maxMessageGap = Long.MIN_VALUE;
+ long numMessageGap = 0;
+ double totalMessageGap = 0;
+
+ public double avgMessageGap()
+ {
+ return totalMessageGap / numMessageGap;
+ }
+
+ public long getMinMessageGap()
+ {
+ return minMessageGap;
+ }
+
+ public long getMaxMessageGap()
+ {
+ return maxMessageGap;
+ }
+
+ public long getNumMessageGap()
+ {
+ return numMessageGap;
+ }
+
+ public MessageGapStats copyOf()
+ {
+ final MessageGapStats copy = new MessageGapStats();
+ copy.minMessageGap = minMessageGap;
+ copy.maxMessageGap = maxMessageGap;
+ copy.numMessageGap = numMessageGap;
+ copy.totalMessageGap = totalMessageGap;
+ return copy;
+ }
+ }
+
+ private final MessageGapStats messageGapStats = new MessageGapStats();
+ private final ReentrantLock lock = new ReentrantLock();
Review Comment:
You don't need a separate lock for this.
Calls that access messageGapStats can be locked by using the internal object lock itself.
`synchronized(messageGapStats) { .... }`
and then I would add a @GuardedBy("messageGapStats") annotation.
`@GuardedBy("messageGapStats")`
`private final MessageGapStats messageGapStats = new MessageGapStats();`
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on PR #17847:
URL: https://github.com/apache/druid/pull/17847#issuecomment-2777651548
> This current message gap metric is the message gap of the most recent row emitted in the default 30s emission period. That's not ideal for getting the spread of message gaps across the emission period, i.e the average. Additionally, understanding what the min/max message gaps were, say for late data is helpful.
Is the metric tracking the avg, min, max message gap within every emission period or in the entire lifecycle of the task so far?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "samarthjain (via GitHub)" <gi...@apache.org>.
samarthjain commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2067110210
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
When you don't specify the default capacity, there are additional checks performed on the first add().
```
public ArrayList(int initialCapacity) {
if (initialCapacity > 0) {
this.elementData = new Object[initialCapacity];
} else if (initialCapacity == 0) {
this.elementData = EMPTY_ELEMENTDATA;
} else {
throw new IllegalArgumentException("Illegal Capacity: "+
initialCapacity);
}
}
public boolean add(E e) {
ensureCapacityInternal(size + 1); // Increments modCount!!
elementData[size++] = e;
return true;
}
```
Java array list uses arrays under the hood with additional checks for capacity.
The downside of using arrays is that future maintainers will have to resize the array when they want to add reasons. If they forget doing that and their tests don't exercise the path where new persist reasons are added, then things can break in production.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066766349
##########
server/src/main/java/org/apache/druid/segment/realtime/appenderator/StreamAppenderator.java:
##########
@@ -354,40 +376,43 @@ public AppenderatorAddResult add(
boolean isPersistRequired = false;
boolean persist = false;
- List<String> persistReasons = new ArrayList<>();
+ final String[] persistReasons = new String[NUMBER_OF_PERSIST_REASONS];
Review Comment:
Array allocation is faster, see the PR description above.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066822234
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
> If we keep two separate atomic fields, the snapshotting can potentially be inconsistent due to race conditions.
Actually, from my understanding, this should never happen. There is a single writer to these fields(a row appenderator per task), and potentially multiple readers (at the moment it's a single reader). The reader threads simply look at the latter of these atomic fields. The "worst" case is the avg computation will be 1-step behind.
That being said, I did try your suggestion before and it was a bit slower, so I opted for this approach:
pair:
```
Benchmark (enableMessageGapMetrics) Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime true avgt 2 1.688 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime false avgt 2 1.701 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap true avgt 2 11.681 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap false avgt 2 11.836 ns/op
```
two atomics:
```
Benchmark (enableMessageGapMetrics) Mode Cnt Score Error Units
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime true avgt 2 1.690 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMaxSegmentHandoffTime false avgt 2 1.687 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap true avgt 2 8.816 ns/op
SegmentGenerationMetricsBenchmark.benchmarkMultipleReportMessageGap false avgt 2 8.824 ns/op
```
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Enhance message gap metric to include min/max/avg aggregations (druid)
Posted by "jtuglu-netflix (via GitHub)" <gi...@apache.org>.
jtuglu-netflix commented on code in PR #17847:
URL: https://github.com/apache/druid/pull/17847#discussion_r2066988222
##########
server/src/main/java/org/apache/druid/segment/realtime/SegmentGenerationMetrics.java:
##########
@@ -55,6 +56,23 @@ public class SegmentGenerationMetrics
private final AtomicLong maxSegmentHandoffTime = new AtomicLong(NO_EMIT_SEGMENT_HANDOFF_TIME);
+ // Message gap accounting
+ private final AtomicLong minMessageGap = new AtomicLong(Long.MAX_VALUE);
+ private final AtomicLong maxMessageGap = new AtomicLong(Long.MIN_VALUE);
+ private final AtomicLong numMessageGap = new AtomicLong(0);
+ private final AtomicDouble avgMessageGap = new AtomicDouble(0);
Review Comment:
The below would be called per-row:
```java
this.avgGapStats.getAndUpdate(oldValue ->
new Pair<>(oldValue.lhs + messageGap, oldValue.rhs + 1)
);
```
since pair members are final I didn't see a way of doing modification in-place. The ctor might be the overhead there.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org