scwhittle commented on a change in pull request #15983:
URL: https://github.com/apache/beam/pull/15983#discussion_r751086938



##########
File path: sdks/python/apache_beam/runners/worker/sdk_worker.py
##########
@@ -1151,10 +1151,21 @@ def extend(
         # When a corrupt value made it into the cache, we have to fail.
         raise Exception("Unexpected cached value: %s" % cached_value)
     # Write to state handler
+    futures = []
     out = coder_impl.create_OutputStream()
     for element in elements:
       coder.encode_to_stream(element, out, True)
-    return self._underlying.append_raw(state_key, out.get())
+      if out.size() > data_plane._DEFAULT_SIZE_FLUSH_THRESHOLD:

Review comment:
       This may overshoot the limit since it is encoding first.  Is there a 
cheap way to get the size of the encoded element to possibly flush before 
encoding to the stream? For dataflow (and perhaps other runners) there is a 
strict batch limit.  As written the largest safest element is that (strict 
limit - the flush threshold) instead of just the strict limit.

##########
File path: sdks/python/apache_beam/runners/worker/sdk_worker.py
##########
@@ -1151,10 +1151,21 @@ def extend(
         # When a corrupt value made it into the cache, we have to fail.
         raise Exception("Unexpected cached value: %s" % cached_value)
     # Write to state handler
+    futures = []
     out = coder_impl.create_OutputStream()
     for element in elements:
       coder.encode_to_stream(element, out, True)
-    return self._underlying.append_raw(state_key, out.get())
+      if out.size() > data_plane._DEFAULT_SIZE_FLUSH_THRESHOLD:
+        futures.append(self._underlying.append_raw(state_key, out.get()))
+        out = coder_impl.create_OutputStream()
+    if out.size():
+      futures.append(self._underlying.append_raw(state_key, out.get()))
+    return _DeferredCall(

Review comment:
       if there is a single future, is it worth returning it directly instead 
of the gather?




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to