Re: [PR] [Parquet] Add test to verify heap size calculation [arrow-rs]
alamb commented on code in PR #8925:
URL: https://github.com/apache/arrow-rs/pull/8925#discussion_r2607638895
##
parquet/tests/metadata_memory.rs:
##
@@ -0,0 +1,156 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Tests calculation of the Parquet metadata heap size
+
+use parquet::arrow::arrow_reader::{ArrowReaderMetadata, ArrowReaderOptions};
+use parquet::encryption::decrypt::FileDecryptionProperties;
+use parquet::file::metadata::PageIndexPolicy;
+use std::alloc::{GlobalAlloc, Layout, System};
+use std::fs::File;
+use std::hint::black_box;
+use std::sync::Arc;
+use std::sync::atomic::{AtomicUsize, Ordering};
+
+pub struct TrackingAllocator {
Review Comment:
this is a very cool 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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] [Parquet] Add test to verify heap size calculation [arrow-rs]
adamreeve commented on PR #8925: URL: https://github.com/apache/arrow-rs/pull/8925#issuecomment-3638905449 Huh, interesting. I think trying to get this to always match exactly and track down all the causes of differences is not worth the effort, and I should just add a small tolerance for all the test cases. -- 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]
Re: [PR] [Parquet] Add test to verify heap size calculation [arrow-rs]
alamb commented on PR #8925:
URL: https://github.com/apache/arrow-rs/pull/8925#issuecomment-3638254065
Interestingly, this PR fails on my mac:
```shell
test_metadata_heap_memory stdout
thread 'test_metadata_heap_memory' (15130761) panicked at
parquet/tests/metadata_memory.rs:138:9:
assertion `left == right` failed: Calculated heap size 10534 doesn't match
the allocated size 10526 for file
/Users/andrewlamb/Software/arrow-rs/arrow/../parquet-testing/data/encrypt_columns_plaintext_footer.parquet.encrypted
left: 10534
right: 10526
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
test_metadata_heap_memory
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered
out; finished in 0.01s
error: test failed, to rerun pass `-p parquet --test metadata_memory`
```
--
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]
Re: [PR] [Parquet] Add test to verify heap size calculation [arrow-rs]
adamreeve commented on code in PR #8925:
URL: https://github.com/apache/arrow-rs/pull/8925#discussion_r2587319067
##
parquet/tests/metadata_memory.rs:
##
@@ -0,0 +1,156 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! Tests calculation of the Parquet metadata heap size
+
+use parquet::arrow::arrow_reader::{ArrowReaderMetadata, ArrowReaderOptions};
+use parquet::encryption::decrypt::FileDecryptionProperties;
+use parquet::file::metadata::PageIndexPolicy;
+use std::alloc::{GlobalAlloc, Layout, System};
+use std::fs::File;
+use std::hint::black_box;
+use std::sync::Arc;
+use std::sync::atomic::{AtomicUsize, Ordering};
+
+pub struct TrackingAllocator {
+pub bytes_allocated: AtomicUsize,
+}
+
+impl TrackingAllocator {
+pub const fn new() -> Self {
+Self {
+bytes_allocated: AtomicUsize::new(0),
+}
+}
+
+pub fn bytes_allocated(&self) -> usize {
+self.bytes_allocated.load(Ordering::Relaxed)
+}
+}
+
+impl Default for TrackingAllocator {
+fn default() -> Self {
+Self::new()
+}
+}
+
+unsafe impl GlobalAlloc for TrackingAllocator {
+unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
+self.bytes_allocated
+.fetch_add(layout.size(), Ordering::Relaxed);
+unsafe { System.alloc(layout) }
+}
+
+unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
+self.bytes_allocated
+.fetch_sub(layout.size(), Ordering::Relaxed);
+unsafe { System.dealloc(ptr, layout) }
+}
+}
+
+#[global_allocator]
+static ALLOCATOR: TrackingAllocator = TrackingAllocator::new();
+
+#[test]
+fn test_metadata_heap_memory() {
+// Run test cases sequentially so that heap allocations
+// are restricted to a single test case at a time.
+let test_data = arrow::util::test_util::parquet_test_data();
+let reader_options =
+
ArrowReaderOptions::default().with_page_index_policy(PageIndexPolicy::Required);
+
+{
+let path = format!("{test_data}/alltypes_dictionary.parquet");
+verify_metadata_heap_memory(&path, 0.0, || reader_options.clone());
+}
+
+{
+// Calculated heap size doesn't match exactly, possibly due to extra
overhead not accounted
+// for in the HeapSize implementation for
parquet::data_type::ByteArray.
Review Comment:
I haven't managed to track down exactly where the difference comes from so
this is a bit of a guess. The confusing part is the file with encryption has
stats for a `ByteArray` column too so I'm not sure why it does give the exact
same heap size. Maybe there's something different about how the stats from
encrypted metadata work or maybe the difference is from somewhere else.
But the computed size is still very close to the actual heap allocation size
so I think this is good enough.
--
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]
