You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/07/05 14:13:40 UTC

[GitHub] [beam] steveniemitz opened a new pull request, #22162: Optimize locking in several critical-path methods

steveniemitz opened a new pull request, #22162:
URL: https://github.com/apache/beam/pull/22162

   This fixes `ProxyInvocationHandler.as`, `DoFnSignatures.getSignature`, and `ByteBuddyDoFnInvokerFactory.getByteBuddyInvokerConstructor` from #22161
   
   The fixes to DoFnSignatures and ByteBuddyDoFnInvokerFactory are trivially changing a Map to ConcurrentHashMap.
   
   ProxyInvocationHandler is more involved, since multiple data structures must be updated atomically on a cache miss.  To do this we extract the relevant structures into an immutable class.  On a cache miss we construct a new instance of it with new (also immutable) copies of the updated structures.  The trade-off here is slightly more garbage creation on a cache miss (since it needs to copy the structures rather than mutate them), however since in steady-state misses ~never occur, and the structures here in question are generally small (~100s of elements).
   
   The impact of these changes is very significant, without these changes my test job spends ~30% of its time in the "start bundle" state, after these changes (as well as ExecutionStateSampler), the % time goes down to ~1-2%.
   
   R: @lukecwik 
   
   ------------------------
   
   Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
   
    - [ ] [**Choose reviewer(s)**](https://beam.apache.org/contribute/#make-your-change) and mention them in a comment (`R: @username`).
    - [x] 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.
    - [x] 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/#make-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)
   
   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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1175333289

   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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1178308826

   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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1176969636

   > It would be great to add a concurrency test to ensure that things like `toString`/`populateDisplayData`/`serialize` all work when `as()` is modifying computed properties.
   > 
   > Not sure how easy it will be since you'll need to generate classes at runtime to invoke `.as()` to.
   
   Hm, yeah what did you have in mind here?  I was struggling to think of anything useful to test.


-- 
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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1175375569

   The Pulsar tests are consistently failing again, seems unrelated to this change:
   
   ```
   Caused by: java.lang.IllegalArgumentException: Trying to claim offset 1657045837238 before start of the range [1657045838354, 1657045838364)
   ```
   


-- 
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 #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
lukecwik commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1177075675

   > > It would be great to add a concurrency test to ensure that things like `toString`/`populateDisplayData`/`serialize` all work when `as()` is modifying computed properties.
   > > Not sure how easy it will be since you'll need to generate classes at runtime to invoke `.as()` to.
   > 
   > Hm, yeah what did you have in mind here? I was struggling to think of anything useful to test.
   
   generate new classes in a loop that add a new getter/setter and call .as() and then set the value to a new property. At the same time have another thread in a loop continuously calling toString/populateDisplayData/serialize ensuring that we don't throw an exception.


-- 
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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1178232404

   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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1175345259

   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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1177858120

   > generate new classes in a loop that add a new getter/setter and call .as() and then set the value to a new property. At the same time have another thread in a loop continuously calling toString/populateDisplayData/serialize ensuring that we don't throw an exception.
   
   Cool, 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] steveniemitz commented on a diff in pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on code in PR #22162:
