You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "lukecwik (via GitHub)" <gi...@apache.org> on 2023/01/30 21:55:25 UTC
[GitHub] [beam] lukecwik opened a new pull request, #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
lukecwik opened a new pull request, #25219:
URL: https://github.com/apache/beam/pull/25219
This prevents an expensive scenario where a user is outputting lots of small values (e.g. ints) to be precombined and hence takes little to no space to store so updating the cache provides little value.
Note the 5-10x change for all types except for unique keys. Some early profiles show that there is an issue with the G1 garbage collector when storing so many small values that the GC management overhead dominates 75% of the execution which requires further investigation.
![97qWBX8bwxXhHcb](https://user-images.githubusercontent.com/10078956/215604050-1e1e96d2-6ac4-4b52-8210-829779145af7.png)
Before:
```
Benchmark (distribution) (globallyWindowed) Mode Cnt Score Error Units
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniform true thrpt 5 8.306 ± 1.255 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniform false thrpt 5 7.849 ± 0.476 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine normal true thrpt 5 10.575 ± 1.295 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine normal false thrpt 5 10.772 ± 0.141 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine hotKey true thrpt 5 9.131 ± 2.761 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine hotKey false thrpt 5 8.302 ± 1.078 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniqueKeys true thrpt 5 3.899 ± 1.737 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniqueKeys false thrpt 5 4.203 ± 2.170 ops/s
```
After:
```
Benchmark (distribution) (globallyWindowed) Mode Cnt Score Error Units
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniform true thrpt 5 88.740 ± 8.925 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniform false thrpt 5 76.005 ± 5.150 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine normal true thrpt 5 43.388 ± 1.966 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine normal false thrpt 5 37.804 ± 7.177 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine hotKey true thrpt 5 84.881 ± 5.040 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine hotKey false thrpt 5 74.183 ± 2.063 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniqueKeys true thrpt 5 5.567 ± 4.068 ops/s
PrecombineGroupingTableBenchmark.sumIntegerBinaryCombine uniqueKeys false thrpt 5 6.957 ± 1.508 ops/s
```
**Please** add a meaningful description for your change here
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://beam.apache.org/contribute/get-started-contributing/#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[![Build python source distribution and wheels](https://github.com/apache/beam/workflows/Build%20python%20source%20distribution%20and%20wheels/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[![Python tests](https://github.com/apache/beam/workflows/Python%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[![Java tests](https://github.com/apache/beam/workflows/Java%20Tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[![Go tests](https://github.com/apache/beam/workflows/Go%20tests/badge.svg?branch=master&event=schedule)](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1416406956
Run Spotless PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1409412226
R: @bhisevishal
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1416407386
Run Java_Kafka_IO_Direct PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1416407831
Run Java_Examples_Dataflow_Java11 PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1416454303
Run Java PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] bhisevishal commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "bhisevishal (via GitHub)" <gi...@apache.org>.
bhisevishal commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1411059058
Thank you @lukecwik this is really awesome news
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] bhisevishal commented on a diff in pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "bhisevishal (via GitHub)" <gi...@apache.org>.
bhisevishal commented on code in PR #25219:
URL: https://github.com/apache/beam/pull/25219#discussion_r1096209136
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy:
##########
@@ -1553,7 +1553,7 @@ class BeamModulePlugin implements Plugin<Project> {
if (project.file("/opt/cprof/profiler_java_agent.so").exists()) {
def gcpProject = project.findProperty('gcpProject') ?: 'apache-beam-testing'
def userName = System.getProperty("user.name").toLowerCase().replaceAll(" ", "_")
- jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + System.currentTimeMillis() + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
+ jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + String.format('%1$tm%1$td%1$tY_%1$tH%1$tM%1$tS%1$tL', System.currentTimeMillis()) + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
Review Comment:
ACK
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] bhisevishal commented on a diff in pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "bhisevishal (via GitHub)" <gi...@apache.org>.
bhisevishal commented on code in PR #25219:
URL: https://github.com/apache/beam/pull/25219#discussion_r1096208462
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/Caches.java:
##########
@@ -53,12 +53,16 @@ public final class Caches {
*/
@VisibleForTesting static final int WEIGHT_RATIO = 6;
+ /** Objects which change in this amount should always update the cache. */
+ private static final long CACHE_SIZE_CHANGE_LIMIT_BYTES = 1 << 16;
Review Comment:
ACK
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1416407078
Run Python_Examples PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] bhisevishal commented on a diff in pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "bhisevishal (via GitHub)" <gi...@apache.org>.
bhisevishal commented on code in PR #25219:
URL: https://github.com/apache/beam/pull/25219#discussion_r1096131692
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy:
##########
@@ -1553,7 +1553,7 @@ class BeamModulePlugin implements Plugin<Project> {
if (project.file("/opt/cprof/profiler_java_agent.so").exists()) {
def gcpProject = project.findProperty('gcpProject') ?: 'apache-beam-testing'
def userName = System.getProperty("user.name").toLowerCase().replaceAll(" ", "_")
- jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + System.currentTimeMillis() + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
+ jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + String.format('%1$tm%1$td%1$tY_%1$tH%1$tM%1$tS%1$tL', System.currentTimeMillis()) + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
Review Comment:
Should we start with year so that its always ascending order?
Separations between data and time be more readable.
And if ':' supported then we can use '%1$tY%1$tm%1$td_%1$tH:%1$tM:%1$tS.%1$tL'
but if its overkill please ignore this comment.
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/Caches.java:
##########
@@ -73,6 +77,25 @@ public static long weigh(Object o) {
}
}
+ /**
+ * Returns whether the cache should be updated in the case where the objects size has changed.
+ *
+ * <p>Note that this should only be used in the case where the cache is being updated very often
+ * in a tight loop and is not a good fit for cases where the object being cached is the result of
+ * an expensive operation like a disk read or remote service call.
+ */
+ public static boolean shouldUpdateOnSizeChange(long oldSize, long newSize) {
+ /*
+ Our strategy is three fold:
+ - tiny objects (<= 2^WEIGHT_RATIO) don't change the amount being weighed
+ - large changes (>= CACHE_SIZE_CHANGE_LIMIT_BYTES) should always update the size
+ - all others if the size changed by a factor of 2
+ */
+ return (oldSize > 1 << WEIGHT_RATIO || newSize > 1 << WEIGHT_RATIO)
Review Comment:
can we also convert this to cont so that more readable e.g lower limit or lowe_detla_change some thing like it.
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/Caches.java:
##########
@@ -53,12 +53,16 @@ public final class Caches {
*/
@VisibleForTesting static final int WEIGHT_RATIO = 6;
+ /** Objects which change in this amount should always update the cache. */
+ private static final long CACHE_SIZE_CHANGE_LIMIT_BYTES = 1 << 16;
Review Comment:
Can you add comment why its 2^16 why not less or why not more. Should this value be const or should configurable based on total memory available.
Will this help to in avoiding OOMs we observed on n1-starandrad-1 machine for certain workload? or this is unrelated 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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1416407603
Run Java PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] byronellis commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "byronellis (via GitHub)" <gi...@apache.org>.
byronellis commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1409502290
Run Java PreCommit
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on a diff in pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on code in PR #25219:
URL: https://github.com/apache/beam/pull/25219#discussion_r1091207885
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy:
##########
@@ -1553,7 +1553,7 @@ class BeamModulePlugin implements Plugin<Project> {
if (project.file("/opt/cprof/profiler_java_agent.so").exists()) {
def gcpProject = project.findProperty('gcpProject') ?: 'apache-beam-testing'
def userName = System.getProperty("user.name").toLowerCase().replaceAll(" ", "_")
- jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + System.currentTimeMillis() + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
+ jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + String.format('%1$tm%1$td%1$tY_%1$tH%1$tM%1$tS%1$tL', System.currentTimeMillis()) + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
Review Comment:
this improves the generated name to contain date and time in a human readable format instead of millis since epoch so it is easier to compare your benchmark runs
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on PR #25219:
URL: https://github.com/apache/beam/pull/25219#issuecomment-1411228665
@bhisevishal this is ready for review.
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik commented on a diff in pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik commented on code in PR #25219:
URL: https://github.com/apache/beam/pull/25219#discussion_r1096182774
##########
buildSrc/src/main/groovy/org/apache/beam/gradle/BeamModulePlugin.groovy:
##########
@@ -1553,7 +1553,7 @@ class BeamModulePlugin implements Plugin<Project> {
if (project.file("/opt/cprof/profiler_java_agent.so").exists()) {
def gcpProject = project.findProperty('gcpProject') ?: 'apache-beam-testing'
def userName = System.getProperty("user.name").toLowerCase().replaceAll(" ", "_")
- jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + System.currentTimeMillis() + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
+ jvmArgs '-agentpath:/opt/cprof/profiler_java_agent.so=-cprof_service=' + userName + "_" + project.getProperty("benchmark").toLowerCase() + '_' + String.format('%1$tm%1$td%1$tY_%1$tH%1$tM%1$tS%1$tL', System.currentTimeMillis()) + ',-cprof_project_id=' + gcpProject + ',-cprof_zone_name=us-central1-a'
Review Comment:
Swapped to make year first.
Unfortunately we are limited to `^[a-z0-9]([-a-z0-9_.]{0,253}[a-z0-9])?$` based upon https://cloud.google.com/profiler/docs/profiling-java#service_name_and_version_arguments
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/Caches.java:
##########
@@ -53,12 +53,16 @@ public final class Caches {
*/
@VisibleForTesting static final int WEIGHT_RATIO = 6;
+ /** Objects which change in this amount should always update the cache. */
+ private static final long CACHE_SIZE_CHANGE_LIMIT_BYTES = 1 << 16;
Review Comment:
Added comment.
Not expected to help avoid OOMs we saw on n1-standard-1
##########
sdks/java/harness/src/main/java/org/apache/beam/fn/harness/Caches.java:
##########
@@ -73,6 +77,25 @@ public static long weigh(Object o) {
}
}
+ /**
+ * Returns whether the cache should be updated in the case where the objects size has changed.
+ *
+ * <p>Note that this should only be used in the case where the cache is being updated very often
+ * in a tight loop and is not a good fit for cases where the object being cached is the result of
+ * an expensive operation like a disk read or remote service call.
+ */
+ public static boolean shouldUpdateOnSizeChange(long oldSize, long newSize) {
+ /*
+ Our strategy is three fold:
+ - tiny objects (<= 2^WEIGHT_RATIO) don't change the amount being weighed
+ - large changes (>= CACHE_SIZE_CHANGE_LIMIT_BYTES) should always update the size
+ - all others if the size changed by a factor of 2
+ */
+ return (oldSize > 1 << WEIGHT_RATIO || newSize > 1 << WEIGHT_RATIO)
Review Comment:
done
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [beam] lukecwik merged pull request #25219: Optimize PGBK table to only update cache when there is a large enough size change. #21250
Posted by "lukecwik (via GitHub)" <gi...@apache.org>.
lukecwik merged PR #25219:
URL: https://github.com/apache/beam/pull/25219
--
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: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org