You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "dybyte (via GitHub)" <gi...@apache.org> on 2025/09/06 15:44:16 UTC
[PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
dybyte opened a new pull request, #9833:
URL: https://github.com/apache/seatunnel/pull/9833
Fixes https://github.com/apache/seatunnel/issues/9817
### Purpose of this pull request
This PR introduces a new configuration option `JOB_METRICS_PARTITION_COUNT` which controls the number of partitions used to store running job metrics in Hazelcast IMap. This allows distributing metrics across multiple keys to reduce contention and improve performance when multiple tasks report metrics concurrently.
If you prefer to use a single key for storing metrics, set `JOB_METRICS_PARTITION_COUNT` to `1` (this is the default, so no configuration is required).
For better parallelism under high load, you can increase this value.
However, setting it too high may introduce overhead when aggregating metrics across multiple partitions, which can lead to reduced overall performance.
### Does this PR introduce _any_ user-facing change?
Yes. Users can tune `JOB_METRICS_PARTITION_COUNT` to balance write contention and aggregation overhead. Default is 1 for backward compatibility.
### How was this patch tested?
Current tests verify that `metricsImap` is updated and cleared with a custom partition configuration.
The use of `compute` ensures that updates are atomic and merge with existing metrics without overwriting, reducing write contention compared to the previous synchronized get/put approach. This also minimizes network round-trips, improving performance under concurrent updates.
In performance tests, we populated an initially empty `localMap` with a large number of entries to induce contention. Comparing the previous structure and the new compute-based structure with a single key, the new approach was observed to be faster under these conditions.
### Check list
* [ ] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] If you are contributing the connector code, please check that the following files are updated:
1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3262493572
I am not yet very experienced with performance metrics, so I did not include specific measurements in this PR. However, I can provide benchmarks or metrics if needed—please let me know if you’d like to see them.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3265383254
Hi @qiaoborui , Thanks for raising this important point!
My understanding is that the root cause is `removeMetrics` not executing properly due to heavy contention on the single key.
As a result, finished job metrics were not cleared in time, which caused `runningJobMetrics` to grow indefinitely.
With this PR, since metrics are partitioned, lock contention should be significantly reduced, so `removeMetrics` is expected to work more efficiently.
This may help prevent `runningJobMetrics` from growing indefinitely, even under heavy load.
I’ll keep monitoring this behavior, and if you have further feedback or see this problem persist, please let me know!
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "zhangshenghang (via GitHub)" <gi...@apache.org>.
zhangshenghang commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3266304383
Can we provide a best practice to guide customers in configuration, such as recommended calculation formulas
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#discussion_r2334309508
##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/SeaTunnelServer.java:
##########
@@ -343,49 +343,79 @@ private void printExecutionInfo() {
}
}
- public synchronized void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
+ public void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
if (localMap == null || localMap.isEmpty()) {
return;
}
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
- getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
+ int partitionCount = seaTunnelConfig.getEngineConfig().getJobMetricsPartitionCount();
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- if (centralMap == null) {
- centralMap = new HashMap<>();
- }
- centralMap.putAll(localMap);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ Map<Long, Map<TaskLocation, SeaTunnelMetricsContext>> partitioned = new HashMap<>();
+ localMap.forEach(
+ (key, value) -> {
+ long partition = getMetricsImapPartition(key, partitionCount);
+ partitioned.computeIfAbsent(partition, k -> new HashMap<>()).put(key, value);
+ });
+
+ partitioned
+ .entrySet()
+ .parallelStream()
+ .forEach(
+ entry -> {
+ metricsImap.compute(
+ entry.getKey(),
+ (k, oldVal) -> {
+ if (oldVal == null) oldVal = new HashMap<>();
+ oldVal.putAll(entry.getValue());
+ return oldVal;
+ });
+ });
}
- public synchronized void removeMetrics(PipelineLocation pipelineLocation) {
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ public void removeMetrics(PipelineLocation pipelineLocation) {
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
- if (centralMap == null) {
- return;
+ Map<Long, List<TaskLocation>> partitionedTasks = new HashMap<>();
+ for (Map.Entry<Long, Map<TaskLocation, SeaTunnelMetricsContext>> entry :
+ metricsImap.entrySet()) {
+ long partition = entry.getKey();
+ List<TaskLocation> tasksToRemove =
+ entry.getValue().keySet().stream()
+ .filter(
+ t ->
+ t.getTaskGroupLocation()
+ .getPipelineLocation()
+ .equals(pipelineLocation))
+ .collect(Collectors.toList());
+ if (!tasksToRemove.isEmpty()) {
+ partitionedTasks.put(partition, tasksToRemove);
+ }
}
- List<TaskLocation> taskLocations = getTaskLocations(pipelineLocation, centralMap);
- taskLocations.forEach(centralMap::remove);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ partitionedTasks
+ .entrySet()
+ .parallelStream()
+ .forEach(
Review Comment:
I intentionally separated the logic into two iterations.
The first pass filters tasks outside of `metricsImap` to minimize the time holding its internal resources,
and the second pass performs only the minimal compute operations inside the `metricsImap`.
Since write operations are frequent, I believe this approach can help reduce contention.
I’d be happy to adjust the implementation if you feel a single iteration would be more appropriate.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3268667762
@zhangshenghang Thanks, I've added it to the documentation for everyone’s reference.
Let me know if there’s anything else to improve!
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3263334936
> where this should be documented
https://github.com/apache/seatunnel/blob/dev/docs/en/seatunnel-engine/hybrid-cluster-deployment.md#4-configure-the-seatunnel-engine and https://github.com/apache/seatunnel/blob/dev/docs/en/seatunnel-engine/separated-cluster-deployment.md#4-configure-seatunnel-engine
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "zhangshenghang (via GitHub)" <gi...@apache.org>.
zhangshenghang merged PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3266883009
> By the way, is there a solution for the current issue of runningJobMetrics growing indefinitely? When synchronizing tasks involving several thousand tables, the WAL persisted in OSS frequently reaches hundreds of GB. @Hisoka-X
@qiaoborui We almost fix it in https://github.com/apache/seatunnel/pull/9696 and https://github.com/apache/seatunnel/pull/9776. This PR is only to address potential risks in extreme scenarios.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "qiaoborui (via GitHub)" <gi...@apache.org>.
qiaoborui commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3268746882
> > Can we provide a best practice to guide customers in configuration, such as recommended calculation formulas
>
> @zhangshenghang Based on local performance tests, increasing the partition count provides significant benefits when the number of tasks exceeds approximately 20,000. As a practical guideline, a partition count of around 1,000-2,000 tends to offer the best balance between reducing lock contention and minimizing overhead. It is recommended to start with this value and then adjust based on your cluster size and workload characteristics. Please note that these recommendations are based on my test results, and the optimal values may vary depending on your environment.
Thank you for pointing this out. I've been keeping an eye on this issue recently as well. However, I previously reviewed these two PRs and noticed that the memory leaks addressed were related to `RunningJobStateIMap` and `pendingJobMasterMap`. I didn't observe any changes concerning `RunningJobMetrics`. Nevertheless, I'll give the latest PRs modifying the IMaps a try. Thank you very much for your contributions.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3268640452
> Can we provide a best practice to guide customers in configuration, such as recommended calculation formulas
@zhangshenghang
Based on local performance tests, increasing the partition count provides significant benefits when the number of tasks exceeds approximately 20,000.
As a practical guideline, a partition count of around 2,000 tends to offer the best balance between reducing lock contention and minimizing overhead.
It is recommended to start with this value and then adjust based on your cluster size and workload characteristics.
Please note that these recommendations are based on my test results, and the optimal values may vary depending on your environment.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "qiaoborui (via GitHub)" <gi...@apache.org>.
qiaoborui commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3265185652
By the way, is there a solution for the current issue of runningJobMetrics growing indefinitely? When synchronizing tasks involving several thousand tables, the WAL persisted in OSS frequently reaches hundreds of GB.
@Hisoka-X
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "zhangshenghang (via GitHub)" <gi...@apache.org>.
zhangshenghang commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3268645684
> > Can we provide a best practice to guide customers in configuration, such as recommended calculation formulas
>
> @zhangshenghang Based on local performance tests, increasing the partition count provides significant benefits when the number of tasks exceeds approximately 20,000. As a practical guideline, a partition count of around 2,000 tends to offer the best balance between reducing lock contention and minimizing overhead. It is recommended to start with this value and then adjust based on your cluster size and workload characteristics. Please note that these recommendations are based on my test results, and the optimal values may vary depending on your environment.
@dybyte Thanks, you can include it in the document for reference by others. This makes it more convenient for users to use.
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#discussion_r2341176270
##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/SeaTunnelServer.java:
##########
@@ -343,49 +343,79 @@ private void printExecutionInfo() {
}
}
- public synchronized void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
+ public void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
if (localMap == null || localMap.isEmpty()) {
return;
}
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
- getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
+ int partitionCount = seaTunnelConfig.getEngineConfig().getJobMetricsPartitionCount();
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- if (centralMap == null) {
- centralMap = new HashMap<>();
- }
- centralMap.putAll(localMap);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ Map<Long, Map<TaskLocation, SeaTunnelMetricsContext>> partitioned = new HashMap<>();
+ localMap.forEach(
+ (key, value) -> {
+ long partition = getMetricsImapPartition(key, partitionCount);
+ partitioned.computeIfAbsent(partition, k -> new HashMap<>()).put(key, value);
+ });
+
+ partitioned
+ .entrySet()
+ .parallelStream()
+ .forEach(
+ entry -> {
+ metricsImap.compute(
+ entry.getKey(),
+ (k, oldVal) -> {
+ if (oldVal == null) oldVal = new HashMap<>();
+ oldVal.putAll(entry.getValue());
+ return oldVal;
+ });
+ });
}
- public synchronized void removeMetrics(PipelineLocation pipelineLocation) {
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ public void removeMetrics(PipelineLocation pipelineLocation) {
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
- if (centralMap == null) {
- return;
+ Map<Long, List<TaskLocation>> partitionedTasks = new HashMap<>();
+ for (Map.Entry<Long, Map<TaskLocation, SeaTunnelMetricsContext>> entry :
+ metricsImap.entrySet()) {
+ long partition = entry.getKey();
+ List<TaskLocation> tasksToRemove =
+ entry.getValue().keySet().stream()
+ .filter(
+ t ->
+ t.getTaskGroupLocation()
+ .getPipelineLocation()
+ .equals(pipelineLocation))
+ .collect(Collectors.toList());
+ if (!tasksToRemove.isEmpty()) {
+ partitionedTasks.put(partition, tasksToRemove);
+ }
}
- List<TaskLocation> taskLocations = getTaskLocations(pipelineLocation, centralMap);
- taskLocations.forEach(centralMap::remove);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ partitionedTasks
+ .entrySet()
+ .parallelStream()
+ .forEach(
Review Comment:
We are a bit limited by imap, maybe we should switch to rocksdb in the future. https://github.com/apache/seatunnel/issues/9851
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#discussion_r2333870588
##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/SeaTunnelServer.java:
##########
@@ -343,49 +343,79 @@ private void printExecutionInfo() {
}
}
- public synchronized void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
+ public void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
if (localMap == null || localMap.isEmpty()) {
return;
}
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
- getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
+ int partitionCount = seaTunnelConfig.getEngineConfig().getJobMetricsPartitionCount();
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- if (centralMap == null) {
- centralMap = new HashMap<>();
- }
- centralMap.putAll(localMap);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ Map<Long, Map<TaskLocation, SeaTunnelMetricsContext>> partitioned = new HashMap<>();
+ localMap.forEach(
+ (key, value) -> {
+ long partition = getMetricsImapPartition(key, partitionCount);
+ partitioned.computeIfAbsent(partition, k -> new HashMap<>()).put(key, value);
+ });
+
+ partitioned
+ .entrySet()
+ .parallelStream()
+ .forEach(
+ entry -> {
+ metricsImap.compute(
+ entry.getKey(),
+ (k, oldVal) -> {
+ if (oldVal == null) oldVal = new HashMap<>();
+ oldVal.putAll(entry.getValue());
+ return oldVal;
+ });
+ });
}
- public synchronized void removeMetrics(PipelineLocation pipelineLocation) {
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ public void removeMetrics(PipelineLocation pipelineLocation) {
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
- if (centralMap == null) {
- return;
+ Map<Long, List<TaskLocation>> partitionedTasks = new HashMap<>();
+ for (Map.Entry<Long, Map<TaskLocation, SeaTunnelMetricsContext>> entry :
+ metricsImap.entrySet()) {
+ long partition = entry.getKey();
+ List<TaskLocation> tasksToRemove =
+ entry.getValue().keySet().stream()
+ .filter(
+ t ->
+ t.getTaskGroupLocation()
+ .getPipelineLocation()
+ .equals(pipelineLocation))
+ .collect(Collectors.toList());
+ if (!tasksToRemove.isEmpty()) {
+ partitionedTasks.put(partition, tasksToRemove);
+ }
}
- List<TaskLocation> taskLocations = getTaskLocations(pipelineLocation, centralMap);
- taskLocations.forEach(centralMap::remove);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ partitionedTasks
+ .entrySet()
+ .parallelStream()
+ .forEach(
Review Comment:
Why foreach metricsImap twice? Can we use only once?
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#discussion_r2341176270
##########
seatunnel-engine/seatunnel-engine-server/src/main/java/org/apache/seatunnel/engine/server/SeaTunnelServer.java:
##########
@@ -343,49 +343,79 @@ private void printExecutionInfo() {
}
}
- public synchronized void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
+ public void updateMetrics(Map<TaskLocation, SeaTunnelMetricsContext> localMap) {
if (localMap == null || localMap.isEmpty()) {
return;
}
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
- getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
+ int partitionCount = seaTunnelConfig.getEngineConfig().getJobMetricsPartitionCount();
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- if (centralMap == null) {
- centralMap = new HashMap<>();
- }
- centralMap.putAll(localMap);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ Map<Long, Map<TaskLocation, SeaTunnelMetricsContext>> partitioned = new HashMap<>();
+ localMap.forEach(
+ (key, value) -> {
+ long partition = getMetricsImapPartition(key, partitionCount);
+ partitioned.computeIfAbsent(partition, k -> new HashMap<>()).put(key, value);
+ });
+
+ partitioned
+ .entrySet()
+ .parallelStream()
+ .forEach(
+ entry -> {
+ metricsImap.compute(
+ entry.getKey(),
+ (k, oldVal) -> {
+ if (oldVal == null) oldVal = new HashMap<>();
+ oldVal.putAll(entry.getValue());
+ return oldVal;
+ });
+ });
}
- public synchronized void removeMetrics(PipelineLocation pipelineLocation) {
- IMap<Long, HashMap<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
+ public void removeMetrics(PipelineLocation pipelineLocation) {
+ IMap<Long, Map<TaskLocation, SeaTunnelMetricsContext>> metricsImap =
getNodeEngine().getHazelcastInstance().getMap(Constant.IMAP_RUNNING_JOB_METRICS);
- HashMap<TaskLocation, SeaTunnelMetricsContext> centralMap =
- metricsImap.get(Constant.IMAP_RUNNING_JOB_METRICS_KEY);
- if (centralMap == null) {
- return;
+ Map<Long, List<TaskLocation>> partitionedTasks = new HashMap<>();
+ for (Map.Entry<Long, Map<TaskLocation, SeaTunnelMetricsContext>> entry :
+ metricsImap.entrySet()) {
+ long partition = entry.getKey();
+ List<TaskLocation> tasksToRemove =
+ entry.getValue().keySet().stream()
+ .filter(
+ t ->
+ t.getTaskGroupLocation()
+ .getPipelineLocation()
+ .equals(pipelineLocation))
+ .collect(Collectors.toList());
+ if (!tasksToRemove.isEmpty()) {
+ partitionedTasks.put(partition, tasksToRemove);
+ }
}
- List<TaskLocation> taskLocations = getTaskLocations(pipelineLocation, centralMap);
- taskLocations.forEach(centralMap::remove);
- metricsImap.put(Constant.IMAP_RUNNING_JOB_METRICS_KEY, centralMap);
+ partitionedTasks
+ .entrySet()
+ .parallelStream()
+ .forEach(
Review Comment:
We are a bit limited by imap, maybe we should switch to rocksdb 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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][Zeta] Improve job metrics handling with partitioning support [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on PR #9833:
URL: https://github.com/apache/seatunnel/pull/9833#issuecomment-3262456032
I was planning to document this new configuration option, but I couldn't find the relevant section for master server config options. Could you please point me to where this should be documented?
--
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@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org