URL: https://github.com/apache/beam/pull/22162#discussion_r915309553


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -96,21 +98,56 @@ class ProxyInvocationHandler implements InvocationHandler, Serializable {
    */
   private final int hashCode = ThreadLocalRandom.current().nextInt();
 
-  private final Set<Class<? extends PipelineOptions>> knownInterfaces;
+  private static final class ComputedProperties {
+    final ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+    final ImmutableMap<String, String> gettersToPropertyNames;
+    final ImmutableMap<String, String> settersToPropertyNames;
+    final ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces;
+
+    private ComputedProperties(
+        ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache,
+        ImmutableMap<String, String> gettersToPropertyNames,
+        ImmutableMap<String, String> settersToPropertyNames,
+        ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces) {
+      this.interfaceToProxyCache = interfaceToProxyCache;
+      this.gettersToPropertyNames = gettersToPropertyNames;
+      this.settersToPropertyNames = settersToPropertyNames;
+      this.knownInterfaces = knownInterfaces;
+    }
+
+    <T extends PipelineOptions> ComputedProperties updated(
+        Class<T> iface, T instance, List<PropertyDescriptor> propertyDescriptors) {
+
+      // these all use mutable maps and then copyOf, rather than a builder because builders enforce
+      // all keys are unique, and its possible they are not here.
+      Map<String, String> allNewGetters = Maps.newHashMap(gettersToPropertyNames);
+      Map<String, String> allNewSetters = Maps.newHashMap(settersToPropertyNames);
+      Set<Class<? extends PipelineOptions>> newKnownInterfaces = Sets.newHashSet(knownInterfaces);
+      Map<Class<? extends PipelineOptions>, PipelineOptions> newInterfaceCache =
+          Maps.newHashMap(interfaceToProxyCache);
+
+      allNewGetters.putAll(generateGettersToPropertyNames(propertyDescriptors));
+      allNewSetters.putAll(generateSettersToPropertyNames(propertyDescriptors));
+      newKnownInterfaces.add(iface);
+      newInterfaceCache.put(iface, instance);
+
+      return new ComputedProperties(
+          ImmutableClassToInstanceMap.copyOf(newInterfaceCache),
+          ImmutableMap.copyOf(allNewGetters),
+          ImmutableMap.copyOf(allNewSetters),
+          ImmutableSet.copyOf(newKnownInterfaces));
+    }
+  }
 
-  // ProxyInvocationHandler implements Serializable only for the sake of throwing an informative
-  // exception in writeObject()
   @SuppressFBWarnings("SE_BAD_FIELD")
-  private final ClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+  private volatile ComputedProperties computedProperties;

Review Comment:
   oh yeah that's true!



-- 
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 #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
lukecwik merged PR #22162:
URL: https://github.com/apache/beam/pull/22162


-- 
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] steveniemitz commented on a diff in pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on code in PR #22162:
URL: https://github.com/apache/beam/pull/22162#discussion_r915242906


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -96,21 +98,56 @@ class ProxyInvocationHandler implements InvocationHandler, Serializable {
    */
   private final int hashCode = ThreadLocalRandom.current().nextInt();
 
-  private final Set<Class<? extends PipelineOptions>> knownInterfaces;
+  private static final class ComputedProperties {
+    final ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+    final ImmutableMap<String, String> gettersToPropertyNames;
+    final ImmutableMap<String, String> settersToPropertyNames;
+    final ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces;
+
+    private ComputedProperties(
+        ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache,
+        ImmutableMap<String, String> gettersToPropertyNames,
+        ImmutableMap<String, String> settersToPropertyNames,
+        ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces) {
+      this.interfaceToProxyCache = interfaceToProxyCache;
+      this.gettersToPropertyNames = gettersToPropertyNames;
+      this.settersToPropertyNames = settersToPropertyNames;
+      this.knownInterfaces = knownInterfaces;
+    }
+
+    <T extends PipelineOptions> ComputedProperties updated(
+        Class<T> iface, T instance, List<PropertyDescriptor> propertyDescriptors) {
+
+      // these all use mutable maps and then copyOf, rather than a builder because builders enforce
+      // all keys are unique, and its possible they are not here.
+      Map<String, String> allNewGetters = Maps.newHashMap(gettersToPropertyNames);
+      Map<String, String> allNewSetters = Maps.newHashMap(settersToPropertyNames);
+      Set<Class<? extends PipelineOptions>> newKnownInterfaces = Sets.newHashSet(knownInterfaces);
+      Map<Class<? extends PipelineOptions>, PipelineOptions> newInterfaceCache =
+          Maps.newHashMap(interfaceToProxyCache);
+
+      allNewGetters.putAll(generateGettersToPropertyNames(propertyDescriptors));
+      allNewSetters.putAll(generateSettersToPropertyNames(propertyDescriptors));
+      newKnownInterfaces.add(iface);
+      newInterfaceCache.put(iface, instance);
+
+      return new ComputedProperties(
+          ImmutableClassToInstanceMap.copyOf(newInterfaceCache),
+          ImmutableMap.copyOf(allNewGetters),
+          ImmutableMap.copyOf(allNewSetters),
+          ImmutableSet.copyOf(newKnownInterfaces));
+    }
+  }
 
-  // ProxyInvocationHandler implements Serializable only for the sake of throwing an informative
-  // exception in writeObject()
   @SuppressFBWarnings("SE_BAD_FIELD")
-  private final ClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+  private volatile ComputedProperties computedProperties;

Review Comment:
   I'll add the comment, although the fact that is it only modified under a lock is not required for correctness.



-- 
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 #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
lukecwik commented on code in PR #22162:
URL: https://github.com/apache/beam/pull/22162#discussion_r915304504


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -96,21 +98,56 @@ class ProxyInvocationHandler implements InvocationHandler, Serializable {
    */
   private final int hashCode = ThreadLocalRandom.current().nextInt();
 
-  private final Set<Class<? extends PipelineOptions>> knownInterfaces;
+  private static final class ComputedProperties {
+    final ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+    final ImmutableMap<String, String> gettersToPropertyNames;
+    final ImmutableMap<String, String> settersToPropertyNames;
+    final ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces;
+
+    private ComputedProperties(
+        ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache,
+        ImmutableMap<String, String> gettersToPropertyNames,
+        ImmutableMap<String, String> settersToPropertyNames,
+        ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces) {
+      this.interfaceToProxyCache = interfaceToProxyCache;
+      this.gettersToPropertyNames = gettersToPropertyNames;
+      this.settersToPropertyNames = settersToPropertyNames;
+      this.knownInterfaces = knownInterfaces;
+    }
+
+    <T extends PipelineOptions> ComputedProperties updated(
+        Class<T> iface, T instance, List<PropertyDescriptor> propertyDescriptors) {
+
+      // these all use mutable maps and then copyOf, rather than a builder because builders enforce
+      // all keys are unique, and its possible they are not here.
+      Map<String, String> allNewGetters = Maps.newHashMap(gettersToPropertyNames);
+      Map<String, String> allNewSetters = Maps.newHashMap(settersToPropertyNames);
+      Set<Class<? extends PipelineOptions>> newKnownInterfaces = Sets.newHashSet(knownInterfaces);
+      Map<Class<? extends PipelineOptions>, PipelineOptions> newInterfaceCache =
+          Maps.newHashMap(interfaceToProxyCache);
+
+      allNewGetters.putAll(generateGettersToPropertyNames(propertyDescriptors));
+      allNewSetters.putAll(generateSettersToPropertyNames(propertyDescriptors));
+      newKnownInterfaces.add(iface);
+      newInterfaceCache.put(iface, instance);
+
+      return new ComputedProperties(
+          ImmutableClassToInstanceMap.copyOf(newInterfaceCache),
+          ImmutableMap.copyOf(allNewGetters),
+          ImmutableMap.copyOf(allNewSetters),
+          ImmutableSet.copyOf(newKnownInterfaces));
+    }
+  }
 
-  // ProxyInvocationHandler implements Serializable only for the sake of throwing an informative
-  // exception in writeObject()
   @SuppressFBWarnings("SE_BAD_FIELD")
-  private final ClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+  private volatile ComputedProperties computedProperties;

Review Comment:
   For the double checked locking to work we need to synchronize on something otherwise we won't guarantee we will drop another's mutation unless we swap to a CAS like operation.



-- 
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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1178193928

   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] steveniemitz commented on a diff in pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on code in PR #22162:
URL: https://github.com/apache/beam/pull/22162#discussion_r915256981


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -671,50 +726,50 @@ private void serializeEntry(
     public void serialize(PipelineOptions value, JsonGenerator jgen, SerializerProvider provider)
         throws IOException {
       ProxyInvocationHandler handler = (ProxyInvocationHandler) Proxy.getInvocationHandler(value);
-      synchronized (handler) {
-        PipelineOptionsFactory.Cache cache = PipelineOptionsFactory.CACHE.get();
-        // We first filter out any properties that have been modified since
-        // the last serialization of this PipelineOptions and then verify that
-        // they are all serializable.
-        Map<String, BoundValue> filteredOptions = Maps.newHashMap(handler.options);
-        Map<String, JsonSerializer<Object>> propertyToSerializer =
-            getSerializerMap(cache, handler.knownInterfaces);
-        removeIgnoredOptions(cache, handler.knownInterfaces, filteredOptions);
-        ensureSerializable(cache, handler.knownInterfaces, filteredOptions, propertyToSerializer);
-
-        // Now we create the map of serializable options by taking the original
-        // set of serialized options (if any) and updating them with any properties
-        // instances that have been modified since the previous serialization.
-        Map<String, Object> serializableOptions = Maps.newHashMap(handler.jsonOptions);
-        for (Map.Entry<String, BoundValue> entry : filteredOptions.entrySet()) {
-          serializableOptions.put(entry.getKey(), entry.getValue().getValue());
-        }
+      PipelineOptionsFactory.Cache cache = PipelineOptionsFactory.CACHE.get();
+      // We first filter out any properties that have been modified since
+      // the last serialization of this PipelineOptions and then verify that
+      // they are all serializable.
+      Map<String, BoundValue> filteredOptions = Maps.newHashMap(handler.options);
+      Set<Class<? extends PipelineOptions>> knownInterfaces =
+          handler.computedProperties.knownInterfaces;
+      Map<String, JsonSerializer<Object>> propertyToSerializer =
+          getSerializerMap(cache, knownInterfaces);
+      removeIgnoredOptions(cache, knownInterfaces, filteredOptions);
+      ensureSerializable(cache, knownInterfaces, filteredOptions, propertyToSerializer);

Review Comment:
   oh yeah I like that idea.



-- 
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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1178116650

   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 #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
lukecwik commented on code in PR #22162:
URL: https://github.com/apache/beam/pull/22162#discussion_r915171497


##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/ByteBuddyDoFnInvokerFactory.java:
##########
@@ -170,7 +170,7 @@ public <InputT, OutputT> DoFnInvoker<InputT, OutputT> invokerFor(DoFn<InputT, Ou
    * number of classes consuming PermGen memory.

Review Comment:
   ```suggestion
      * number of classes consuming PermGen memory.
      *
      * <p>Note that special care must be taken to enumerate this object as concurrent hash maps are <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html#Weakly>weakly consistent</a>.
   ```



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -671,50 +726,50 @@ private void serializeEntry(
     public void serialize(PipelineOptions value, JsonGenerator jgen, SerializerProvider provider)
         throws IOException {
       ProxyInvocationHandler handler = (ProxyInvocationHandler) Proxy.getInvocationHandler(value);
-      synchronized (handler) {
-        PipelineOptionsFactory.Cache cache = PipelineOptionsFactory.CACHE.get();
-        // We first filter out any properties that have been modified since
-        // the last serialization of this PipelineOptions and then verify that
-        // they are all serializable.
-        Map<String, BoundValue> filteredOptions = Maps.newHashMap(handler.options);
-        Map<String, JsonSerializer<Object>> propertyToSerializer =
-            getSerializerMap(cache, handler.knownInterfaces);
-        removeIgnoredOptions(cache, handler.knownInterfaces, filteredOptions);
-        ensureSerializable(cache, handler.knownInterfaces, filteredOptions, propertyToSerializer);
-
-        // Now we create the map of serializable options by taking the original
-        // set of serialized options (if any) and updating them with any properties
-        // instances that have been modified since the previous serialization.
-        Map<String, Object> serializableOptions = Maps.newHashMap(handler.jsonOptions);
-        for (Map.Entry<String, BoundValue> entry : filteredOptions.entrySet()) {
-          serializableOptions.put(entry.getKey(), entry.getValue().getValue());
-        }
+      PipelineOptionsFactory.Cache cache = PipelineOptionsFactory.CACHE.get();
+      // We first filter out any properties that have been modified since
+      // the last serialization of this PipelineOptions and then verify that
+      // they are all serializable.
+      Map<String, BoundValue> filteredOptions = Maps.newHashMap(handler.options);
+      Set<Class<? extends PipelineOptions>> knownInterfaces =
+          handler.computedProperties.knownInterfaces;
+      Map<String, JsonSerializer<Object>> propertyToSerializer =
+          getSerializerMap(cache, knownInterfaces);
+      removeIgnoredOptions(cache, knownInterfaces, filteredOptions);
+      ensureSerializable(cache, knownInterfaces, filteredOptions, propertyToSerializer);

Review Comment:
   Can we make `getSerializerMap`, `removeIgnoredOptions`, and `ensureSerializable` to be static methods. It helps with understanding the ordering since the static method will be prevented from reading `this`.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/reflect/DoFnSignatures.java:
##########
@@ -114,7 +114,8 @@ public class DoFnSignatures {
 
   private DoFnSignatures() {}
 
-  private static final Map<Class<?>, DoFnSignature> signatureCache = new LinkedHashMap<>();
+  private static final Map<Class<? extends DoFn<?, ?>>, DoFnSignature> signatureCache =

Review Comment:
   ```suggestion
    /**
      * Note that special care must be taken to enumerate this object as concurrent hash maps are <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html#Weakly>weakly consistent</a>.
      */
     private static final Map<Class<? extends DoFn<?, ?>>, DoFnSignature> signatureCache =
   ```



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -302,7 +358,7 @@ class PipelineOptionsDisplayData implements HasDisplayData {
     @Override
     public void populateDisplayData(DisplayData.Builder builder) {
       Set<PipelineOptionSpec> optionSpecs =

Review Comment:
   ```suggestion
         // We must first make a copy of the current options because a concurrent modification
         // may add a new option after we have derived optionSpecs but before we have enumerated
         // all the pipeline options.
         Map<String, BoundValue> copiedOptions = new HashMap<>(options);
         Set<PipelineOptionSpec> optionSpecs =
   ```
   And then update usage below to use the copy.



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -96,21 +98,56 @@ class ProxyInvocationHandler implements InvocationHandler, Serializable {
    */
   private final int hashCode = ThreadLocalRandom.current().nextInt();
 
-  private final Set<Class<? extends PipelineOptions>> knownInterfaces;
+  private static final class ComputedProperties {
+    final ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+    final ImmutableMap<String, String> gettersToPropertyNames;
+    final ImmutableMap<String, String> settersToPropertyNames;
+    final ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces;
+
+    private ComputedProperties(
+        ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache,
+        ImmutableMap<String, String> gettersToPropertyNames,
+        ImmutableMap<String, String> settersToPropertyNames,
+        ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces) {
+      this.interfaceToProxyCache = interfaceToProxyCache;
+      this.gettersToPropertyNames = gettersToPropertyNames;
+      this.settersToPropertyNames = settersToPropertyNames;
+      this.knownInterfaces = knownInterfaces;
+    }
+
+    <T extends PipelineOptions> ComputedProperties updated(
+        Class<T> iface, T instance, List<PropertyDescriptor> propertyDescriptors) {
+
+      // these all use mutable maps and then copyOf, rather than a builder because builders enforce
+      // all keys are unique, and its possible they are not here.
+      Map<String, String> allNewGetters = Maps.newHashMap(gettersToPropertyNames);
+      Map<String, String> allNewSetters = Maps.newHashMap(settersToPropertyNames);
+      Set<Class<? extends PipelineOptions>> newKnownInterfaces = Sets.newHashSet(knownInterfaces);
+      Map<Class<? extends PipelineOptions>, PipelineOptions> newInterfaceCache =
+          Maps.newHashMap(interfaceToProxyCache);
+
+      allNewGetters.putAll(generateGettersToPropertyNames(propertyDescriptors));
+      allNewSetters.putAll(generateSettersToPropertyNames(propertyDescriptors));
+      newKnownInterfaces.add(iface);
+      newInterfaceCache.put(iface, instance);
+
+      return new ComputedProperties(
+          ImmutableClassToInstanceMap.copyOf(newInterfaceCache),
+          ImmutableMap.copyOf(allNewGetters),
+          ImmutableMap.copyOf(allNewSetters),
+          ImmutableSet.copyOf(newKnownInterfaces));
+    }
+  }
 
-  // ProxyInvocationHandler implements Serializable only for the sake of throwing an informative
-  // exception in writeObject()
   @SuppressFBWarnings("SE_BAD_FIELD")
-  private final ClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+  private volatile ComputedProperties computedProperties;

Review Comment:
   ```suggestion
     /** Only modified while holding a lock on {@code this}. */
     private volatile ComputedProperties computedProperties;
   ```



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -96,21 +98,56 @@ class ProxyInvocationHandler implements InvocationHandler, Serializable {
    */
   private final int hashCode = ThreadLocalRandom.current().nextInt();
 
-  private final Set<Class<? extends PipelineOptions>> knownInterfaces;
+  private static final class ComputedProperties {
+    final ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+    final ImmutableMap<String, String> gettersToPropertyNames;
+    final ImmutableMap<String, String> settersToPropertyNames;
+    final ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces;
+
+    private ComputedProperties(
+        ImmutableClassToInstanceMap<PipelineOptions> interfaceToProxyCache,
+        ImmutableMap<String, String> gettersToPropertyNames,
+        ImmutableMap<String, String> settersToPropertyNames,
+        ImmutableSet<Class<? extends PipelineOptions>> knownInterfaces) {
+      this.interfaceToProxyCache = interfaceToProxyCache;
+      this.gettersToPropertyNames = gettersToPropertyNames;
+      this.settersToPropertyNames = settersToPropertyNames;
+      this.knownInterfaces = knownInterfaces;
+    }
+
+    <T extends PipelineOptions> ComputedProperties updated(
+        Class<T> iface, T instance, List<PropertyDescriptor> propertyDescriptors) {
+
+      // these all use mutable maps and then copyOf, rather than a builder because builders enforce
+      // all keys are unique, and its possible they are not here.
+      Map<String, String> allNewGetters = Maps.newHashMap(gettersToPropertyNames);
+      Map<String, String> allNewSetters = Maps.newHashMap(settersToPropertyNames);
+      Set<Class<? extends PipelineOptions>> newKnownInterfaces = Sets.newHashSet(knownInterfaces);
+      Map<Class<? extends PipelineOptions>, PipelineOptions> newInterfaceCache =
+          Maps.newHashMap(interfaceToProxyCache);
+
+      allNewGetters.putAll(generateGettersToPropertyNames(propertyDescriptors));
+      allNewSetters.putAll(generateSettersToPropertyNames(propertyDescriptors));
+      newKnownInterfaces.add(iface);
+      newInterfaceCache.put(iface, instance);
+
+      return new ComputedProperties(
+          ImmutableClassToInstanceMap.copyOf(newInterfaceCache),
+          ImmutableMap.copyOf(allNewGetters),
+          ImmutableMap.copyOf(allNewSetters),
+          ImmutableSet.copyOf(newKnownInterfaces));
+    }
+  }
 
-  // ProxyInvocationHandler implements Serializable only for the sake of throwing an informative
-  // exception in writeObject()
   @SuppressFBWarnings("SE_BAD_FIELD")
-  private final ClassToInstanceMap<PipelineOptions> interfaceToProxyCache;
+  private volatile ComputedProperties computedProperties;
 
   // ProxyInvocationHandler implements Serializable only for the sake of throwing an informative
   // exception in writeObject()
   @SuppressFBWarnings("SE_BAD_FIELD")
-  private final Map<String, BoundValue> options;
+  private final ConcurrentHashMap<String, BoundValue> options;

Review Comment:
   ```suggestion
     /**
       * Enumerating {@code options} must always be done on a copy made before accessing or deriving properties from {@code computedProperties} since concurrent hash maps are <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/package-summary.html#Weakly>weakly consistent</a>. This will allow us to ensure that the keys in {code options} will always be a subset of properties stored in {code computedProperties}. 
       */
     private final ConcurrentHashMap<String, BoundValue> options;
   ```



##########
sdks/java/core/src/main/java/org/apache/beam/sdk/options/ProxyInvocationHandler.java:
##########
@@ -671,50 +726,50 @@ private void serializeEntry(
     public void serialize(PipelineOptions value, JsonGenerator jgen, SerializerProvider provider)
         throws IOException {
       ProxyInvocationHandler handler = (ProxyInvocationHandler) Proxy.getInvocationHandler(value);
-      synchronized (handler) {
-        PipelineOptionsFactory.Cache cache = PipelineOptionsFactory.CACHE.get();
-        // We first filter out any properties that have been modified since
-        // the last serialization of this PipelineOptions and then verify that
-        // they are all serializable.
-        Map<String, BoundValue> filteredOptions = Maps.newHashMap(handler.options);
-        Map<String, JsonSerializer<Object>> propertyToSerializer =
-            getSerializerMap(cache, handler.knownInterfaces);
-        removeIgnoredOptions(cache, handler.knownInterfaces, filteredOptions);
-        ensureSerializable(cache, handler.knownInterfaces, filteredOptions, propertyToSerializer);
-
-        // Now we create the map of serializable options by taking the original
-        // set of serialized options (if any) and updating them with any properties
-        // instances that have been modified since the previous serialization.
-        Map<String, Object> serializableOptions = Maps.newHashMap(handler.jsonOptions);
-        for (Map.Entry<String, BoundValue> entry : filteredOptions.entrySet()) {
-          serializableOptions.put(entry.getKey(), entry.getValue().getValue());
-        }
+      PipelineOptionsFactory.Cache cache = PipelineOptionsFactory.CACHE.get();
+      // We first filter out any properties that have been modified since
+      // the last serialization of this PipelineOptions and then verify that
+      // they are all serializable.

Review Comment:
   ```suggestion
         // We first copy and then filter out any properties that have been modified since
         // the last serialization of this PipelineOptions and then verify that
         // they are all serializable.
   ```



-- 
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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1175263084

   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 #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
lukecwik commented on code in PR #22162:
URL: https://github.com/apache/beam/pull/22162#discussion_r916070060


##########
sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java:
##########
@@ -1246,4 +1263,112 @@ public void testGetOptionNameFromMethod() throws NoSuchMethodException {
     handler.as(BaseOptions.class);
     assertEquals("foo", handler.getOptionName(BaseOptions.class.getMethod("getFoo")));
   }
+
+  private DynamicType.Unloaded<? extends PipelineOptions> spinNewInterface(int methodNumber) {
+    return new ByteBuddy()
+        .makeInterface(PipelineOptions.class)
+        .defineMethod("getDynamicMethod" + methodNumber, String.class, Visibility.PUBLIC)
+        .withoutCode()
+        .defineMethod("setDynamicMethod" + methodNumber, Void.TYPE, Visibility.PUBLIC)
+        .withParameters(String.class)
+        .withoutCode()
+        .make();
+  }
+
+  private Map<Integer, Class<? extends PipelineOptions>> loadAllInterfaces(
+      int numInterfaces, ClassLoader classLoader) {
+    List<DynamicType.Unloaded<? extends PipelineOptions>> dynamicInterfaces =
+        IntStream.range(0, numInterfaces)
+            .mapToObj(this::spinNewInterface)
+            .collect(Collectors.toList());
+
+    DynamicType.Loaded<Object> root =
+        new ByteBuddy().subclass(Object.class).make().include(dynamicInterfaces).load(classLoader);
+
+    Map<TypeDescription, Class<?>> loadedInterfaces = root.getLoadedAuxiliaryTypes();
+    Map<Integer, Class<? extends PipelineOptions>> result = Maps.newHashMap();
+
+    IntStream.range(0, numInterfaces)
+        .forEach(
+            i -> {
+              DynamicType.Unloaded<? extends PipelineOptions> iface = dynamicInterfaces.get(i);
+              Class<?> clazz = loadedInterfaces.get(iface.getTypeDescription());
+              result.put(i, (Class<? extends PipelineOptions>) clazz);
+            });
+
+    return result;
+  }
+
+  @Test
+  public void testConcurrency() throws Exception {
+    int numInterfaces = 100;
+    int numWorkers = 10;
+    int numReaders = 10;
+    int step = numInterfaces / numWorkers;
+
+    ProxyInvocationHandler handler = new ProxyInvocationHandler(Maps.newHashMap());
+    ClassLoader cl = Thread.currentThread().getContextClassLoader();
+    Map<Integer, Class<? extends PipelineOptions>> ifaces = loadAllInterfaces(numInterfaces, cl);
+    CountDownLatch startWaiter = new CountDownLatch(1);
+    CountDownLatch done = new CountDownLatch(numWorkers);
+
+    ExecutorService executor = Executors.newFixedThreadPool(numWorkers + numReaders);
+    List<Future<?>> futs = Lists.newArrayList();
+
+    // launch a `numWorkers` concurrent "writers" that will try to cast the proxy handler to various
+    // interfaces and set a value on them.
+    for (int start = 0; start < numInterfaces; start += step) {
+      final int s = start;
+      final int end = start + step;
+      Callable<Void> worker =
+          () -> {
+            startWaiter.await();
+            for (int i = s; i < end; i++) {
+              Class<? extends PipelineOptions> iface = ifaces.get(i);
+              Method setter = iface.getDeclaredMethod("setDynamicMethod" + i, String.class);
+              PipelineOptions opt1 = handler.as(iface);
+              setter.invoke(opt1, "test-" + i);
+            }
+            done.countDown();
+            return null;
+          };
+      futs.add(executor.submit(worker));
+    }
+
+    // launch concurrent readers that call `toString` and serializes the options, making sure they
+    // don't fail.
+    for (int i = 0; i < 10; i++) {
+      Callable<Void> worker =
+          () -> {
+            while (true) {
+              if (done.await(0, TimeUnit.MILLISECONDS)) {

Review Comment:
   ```suggestion
                 if (done.getCount() == 0) {
   ```



##########
sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java:
##########
@@ -1246,4 +1263,116 @@ public void testGetOptionNameFromMethod() throws NoSuchMethodException {
     handler.as(BaseOptions.class);
     assertEquals("foo", handler.getOptionName(BaseOptions.class.getMethod("getFoo")));
   }
+
+  private DynamicType.Unloaded<? extends PipelineOptions> spinNewInterface(int methodNumber) {
+    return new ByteBuddy()
+        .makeInterface(PipelineOptions.class)
+        .defineMethod("getDynamicMethod" + methodNumber, String.class, Visibility.PUBLIC)
+        .withoutCode()
+        .defineMethod("setDynamicMethod" + methodNumber, Void.TYPE, Visibility.PUBLIC)
+        .withParameters(String.class)
+        .withoutCode()
+        .make();
+  }
+
+  private Map<Integer, Class<? extends PipelineOptions>> loadAllInterfaces(
+      int numInterfaces, ClassLoader classLoader) {
+    List<DynamicType.Unloaded<? extends PipelineOptions>> dynamicInterfaces =
+        IntStream.range(0, numInterfaces)
+            .mapToObj(this::spinNewInterface)
+            .collect(Collectors.toList());
+
+    DynamicType.Loaded<Object> root =
+        new ByteBuddy().subclass(Object.class).make().include(dynamicInterfaces).load(classLoader);
+
+    Map<TypeDescription, Class<?>> loadedInterfaces = root.getLoadedAuxiliaryTypes();
+    Map<Integer, Class<? extends PipelineOptions>> result = Maps.newHashMap();
+
+    IntStream.range(0, numInterfaces)
+        .forEach(
+            i -> {
+              DynamicType.Unloaded<? extends PipelineOptions> iface = dynamicInterfaces.get(i);
+              Class<?> clazz = loadedInterfaces.get(iface.getTypeDescription());
+              result.put(i, (Class<? extends PipelineOptions>) clazz);
+            });
+
+    return result;
+  }
+
+  @Test
+  public void testConcurrency() throws Exception {
+    int numInterfaces = 100;
+    int numWorkers = 10;
+    int numReaders = 10;
+    int step = numInterfaces / numWorkers;
+
+    ProxyInvocationHandler handler = new ProxyInvocationHandler(Maps.newHashMap());
+    ClassLoader cl = Thread.currentThread().getContextClassLoader();
+    Map<Integer, Class<? extends PipelineOptions>> ifaces = loadAllInterfaces(numInterfaces, cl);
+    CountDownLatch startWaiter = new CountDownLatch(1);
+    CountDownLatch done = new CountDownLatch(numWorkers);
+
+    ExecutorService executor = Executors.newFixedThreadPool(numWorkers + numReaders);
+    List<Future<?>> futs = Lists.newArrayList();
+
+    // launch a `numWorkers` concurrent "writers" that will try to cast the proxy handler to various

Review Comment:
   ```suggestion
       // launch `numWorkers` concurrent "writers" that will try to cast the proxy handler to various
   ```



##########
sdks/java/core/src/test/java/org/apache/beam/sdk/options/ProxyInvocationHandlerTest.java:
##########
@@ -1246,4 +1263,112 @@ public void testGetOptionNameFromMethod() throws NoSuchMethodException {
     handler.as(BaseOptions.class);
     assertEquals("foo", handler.getOptionName(BaseOptions.class.getMethod("getFoo")));
   }
+
+  private DynamicType.Unloaded<? extends PipelineOptions> spinNewInterface(int methodNumber) {
+    return new ByteBuddy()
+        .makeInterface(PipelineOptions.class)
+        .defineMethod("getDynamicMethod" + methodNumber, String.class, Visibility.PUBLIC)
+        .withoutCode()
+        .defineMethod("setDynamicMethod" + methodNumber, Void.TYPE, Visibility.PUBLIC)
+        .withParameters(String.class)
+        .withoutCode()
+        .make();
+  }
+
+  private Map<Integer, Class<? extends PipelineOptions>> loadAllInterfaces(
+      int numInterfaces, ClassLoader classLoader) {
+    List<DynamicType.Unloaded<? extends PipelineOptions>> dynamicInterfaces =
+        IntStream.range(0, numInterfaces)
+            .mapToObj(this::spinNewInterface)
+            .collect(Collectors.toList());
+
+    DynamicType.Loaded<Object> root =
+        new ByteBuddy().subclass(Object.class).make().include(dynamicInterfaces).load(classLoader);
+
+    Map<TypeDescription, Class<?>> loadedInterfaces = root.getLoadedAuxiliaryTypes();
+    Map<Integer, Class<? extends PipelineOptions>> result = Maps.newHashMap();
+
+    IntStream.range(0, numInterfaces)
+        .forEach(
+            i -> {
+              DynamicType.Unloaded<? extends PipelineOptions> iface = dynamicInterfaces.get(i);
+              Class<?> clazz = loadedInterfaces.get(iface.getTypeDescription());
+              result.put(i, (Class<? extends PipelineOptions>) clazz);
+            });
+
+    return result;
+  }
+
+  @Test
+  public void testConcurrency() throws Exception {
+    int numInterfaces = 100;
+    int numWorkers = 10;
+    int numReaders = 10;
+    int step = numInterfaces / numWorkers;
+
+    ProxyInvocationHandler handler = new ProxyInvocationHandler(Maps.newHashMap());
+    ClassLoader cl = Thread.currentThread().getContextClassLoader();
+    Map<Integer, Class<? extends PipelineOptions>> ifaces = loadAllInterfaces(numInterfaces, cl);
+    CountDownLatch startWaiter = new CountDownLatch(1);
+    CountDownLatch done = new CountDownLatch(numWorkers);
+
+    ExecutorService executor = Executors.newFixedThreadPool(numWorkers + numReaders);
+    List<Future<?>> futs = Lists.newArrayList();
+
+    // launch a `numWorkers` concurrent "writers" that will try to cast the proxy handler to various
+    // interfaces and set a value on them.
+    for (int start = 0; start < numInterfaces; start += step) {
+      final int s = start;
+      final int end = start + step;
+      Callable<Void> worker =
+          () -> {
+            startWaiter.await();
+            for (int i = s; i < end; i++) {
+              Class<? extends PipelineOptions> iface = ifaces.get(i);
+              Method setter = iface.getDeclaredMethod("setDynamicMethod" + i, String.class);
+              PipelineOptions opt1 = handler.as(iface);
+              setter.invoke(opt1, "test-" + i);
+            }
+            done.countDown();
+            return null;
+          };
+      futs.add(executor.submit(worker));
+    }
+
+    // launch concurrent readers that call `toString` and serializes the options, making sure they
+    // don't fail.
+    for (int i = 0; i < 10; i++) {
+      Callable<Void> worker =
+          () -> {
+            while (true) {
+              if (done.await(0, TimeUnit.MILLISECONDS)) {
+                return null;
+              }
+              assertNotNull(handler.toString());
+              PipelineOptionsFactory.MAPPER.writeValue(
+                  ByteStreams.nullOutputStream(), handler.as(PipelineOptions.class));
+            }
+          };
+      futs.add(executor.submit(worker));
+    }
+
+    // wait for everything to finish
+    startWaiter.countDown();
+    done.await();

Review Comment:
   ```suggestion
   ```
   
   Blocking on the futures makes this redundant.



-- 
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] steveniemitz commented on pull request #22162: Optimize locking in several critical-path methods

Posted by GitBox <gi...@apache.org>.
steveniemitz commented on PR #22162:
URL: https://github.com/apache/beam/pull/22162#issuecomment-1175362411

   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