-
Notifications
You must be signed in to change notification settings - Fork 58
Page offset buffers not repooled #372
Comments
Hello @mdisibio I believe this issue might be isolated to Go 1.17 and the use of A different fix could be this: diff --git a/column.go b/column.go
index d511623..520ee77 100644
--- a/column.go
+++ b/column.go
@@ -636,7 +636,7 @@ func (c *Column) decodeDataPage(header DataPageHeader, numValues int, repetition
if pageKind == ByteArray {
obuf = buffers.get(4 * (numValues + 1))
defer obuf.unref()
- pageOffsets = unsafecast.BytesToUint32(obuf.data)
+ pageOffsets = unsafecast.BytesToUint32(obuf.data[:cap(obuf.data)])
}
values := pageType.NewValues(pageValues, pageOffsets)
@@ -647,7 +647,8 @@ func (c *Column) decodeDataPage(header DataPageHeader, numValues int, repetition
vbuf.data = pageValues
}
if obuf != nil {
- obuf.data = unsafecast.Uint32ToBytes(pageOffsets)
+ obuf.data = unsafecast.Uint32ToBytes(pageOffsets[:cap(pageOffsets)])
+ obuf.data = obuf.data[:4*len(pageOffsets)]
}
if err != nil {
return nil, err I would recommend upgrading to 1.18+ tho, the And when Go 1.20 gets released we will need to have more serious discussions about dropping support for 1.17. |
Hi @achille-roussel afaik Tempo has been updated to 1.19, and I am running 1.19.1 locally. Tested the proposed lines above and didn't see an improvement. Happy to provide more info or try things out. |
Thanks for confirming, sorry for making the wrong assumption here. I'll dig further to understand why the capacity information gets lost. Super happy to hear that you were able to do the upgrade to 1.19 as well! |
I would be curious to know if using the Release/Retain functions introduced in #380 will modify the behavior you observed here! |
Hi @achille-roussel as discussed offline, the new Release/Retain functionality did not change the observed behavior. Spent some more effort in this area and was able to create a more formal code change. I think this also shows more clearly what I think is happening (page buffer being swapped and original lost), but I don't know the why. if obuf != nil {
if unsafecast.PointerOf(obuf.data) != unsafecast.PointerOf(pageOffsets) {
// Pageoffset buffer is being swapped.
// Recreate obuf which allows the orignal to be unrefed and returned to the pool.
obuf = &buffer{pool: obuf.pool, data: unsafecast.Uint32ToBytes(pageOffsets)}
}
} This change yields significant memory alloc improvements on top of the benchmarks in Tempo #1818
|
As discussed offline, the real root cause is that page offset buffers were being unnecessarily allocated for dictionary-encoded byteArray columns. Submitted #398. Want to mention that #386 still yielded a minor improvement in cpu and may be worth merging (although was neutral on memory usage). Here is a benchmark comparison:
|
Related to memory profiling done in #370 , it looks like page offset buffers are attempted to be pooled, but it is not working as expected. Suspect this logic which swaps the slices.
Testing methodology
Added some simple instrumentation to
bufferPool
to track outstanding allocs via sum(gets) - sum(puts). Added a print statement here to print the before and after capacities when the offset buffer is swapped.** Results **
The pageOffsetsBufferPool allocs much more than expected, several GB. The other pools have reasonable allocs (1K to ~30MB).
When
obuf.data
is swapped to a slice of different size, the new slice is 0-length. Unsure if this is specific to our schema or relevant, but wanted to mention.prints:
** Solution**
Tried this simple fix, but it doesn't quite work. Our tests surface some data inconsistencies afterwards.
Hacking a little more does work, but I'm not familiar enough with this area to put a proper solution. This change does result in 50+% fewer allocs.
The text was updated successfully, but these errors were encountered: