You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avro.apache.org by GitBox <gi...@apache.org> on 2022/03/19 22:40:28 UTC

[GitHub] [avro] jklamer opened a new pull request #1608: [AVRO-3451] Reuse Resolved Schemas

jklamer opened a new pull request #1608:
URL: https://github.com/apache/avro/pull/1608


   A reuse of the resolved schema struct to help improve performance when possible. Currently every write/append into a writer would use the same schema and resolve it to index all the named schemas for every object being written. Because a writer has a consistent schema it is trivial to reuse the same resolved schema for every write. This improvement was brought up in collaboration with @travisbrown 
   
   What made the implementation less straightforward were the following design constraints:
   - absolutely no API breaking changes
   - Want to keep Resolved Schema crate private for simplicity
   
   As a result there is some complexity to how the resolved schema is initialized within the writer but I believe it is handled.
   
   ### Benchmark results:
   Using the example/benchmark.rs to get a csv output. I ran data for pre 1602 code (which the JIRA is based on) and on the latest commit of this branch. This is run on a 2016 macbook pro. I ran multiple times to confirm that the results were consistent and chose the last run for comparisons. 
   
   #### Pre 1602
   | count |  runs  |  big_or_small |  total_write_secs | 
   |-------|--------|---------------|-------------------| 
   | 10000 | 1      | Small         | 0.080105792       | 
   | 10000 | 1      | Big           | 0.363642778       | 
   | 1     | 100000 | Small         | 5.450658665       | 
   | 100   | 1000   | Small         | 0.844267501       | 
   | 10000 | 10     | Small         | 0.799961709       | 
   | 1     | 100000 | Big           | 13.395100232      | 
   | 100   | 1000   | Big           | 4.254442101       | 
   | 10000 | 10     | Big           | 3.755155395       | 
   
   #### This branch 
   | count |  runs  |  big_or_small |  total_write_secs | 
   |-------|--------|---------------|-------------------| 
   | 10000 | 1      | Small         | 0.019134068       | 
   | 10000 | 1      | Big           | 0.089809544       | 
   | 1     | 100000 | Small         | 4.449467382       | 
   | 100   | 1000   | Small         | 0.307506175       | 
   | 10000 | 10     | Small         | 0.190783385       | 
   | 1     | 100000 | Big           | 11.514703263      | 
   | 100   | 1000   | Big           | 0.931118263       | 
   | 10000 | 10     | Big           | 1.042874368       | 
   
   #### Percent change (initial - final) / initial 
   | count |  runs  |  big_or_small | % reduction | 
   |-------|--------|---------------|-------------| 
   | 10000 | 1      | Small         | 0.761140018 | 
   | 10000 | 1      | Big           | 0.753028110 | 
   | 1     | 100000 | Small         | 0.183682623 | 
   | 100   | 1000   | Small         | 0.635771631 | 
   | 10000 | 10     | Small         | 0.761509354 | 
   | 1     | 100000 | Big           | 0.140379462 | 
   | 100   | 1000   | Big           | 0.781142100 | 
   | 10000 | 10     | Big           | 0.722281968 | 
   
   This is consistent with whats expected as we get the least performance improvements when the writer is constantly being remade. The 14/18 improvement, is a result of changes in #1602 that seem to have a highly variable performance impact  depending on schema. 
   
   ### Jira
   
   - [ ] My PR addresses the following [Avro Jira](https://issues.apache.org/jira/browse/AVRO-3451) 
   
   ### Tests
   
   My Pr does not add tests because it does not add functionality. All tests pass as before. 
   
   ### Documentation
   
   No new user facing changes
   


-- 
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: dev-unsubscribe@avro.apache.org

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



[GitHub] [avro] martin-g commented on pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
martin-g commented on pull request #1608:
URL: https://github.com/apache/avro/pull/1608#issuecomment-1073316938


   Here are the results from the benchmark on my laptop:
   
   `master` branch: 
   ```
   10000,1,Small,0.039890636,0.042860779
   10000,1,Big,0.099197248,0.103504636
   1,100000,Small,4.622638324,20.889562055
   100,1000,Small,0.52317468,0.731093513
   10000,10,Small,0.530728866,0.633507069
   1,100000,Big,10.907742395,71.910063022
   100,1000,Big,1.151314511,2.06744156
   10000,10,Big,1.172123896,1.171496815
   ```
   
   This PR:
   ```
   10000,1,Small,0.011186142,0.043883047
   10000,1,Big,0.056111559,0.114635545
   1,100000,Small,4.730861091,21.375156375
   100,1000,Small,0.170062576,0.701255961
   10000,10,Small,0.116927097,0.453378823
   1,100000,Big,10.054628933,69.582575465
   100,1000,Big,0.651133748,2.037338469
   10000,10,Big,0.702202783,1.152962118
   ```


-- 
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: issues-unsubscribe@avro.apache.org

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



[GitHub] [avro] travisbrown commented on pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
travisbrown commented on pull request #1608:
URL: https://github.com/apache/avro/pull/1608#issuecomment-1073237134


   Thanks again for making this happen! I haven't had a chance to look closely, but I have tried this branch in one of my Rust projects, and it seems to work perfectly (including processing Rust-generated Avro files externally from the JVM tools).


-- 
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: issues-unsubscribe@avro.apache.org

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



[GitHub] [avro] martin-g merged pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
martin-g merged pull request #1608:
URL: https://github.com/apache/avro/pull/1608


   


-- 
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: dev-unsubscribe@avro.apache.org

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



[GitHub] [avro] jklamer commented on a change in pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
jklamer commented on a change in pull request #1608:
URL: https://github.com/apache/avro/pull/1608#discussion_r830665175



##########
File path: lang/rust/avro/src/writer.rs
##########
@@ -109,15 +111,27 @@ impl<'a, W: Write> Writer<'a, W> {
     pub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize> {
         let n = self.maybe_write_header()?;
 
-        write_value_ref(self.schema, value, &mut self.buffer)?;
+        // Lazy init for users using the builder pattern with error throwing
+        match self.resolved_schema {
+            Some(ref rs) => {
+                write_value_ref_resolved(rs, value, &mut self.buffer)?;
+                self.num_values += 1;
 
-        self.num_values += 1;
+                if self.buffer.len() >= self.block_size {
+                    return self.flush().map(|b| b + n);
+                }
 
-        if self.buffer.len() >= self.block_size {
-            return self.flush().map(|b| b + n);
+                Ok(n)
+            }
+            None => {
+                if !self.attempted_resolve {

Review comment:
       Oh right, this check does nothing based on the design I ended with 😅 . I was trying to differentiate between builder built writers and constructor built writers. Thank you!




-- 
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: issues-unsubscribe@avro.apache.org

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



[GitHub] [avro] martin-g commented on pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
martin-g commented on pull request #1608:
URL: https://github.com/apache/avro/pull/1608#issuecomment-1073339991


   Thank you, @jklamer !


-- 
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: issues-unsubscribe@avro.apache.org

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



[GitHub] [avro] martin-g commented on a change in pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
martin-g commented on a change in pull request #1608:
URL: https://github.com/apache/avro/pull/1608#discussion_r830662218



##########
File path: lang/rust/avro/src/writer.rs
##########
@@ -109,15 +111,27 @@ impl<'a, W: Write> Writer<'a, W> {
     pub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize> {
         let n = self.maybe_write_header()?;
 
-        write_value_ref(self.schema, value, &mut self.buffer)?;
+        // Lazy init for users using the builder pattern with error throwing
+        match self.resolved_schema {
+            Some(ref rs) => {
+                write_value_ref_resolved(rs, value, &mut self.buffer)?;
+                self.num_values += 1;
 
-        self.num_values += 1;
+                if self.buffer.len() >= self.block_size {
+                    return self.flush().map(|b| b + n);
+                }
 
-        if self.buffer.len() >= self.block_size {
-            return self.flush().map(|b| b + n);
+                Ok(n)
+            }
+            None => {
+                if !self.attempted_resolve {

Review comment:
       Is it possible the value to be already `true` ?
   Maybe we can remove the `if` ?!




-- 
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: issues-unsubscribe@avro.apache.org

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



[GitHub] [avro] jklamer commented on a change in pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
jklamer commented on a change in pull request #1608:
URL: https://github.com/apache/avro/pull/1608#discussion_r830665396



##########
File path: lang/rust/avro/src/writer.rs
##########
@@ -109,15 +111,27 @@ impl<'a, W: Write> Writer<'a, W> {
     pub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize> {
         let n = self.maybe_write_header()?;
 
-        write_value_ref(self.schema, value, &mut self.buffer)?;
+        // Lazy init for users using the builder pattern with error throwing
+        match self.resolved_schema {
+            Some(ref rs) => {
+                write_value_ref_resolved(rs, value, &mut self.buffer)?;
+                self.num_values += 1;
 
-        self.num_values += 1;
+                if self.buffer.len() >= self.block_size {
+                    return self.flush().map(|b| b + n);
+                }
 
-        if self.buffer.len() >= self.block_size {
-            return self.flush().map(|b| b + n);
+                Ok(n)
+            }
+            None => {
+                if !self.attempted_resolve {

Review comment:
       I believe we should be able to remove the bool all together




-- 
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: issues-unsubscribe@avro.apache.org

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



[GitHub] [avro] martin-g commented on a change in pull request #1608: AVRO-3451: Reuse Resolved Schemas

Posted by GitBox <gi...@apache.org>.
martin-g commented on a change in pull request #1608:
URL: https://github.com/apache/avro/pull/1608#discussion_r830664802



##########
File path: lang/rust/avro/src/writer.rs
##########
@@ -109,15 +111,27 @@ impl<'a, W: Write> Writer<'a, W> {
     pub fn append_value_ref(&mut self, value: &Value) -> AvroResult<usize> {
         let n = self.maybe_write_header()?;
 
-        write_value_ref(self.schema, value, &mut self.buffer)?;
+        // Lazy init for users using the builder pattern with error throwing
+        match self.resolved_schema {
+            Some(ref rs) => {
+                write_value_ref_resolved(rs, value, &mut self.buffer)?;
+                self.num_values += 1;
 
-        self.num_values += 1;
+                if self.buffer.len() >= self.block_size {
+                    return self.flush().map(|b| b + n);
+                }
 
-        if self.buffer.len() >= self.block_size {
-            return self.flush().map(|b| b + n);
+                Ok(n)
+            }
+            None => {
+                if !self.attempted_resolve {

Review comment:
       I've removed the check.




-- 
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: issues-unsubscribe@avro.apache.org

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