You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "StefanRRichter (via GitHub)" <gi...@apache.org> on 2024/01/17 13:56:16 UTC
[PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
StefanRRichter opened a new pull request, #24119:
URL: https://github.com/apache/flink/pull/24119
## What is the purpose of the change
Introduces tracing for state sizes and locations in task recovery. This is particularly interesting for a mixed recovery with some local and some remote state.
## Brief change log
- Add new stats collection default method to state object interface.
- Implement StateObject type-specific overrides.
- Perform stats collecting and reporting during restore.
- Documentation.
## Verifying this change
- Added tests for stats collecting implementations.
- Enhanced StreamTaskStateInitializerImplTest with checking tracing results.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (no)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)
- The serializers: (no)
- The runtime per-record code paths (performance sensitive): (no )
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes)
- The S3 file system connector: (no)
## Documentation
- Does this pull request introduce a new feature? (yes)
- If yes, how is the feature documented? ( docs / JavaDocs)
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "StefanRRichter (via GitHub)" <gi...@apache.org>.
StefanRRichter commented on code in PR #24119:
URL: https://github.com/apache/flink/pull/24119#discussion_r1457351231
##########
docs/content.zh/docs/ops/traces.md:
##########
@@ -159,6 +159,14 @@ Flink reports a single span trace for the whole checkpoint and job initializatio
<td>(Max/Sum)DownloadStateDurationMs<br><br>(optional - currently only supported by RocksDB Incremental)</td>
<td>The aggregated (max and sum) across all subtasks duration of downloading state files from the DFS.</td>
</tr>
+ <tr>
+ <td>(Max/Sum)RestoreStateSizeBytes.[location]<br><br>(optional - only reported if metrics.trace-restore-state-size is true)</td>
Review Comment:
Fine with me.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "StefanRRichter (via GitHub)" <gi...@apache.org>.
StefanRRichter closed pull request #24119: [FLINK-34134] Add tracing for restored state size and locations
URL: https://github.com/apache/flink/pull/24119
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "flinkbot (via GitHub)" <gi...@apache.org>.
flinkbot commented on PR #24119:
URL: https://github.com/apache/flink/pull/24119#issuecomment-1895884723
<!--
Meta data
{
"version" : 1,
"metaDataEntries" : [ {
"hash" : "5752457fc6142577ba63e376e11f15e0dfeb5dfc",
"status" : "UNKNOWN",
"url" : "TBD",
"triggerID" : "5752457fc6142577ba63e376e11f15e0dfeb5dfc",
"triggerType" : "PUSH"
} ]
}-->
## CI report:
* 5752457fc6142577ba63e376e11f15e0dfeb5dfc UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run azure` re-run the last Azure build
</details>
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "StefanRRichter (via GitHub)" <gi...@apache.org>.
StefanRRichter commented on code in PR #24119:
URL: https://github.com/apache/flink/pull/24119#discussion_r1457345256
##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/StateObject.java:
##########
@@ -63,4 +64,60 @@ public interface StateObject extends Serializable {
* @return Size of the state in bytes.
*/
long getStateSize();
+
+ /**
+ * Collects statistics about state size and location from the state object.
+ *
+ * @implNote default implementation reports {@link StateObject#getStateSize()} as size and
+ * {@link StateObjectLocation#UNKNOWN} as location.
+ * @param collector the statistics collector.
+ */
+ default void collectSizeStats(StateObjectSizeStatsCollector collector) {
+ collector.add(StateObjectLocation.UNKNOWN, getStateSize());
+ }
+
+ /** Enum for state locations. */
+ enum StateObjectLocation {
+ LOCAL_MEMORY,
+ LOCAL_DISK,
+ REMOTE,
+ UNKNOWN,
+ }
+
+ /**
+ * Collector for size and location stats from a state object via {@link
+ * StateObject#collectSizeStats(StateObjectSizeStatsCollector)}.
+ */
+ final class StateObjectSizeStatsCollector {
+ private final EnumMap<StateObjectLocation, Long> stats;
+
+ private StateObjectSizeStatsCollector() {
+ stats = new EnumMap<>(StateObjectLocation.class);
+ }
+
+ public void add(StateObjectLocation key, long value) {
+ stats.compute(
+ key,
+ (k, v) -> {
+ if (v != null) {
+ return v + value;
+ } else {
+ return value;
+ }
+ });
+ }
+
+ public EnumMap<StateObjectLocation, Long> getStats() {
+ return stats;
+ }
+
+ public static StateObjectSizeStatsCollector create() {
+ return new StateObjectSizeStatsCollector();
+ }
+
+ @Override
+ public String toString() {
+ return "StateObjectSizeStatsCollector{" + "stats=" + stats + '}';
Review Comment:
Yes
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "pnowojski (via GitHub)" <gi...@apache.org>.
pnowojski commented on code in PR #24119:
URL: https://github.com/apache/flink/pull/24119#discussion_r1457322520
##########
flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/StateHandleDownloadSpec.java:
##########
@@ -53,7 +53,9 @@ public IncrementalLocalKeyedStateHandle createLocalStateHandleForDownloadedState
return new IncrementalLocalKeyedStateHandle(
stateHandle.getBackendIdentifier(),
stateHandle.getCheckpointId(),
- new DirectoryStateHandle(downloadDestination),
+ // This handle is just temporary and will the directory size will never be used for
+ // metrics, so we just fill it in as 0.
+ new DirectoryStateHandle(downloadDestination, 0L),
Review Comment:
For completeness, why don't you pass here `stateHandle.getStateSize()`?
##########
flink-runtime/src/main/java/org/apache/flink/runtime/state/StateObject.java:
##########
@@ -63,4 +64,60 @@ public interface StateObject extends Serializable {
* @return Size of the state in bytes.
*/
long getStateSize();
+
+ /**
+ * Collects statistics about state size and location from the state object.
+ *
+ * @implNote default implementation reports {@link StateObject#getStateSize()} as size and
+ * {@link StateObjectLocation#UNKNOWN} as location.
+ * @param collector the statistics collector.
+ */
+ default void collectSizeStats(StateObjectSizeStatsCollector collector) {
+ collector.add(StateObjectLocation.UNKNOWN, getStateSize());
+ }
+
+ /** Enum for state locations. */
+ enum StateObjectLocation {
+ LOCAL_MEMORY,
+ LOCAL_DISK,
+ REMOTE,
+ UNKNOWN,
+ }
+
+ /**
+ * Collector for size and location stats from a state object via {@link
+ * StateObject#collectSizeStats(StateObjectSizeStatsCollector)}.
+ */
+ final class StateObjectSizeStatsCollector {
+ private final EnumMap<StateObjectLocation, Long> stats;
+
+ private StateObjectSizeStatsCollector() {
+ stats = new EnumMap<>(StateObjectLocation.class);
+ }
+
+ public void add(StateObjectLocation key, long value) {
+ stats.compute(
+ key,
+ (k, v) -> {
+ if (v != null) {
+ return v + value;
+ } else {
+ return value;
+ }
+ });
+ }
+
+ public EnumMap<StateObjectLocation, Long> getStats() {
+ return stats;
+ }
+
+ public static StateObjectSizeStatsCollector create() {
+ return new StateObjectSizeStatsCollector();
+ }
+
+ @Override
+ public String toString() {
+ return "StateObjectSizeStatsCollector{" + "stats=" + stats + '}';
Review Comment:
Will this print to a human readable map representation?
##########
docs/content.zh/docs/ops/traces.md:
##########
@@ -159,6 +159,14 @@ Flink reports a single span trace for the whole checkpoint and job initializatio
<td>(Max/Sum)DownloadStateDurationMs<br><br>(optional - currently only supported by RocksDB Incremental)</td>
<td>The aggregated (max and sum) across all subtasks duration of downloading state files from the DFS.</td>
</tr>
+ <tr>
+ <td>(Max/Sum)RestoreStateSizeBytes.[location]<br><br>(optional - only reported if metrics.trace-restore-state-size is true)</td>
Review Comment:
Restore**d**StateSizeBytes ? (ditto in the actual metric name)
##########
flink-runtime/src/main/java/org/apache/flink/runtime/checkpoint/OperatorSubtaskState.java:
##########
@@ -130,21 +135,26 @@ private OperatorSubtaskState(
this.inputRescalingDescriptor = checkNotNull(inputRescalingDescriptor);
this.outputRescalingDescriptor = checkNotNull(outputRescalingDescriptor);
- long calculateStateSize = managedOperatorState.getStateSize();
- calculateStateSize += rawOperatorState.getStateSize();
- calculateStateSize += managedKeyedState.getStateSize();
- calculateStateSize += rawKeyedState.getStateSize();
- calculateStateSize += inputChannelState.getStateSize();
- calculateStateSize += resultSubpartitionState.getStateSize();
- stateSize = calculateStateSize;
-
- long calculateCheckpointedSize = managedOperatorState.getCheckpointedSize();
- calculateCheckpointedSize += rawOperatorState.getCheckpointedSize();
- calculateCheckpointedSize += managedKeyedState.getCheckpointedSize();
- calculateCheckpointedSize += rawKeyedState.getCheckpointedSize();
- calculateCheckpointedSize += inputChannelState.getCheckpointedSize();
- calculateCheckpointedSize += resultSubpartitionState.getCheckpointedSize();
- this.checkpointedSize = calculateCheckpointedSize;
+ this.stateSize = streamSubCollections().mapToLong(StateObject::getStateSize).sum();
+ this.checkpointedSize =
+ streamSubCollections().mapToLong(StateObjectCollection::getCheckpointedSize).sum();
+ }
+
+ private Stream<StateObjectCollection<?>> streamSubCollections() {
+ return Stream.of(streamOperatorAndKeyedStates(), streamChannelStates())
+ .flatMap(Function.identity());
+ }
+
+ private Stream<StateObjectCollection<? extends StateObject>> streamOperatorAndKeyedStates() {
+ return Stream.of(managedOperatorState, rawOperatorState, managedKeyedState, rawKeyedState)
+ .filter(Objects::nonNull);
+ }
+
+ private Stream<StateObjectCollection<? extends AbstractChannelStateHandle<?>>>
+ streamChannelStates() {
+ return Stream.<StateObjectCollection<? extends AbstractChannelStateHandle<?>>>of(
+ inputChannelState, resultSubpartitionState)
+ .filter(Objects::nonNull);
Review Comment:
Why do we need two methods, can not we have just a single one returning both op and channel state?
edit: I see `collectUniqueDelegates`. Note, `collectUniqueDelegates` could be refactored to also support but ignore non channel state, and then we wouldn't need to differentiate between two types of handles? But I'm not sure which option is better so 🤷
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamTaskStateInitializerImpl.java:
##########
@@ -227,6 +238,24 @@ public StreamOperatorStateContext streamOperatorStateContext(
timeServiceManager = null;
}
+ // Add stats for input channel and result partition state
+ Stream.concat(
+ prioritizedOperatorSubtaskStates.getPrioritizedInputChannelState()
+ .stream(),
+ prioritizedOperatorSubtaskStates.getPrioritizedResultSubpartitionState()
+ .stream())
+ .filter(Objects::nonNull)
+ .forEach(channelHandle -> channelHandle.collectSizeStats(statsCollector));
+
+ // Report collected stats to metrics
+ statsCollector
+ .getStats()
+ .forEach(
Review Comment:
If you are going all in with streams, why don't you merge those two?
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "StefanRRichter (via GitHub)" <gi...@apache.org>.
StefanRRichter merged PR #24119:
URL: https://github.com/apache/flink/pull/24119
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "StefanRRichter (via GitHub)" <gi...@apache.org>.
StefanRRichter commented on code in PR #24119:
URL: https://github.com/apache/flink/pull/24119#discussion_r1457349158
##########
flink-state-backends/flink-statebackend-rocksdb/src/main/java/org/apache/flink/contrib/streaming/state/StateHandleDownloadSpec.java:
##########
@@ -53,7 +53,9 @@ public IncrementalLocalKeyedStateHandle createLocalStateHandleForDownloadedState
return new IncrementalLocalKeyedStateHandle(
stateHandle.getBackendIdentifier(),
stateHandle.getCheckpointId(),
- new DirectoryStateHandle(downloadDestination),
+ // This handle is just temporary and will the directory size will never be used for
+ // metrics, so we just fill it in as 0.
+ new DirectoryStateHandle(downloadDestination, 0L),
Review Comment:
Need to double check if that would do the right thing, I didn't care much because none of that is every reported, but yeah...if it works it's nicer.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [FLINK-34134] Add tracing for restored state size and locations [flink]
Posted by "StefanRRichter (via GitHub)" <gi...@apache.org>.
StefanRRichter commented on code in PR #24119:
URL: https://github.com/apache/flink/pull/24119#discussion_r1457346844
##########
flink-streaming-java/src/main/java/org/apache/flink/streaming/api/operators/StreamTaskStateInitializerImpl.java:
##########
@@ -227,6 +238,24 @@ public StreamOperatorStateContext streamOperatorStateContext(
timeServiceManager = null;
}
+ // Add stats for input channel and result partition state
+ Stream.concat(
+ prioritizedOperatorSubtaskStates.getPrioritizedInputChannelState()
+ .stream(),
+ prioritizedOperatorSubtaskStates.getPrioritizedResultSubpartitionState()
+ .stream())
+ .filter(Objects::nonNull)
+ .forEach(channelHandle -> channelHandle.collectSizeStats(statsCollector));
+
+ // Report collected stats to metrics
+ statsCollector
+ .getStats()
+ .forEach(
Review Comment:
One is still collecting remaining stats from channels, the second is reporting. I like to keep them separate.
--
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: issues-unsubscribe@flink.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org