You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "wollowizard (via GitHub)" <gi...@apache.org> on 2025/05/06 21:19:58 UTC

[PR] 34749 added cache for avro coder to reduce memory footprint [beam]

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

   This addresses issue https://github.com/apache/beam/issues/34749.
   See also PR https://github.com/apache/beam/pull/34750 for more details


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2079855377


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -840,4 +843,38 @@ public boolean equals(@Nullable Object other) {
   public int hashCode() {
     return Objects.hash(getClass(), typeDescriptor, datumFactory, schemaSupplier.get());
   }
+
+  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

Review Comment:
   I know that for DoFn objects we deserialize them multiple times and cache them since they are single-threaded and we run in multiple threads in parallel.  However I'm not sure if Coders are deserialized similarly.  Since they are thread-safe it seems they could be deserialized once and shared.
   @kennknowles Do you know how coders are represented and deserialized off the top of your head? Should we worry about multiple copies  not sharing state or is that unexpected? Are coders represented with some set of coders for the pipeline or could the same coder perhaps be serialized multiple times in the graph?
   
   One benefit of the writeReplace and readResolve idea is that the same AvroCoder instance would be used from multiple deserializations so the thread-local encode/decode buffers it contains would be shared, not just the reader and writer. But we could do that as a follow up.
   
   Were you able to test this to verify it was working as expected?



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "wollowizard (via GitHub)" <gi...@apache.org>.
wollowizard commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2077484721


##########
sdks/java/extensions/avro/src/test/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoderTest.java:
##########
@@ -416,6 +417,40 @@ public void testReflectRecordEncoding() throws Exception {
     CoderProperties.coderDecodeEncodeEqual(coderWithSchema, AVRO_SPECIFIC_RECORD);
   }
 
+  @Test
+  public void testCoderCached() {
+    Schema schema = AVRO_SPECIFIC_RECORD.getSchema();
+    TypeDescriptor<TestAvro> typeDescriptor = TypeDescriptor.of(TestAvro.class);
+    Class<TestAvro> clazz = TestAvro.class;
+    boolean useReflectApi = false;
+    AvroDatumFactory<TestAvro> datumFactory = new AvroDatumFactory.ReflectDatumFactory<>(clazz);
+
+    assertSame(AvroCoder.of(clazz), AvroCoder.of(clazz));
+    assertSame(AvroCoder.of(clazz, useReflectApi), AvroCoder.of(clazz, useReflectApi));
+    assertSame(AvroCoder.of(typeDescriptor), AvroCoder.of(typeDescriptor));
+    assertSame(
+        AvroCoder.of(typeDescriptor, useReflectApi), AvroCoder.of(typeDescriptor, useReflectApi));
+    assertSame(AvroCoder.of(clazz, schema), AvroCoder.of(clazz, schema));
+    assertSame(
+        AvroCoder.of(clazz, schema, useReflectApi), AvroCoder.of(clazz, schema, useReflectApi));
+    assertSame(AvroCoder.of(datumFactory, schema), AvroCoder.of(datumFactory, schema));
+
+    assertSame(AvroCoder.specific(clazz), AvroCoder.specific(clazz));

Review Comment:
   done see last check in this test



##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroGenericCoder.java:
##########
@@ -17,17 +17,27 @@
  */
 package org.apache.beam.sdk.extensions.avro.coders;
 
+import java.util.concurrent.ExecutionException;
 import org.apache.avro.Schema;
 import org.apache.avro.generic.GenericRecord;
 import org.apache.beam.sdk.extensions.avro.io.AvroDatumFactory;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.Cache;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.CacheBuilder;
 
 /** AvroCoder specialisation for GenericRecord, needed for cross-language transforms. */
 public class AvroGenericCoder extends AvroCoder<GenericRecord> {
+  private static final Cache<Schema, AvroGenericCoder> AVRO_GENERIC_CODER_CACHE =
+      CacheBuilder.newBuilder().build();

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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle merged PR #34873:
URL: https://github.com/apache/beam/pull/34873


-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "wollowizard (via GitHub)" <gi...@apache.org>.
wollowizard commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2081239744


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -840,4 +843,38 @@ public boolean equals(@Nullable Object other) {
   public int hashCode() {
     return Objects.hash(getClass(), typeDescriptor, datumFactory, schemaSupplier.get());
   }
+
+  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

Review Comment:
   @scwhittle yes I could test it with realistic data, and it works as expected.
   
   **AvroDatumFactory**
   before: 32%
   after: 0.036%
   
   **AvroCoder**
   before: 69%
   after: 11%
   
   
   As we thought, this improves not only user code, but also sdk performance.
   Example taken from another pipeline:
   **org.apache.beam.runners.dataflow.worker.StreamingModeExecutionContext.flushState()**
   before: 43%
   after: 10%
   
   
   **Before**
   
   <img width="600" alt="image" src="https://github.com/user-attachments/assets/b121e360-79c9-4fbd-b9d9-079ed9ad50c3" />
   <img width="600" alt="image" src="https://github.com/user-attachments/assets/3a0e3651-c5f3-4d0b-a2ef-87ec61733bfe" />
   <img width="600" alt="image" src="https://github.com/user-attachments/assets/6173ea0e-a9b6-4a23-9653-d62df14ef61e" />
   
   
   
   
   
   **After**
   
   <img width="600" alt="image" src="https://github.com/user-attachments/assets/a33c71f6-af23-481e-a721-5fb272161e67" />
   <img width="600" alt="image" src="https://github.com/user-attachments/assets/31ee28a8-637c-4bd6-a95e-7eca0b19040b" />
   <img width="600" alt="image" src="https://github.com/user-attachments/assets/ae1516dc-d23a-4857-ae09-e2c28e4977a0" />
   
   
   



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on PR #34873:
URL: https://github.com/apache/beam/pull/34873#issuecomment-2866658738

   The test failures look unrelated I will retrigger just to be safe though


-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "wollowizard (via GitHub)" <gi...@apache.org>.
wollowizard commented on PR #34873:
URL: https://github.com/apache/beam/pull/34873#issuecomment-2856025987

   @scwhittle this is a follow up to our discussion in https://github.com/apache/beam/issues/34749 and https://github.com/apache/beam/pull/34750. I would like to run a test with real data in the dataflow runner, is there a way to get a snapshot build for this PR, so that I? 


-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "wollowizard (via GitHub)" <gi...@apache.org>.
wollowizard commented on PR #34873:
URL: https://github.com/apache/beam/pull/34873#issuecomment-2856021830

   assign set of reviewers


-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on PR #34873:
URL: https://github.com/apache/beam/pull/34873#issuecomment-2866659189

   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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2077109138


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -840,4 +843,38 @@ public boolean equals(@Nullable Object other) {
   public int hashCode() {
     return Objects.hash(getClass(), typeDescriptor, datumFactory, schemaSupplier.get());
   }
+
+  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

Review Comment:
   Actually I think that this could still lead to duplicate reader/writers if we deserialize the same logical coder multiple times.
   
   I think that could be fixed by using readResolve which allows modifying the deserialized object (just learning about this myself). https://docs.oracle.com/javase/8/docs/platform/serialization/spec/input.html#a5903
   
   One idea that seems clean is to change to serialize the cache key for AvroCoder using writeReplace and then use readResolve of that key to lookup/create the coder in the cache based upon that key.  There is an example in this file of that with SerializableSchemaString.
   



##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -242,7 +252,18 @@ public static <T> AvroCoder<T> of(Class<T> type, Schema schema) {
    * @param <T> the element type
    */
   public static <T> AvroCoder<T> of(AvroDatumFactory<T> datumFactory, Schema schema) {
-    return new AvroCoder<>(datumFactory, schema);
+    Class<T> type = datumFactory.getType();
+    return fromCacheOrCreate(type, schema, () -> new AvroCoder<>(datumFactory, schema));
+  }
+
+  private static <T> AvroCoder<T> fromCacheOrCreate(
+      Class<T> type, Schema schema, Callable<AvroCoder<T>> avroCoderCreator) {

Review Comment:
   it might be safer to have this take a type ENUM as well (specific, reflect). Otherwise AvroCoder.specific() factory could return something previously cached via AvroCoder.reflect() and vice versa.
   
   That might not be expected usage but seems like we might as well guard against that since it woudl be pretty confusing.



##########
sdks/java/extensions/avro/src/test/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoderTest.java:
##########
@@ -416,6 +417,40 @@ public void testReflectRecordEncoding() throws Exception {
     CoderProperties.coderDecodeEncodeEqual(coderWithSchema, AVRO_SPECIFIC_RECORD);
   }
 
+  @Test
+  public void testCoderCached() {
+    Schema schema = AVRO_SPECIFIC_RECORD.getSchema();
+    TypeDescriptor<TestAvro> typeDescriptor = TypeDescriptor.of(TestAvro.class);
+    Class<TestAvro> clazz = TestAvro.class;
+    boolean useReflectApi = false;
+    AvroDatumFactory<TestAvro> datumFactory = new AvroDatumFactory.ReflectDatumFactory<>(clazz);
+
+    assertSame(AvroCoder.of(clazz), AvroCoder.of(clazz));
+    assertSame(AvroCoder.of(clazz, useReflectApi), AvroCoder.of(clazz, useReflectApi));
+    assertSame(AvroCoder.of(typeDescriptor), AvroCoder.of(typeDescriptor));
+    assertSame(
+        AvroCoder.of(typeDescriptor, useReflectApi), AvroCoder.of(typeDescriptor, useReflectApi));
+    assertSame(AvroCoder.of(clazz, schema), AvroCoder.of(clazz, schema));
+    assertSame(
+        AvroCoder.of(clazz, schema, useReflectApi), AvroCoder.of(clazz, schema, useReflectApi));
+    assertSame(AvroCoder.of(datumFactory, schema), AvroCoder.of(datumFactory, schema));
+
+    assertSame(AvroCoder.specific(clazz), AvroCoder.specific(clazz));

Review Comment:
   assert that AvroCoder.specific(clazz) is different than AvroCoder.reflect(clazz)



##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroGenericCoder.java:
##########
@@ -17,17 +17,27 @@
  */
 package org.apache.beam.sdk.extensions.avro.coders;
 
+import java.util.concurrent.ExecutionException;
 import org.apache.avro.Schema;
 import org.apache.avro.generic.GenericRecord;
 import org.apache.beam.sdk.extensions.avro.io.AvroDatumFactory;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.Cache;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.CacheBuilder;
 
 /** AvroCoder specialisation for GenericRecord, needed for cross-language transforms. */
 public class AvroGenericCoder extends AvroCoder<GenericRecord> {
+  private static final Cache<Schema, AvroGenericCoder> AVRO_GENERIC_CODER_CACHE =
+      CacheBuilder.newBuilder().build();

Review Comment:
   use the weakValues option?  I'm not sure if there are cases where schemas are created dynamically and this cache could grow unbounded.



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2081292585


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -840,4 +843,38 @@ public boolean equals(@Nullable Object other) {
   public int hashCode() {
     return Objects.hash(getClass(), typeDescriptor, datumFactory, schemaSupplier.get());
   }
+
+  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

Review Comment:
   This is great, thanks!



##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroGenericCoder.java:
##########
@@ -17,17 +17,27 @@
  */
 package org.apache.beam.sdk.extensions.avro.coders;
 
+import java.util.concurrent.ExecutionException;
 import org.apache.avro.Schema;
 import org.apache.avro.generic.GenericRecord;
 import org.apache.beam.sdk.extensions.avro.io.AvroDatumFactory;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.Cache;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.cache.CacheBuilder;
 
 /** AvroCoder specialisation for GenericRecord, needed for cross-language transforms. */
 public class AvroGenericCoder extends AvroCoder<GenericRecord> {
+  private static final Cache<Schema, AvroGenericCoder> AVRO_GENERIC_CODER_CACHE =
+      CacheBuilder.newBuilder().build();

Review Comment:
   actually this cache could still be weakValues



##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -354,8 +392,10 @@ public Schema get() {
   // an inner coder.
   private final EmptyOnDeserializationThreadLocal<BinaryDecoder> decoder;
   private final EmptyOnDeserializationThreadLocal<BinaryEncoder> encoder;
-  private final EmptyOnDeserializationThreadLocal<DatumWriter<T>> writer;

Review Comment:
   Sorry I didn't think of this earlier, but I realized that this is going to change the java serialization of this coder which will lead to update incompatability.
   
   Options:
   - keep the existing fields and the new transient fields and just don't use existing fields.
   - remove the new fields and change existing fields to do the cache lookup in the initialvalue method.  I think you could remove readObject then. We are using unnecessary per-thread caching still then.
   
   I think I'd lean towards the first option of keeping the existing fields but not using 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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #34873:
URL: https://github.com/apache/beam/pull/34873#issuecomment-2868566937

   Assigning reviewers:
   
   R: @kennknowles for label java.
   
   
   Note: If you would like to opt out of this review, comment `assign to next reviewer`.
   
   Available commands:
   - `stop reviewer notifications` - opt out of the automated review tooling
   - `remind me after tests pass` - tag the comment author after tests pass
   - `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
   
   The PR bot will only process comments in the main thread (not review comments).


-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2081742961


##########
sdks/java/extensions/avro/src/test/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoderTest.java:
##########
@@ -416,6 +419,88 @@ public void testReflectRecordEncoding() throws Exception {
     CoderProperties.coderDecodeEncodeEqual(coderWithSchema, AVRO_SPECIFIC_RECORD);
   }
 
+  @Test
+  public void testCoderCached() {
+    Schema schema = AVRO_SPECIFIC_RECORD.getSchema();
+    TypeDescriptor<TestAvro> typeDescriptor = TypeDescriptor.of(TestAvro.class);
+    Class<TestAvro> clazz = TestAvro.class;
+    boolean useReflectApi = false;

Review Comment:
   nit: how about 
   final boolean USE_REFLECT_API = true;
   
   I was a little confused about this at first thinking you meant to test with both true/false. But it's also odd to set this to false if the parameter is useReflectApi as it is then inverted.



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2084085775


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -354,8 +392,10 @@ public Schema get() {
   // an inner coder.
   private final EmptyOnDeserializationThreadLocal<BinaryDecoder> decoder;
   private final EmptyOnDeserializationThreadLocal<BinaryEncoder> encoder;
-  private final EmptyOnDeserializationThreadLocal<DatumWriter<T>> writer;

Review Comment:
   Yes, this is for compatability across updates in which the pipeline has been reserialized and may be before and after this change.
   
   There is an updateCompatabilityVersion option that can be used to guard uncompatible changes but seems simpler in this case to just leave the old unused fields.



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "wollowizard (via GitHub)" <gi...@apache.org>.
wollowizard commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2077483390


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -840,4 +843,38 @@ public boolean equals(@Nullable Object other) {
   public int hashCode() {
     return Objects.hash(getClass(), typeDescriptor, datumFactory, schemaSupplier.get());
   }
+
+  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

Review Comment:
   @scwhittle you were right when deserializing the same coder, we would get different readers/writers.
   I've fixed that in a way similar to the one you described, but maybe a bit simpler. I've added a test for that too.
   
   As curiosity, are coders serialized and deserialized often? my assumption was that they this happens when a new vm is started for example, or when checkpointing. or does it happen even more often so to have a performance impact?



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #34873:
URL: https://github.com/apache/beam/pull/34873#issuecomment-2858558590

   Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`


-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on PR #34873:
URL: https://github.com/apache/beam/pull/34873#issuecomment-2857731188

   > @scwhittle this is a follow up to our discussion in #34749 and #34750. I would like to run a test with real data in the dataflow runner, is there a way to get a snapshot build for this PR?
   
   I think that you should be able to run a pipeline with these changes by publishing the jars to your local maven and then configuring your pipeline to use them.
   
   # In the repo with this PR
   ./gradlew sdks:java:io:google-cloud-platform:compileJava \
   && ./gradlew -Ppublishing -p sdks/java/io/google-cloud-platform publishToMavenLocal
   # find local maven path
   mvn help:evaluate -Dexpression=settings.localRepository
   
   # In the project with your pipeline, modify pom.xml to use local repo
   <repositories>
       <repository>
         <id>example-repo</id>
         <name>Example Repository</name>
         <url>file:///complete/path/to/.m2/repository</url>
       </repository>
       ...
   </repositories>
   # Also modify the BEAM version in the pom.xml to match the version published above. ie (<beam.version>2.64.0</beam.version>) to the SNAPSHOT version (<beam.version>2.65.0-SNAPSHOT</beam.version>)
   
   Then if you launch the dataflow pipeline as normal from your pipeline it should pull in the locally published sdk changes. Let me know if that works or if you have problems with that


-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "wollowizard (via GitHub)" <gi...@apache.org>.
wollowizard commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2077483390


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -840,4 +843,38 @@ public boolean equals(@Nullable Object other) {
   public int hashCode() {
     return Objects.hash(getClass(), typeDescriptor, datumFactory, schemaSupplier.get());
   }
+
+  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {

Review Comment:
   @scwhittle you wer right when deserializing the same coder, we would get different readers/writers.
   I've fixed that in a way similar to the one you described, but maybe a bit simpler. I've added a test for that too.
   
   As curiosity, are coders serialized and deserialized often? my assumption was that they this happens when a new vm is started for example, or when checkpointing. or does it happen even more often so to have a performance impact?



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "wollowizard (via GitHub)" <gi...@apache.org>.
wollowizard commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2081480151


##########
sdks/java/extensions/avro/src/main/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoder.java:
##########
@@ -354,8 +392,10 @@ public Schema get() {
   // an inner coder.
   private final EmptyOnDeserializationThreadLocal<BinaryDecoder> decoder;
   private final EmptyOnDeserializationThreadLocal<BinaryEncoder> encoder;
-  private final EmptyOnDeserializationThreadLocal<DatumWriter<T>> writer;

Review Comment:
   @scwhittle i see, i guess this is to support [pipeline upgrades](https://cloud.google.com/dataflow/docs/guides/updating-a-pipeline)?
   anyway I restored the old fields 



-- 
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


Re: [PR] 34749 added cache for avro coder to reduce memory footprint [beam]

Posted by "scwhittle (via GitHub)" <gi...@apache.org>.
scwhittle commented on code in PR #34873:
URL: https://github.com/apache/beam/pull/34873#discussion_r2081742961


##########
sdks/java/extensions/avro/src/test/java/org/apache/beam/sdk/extensions/avro/coders/AvroCoderTest.java:
##########
@@ -416,6 +419,88 @@ public void testReflectRecordEncoding() throws Exception {
     CoderProperties.coderDecodeEncodeEqual(coderWithSchema, AVRO_SPECIFIC_RECORD);
   }
 
+  @Test
+  public void testCoderCached() {
+    Schema schema = AVRO_SPECIFIC_RECORD.getSchema();
+    TypeDescriptor<TestAvro> typeDescriptor = TypeDescriptor.of(TestAvro.class);
+    Class<TestAvro> clazz = TestAvro.class;
+    boolean useReflectApi = false;

Review Comment:
   nit: how about final boolean USE_REFLECT_API
   
   I was a little confused about this at first thinking you meant to test with setting this to true too.



-- 
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