-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buffer pool for decompression #1308
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 3 files reviewed, 6 unresolved discussions (waiting on @ashish-goswami, @jarifibrahim, and @manishrjain)
table/iterator.go, line 320 at r3 (raw file):
decompressPool.Put(&itr.bi.data) } itr.bi.data = nil
Set nil before putting it into the pool.
table/iterator.go, line 351 at r3 (raw file):
decompressPool.Put(&itr.bi.data) } itr.bi.data = nil
same here.
table/table.go, line 645 at r3 (raw file):
func (t *Table) decompressData(data []byte) ([]byte, error) { fmt.Println("Decompress111") dst := decompressPool.Get().(*[]byte)
Why not use y.Slice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 0 of 4 files reviewed, 6 unresolved discussions (waiting on @ashish-goswami, @gja, @jarifibrahim, and @manishrjain)
table/iterator.go, line 109 at r2 (raw file):
Previously, gja (Tejas Dinkar) wrote…
this feels a bit weird that it's done in this way. Can't we keep a single buffer pool for both decompressed and regular data?
We cannot do that since the uncompressed buffers actually point to the mmapped file.
table/iterator.go, line 320 at r3 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
Set nil before putting it into the pool.
I've changed the implementation. This is no longer necessary.
table/iterator.go, line 351 at r3 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
same here.
I've changed the implementation. This is no longer necessary.
table/table.go, line 644 at r2 (raw file):
Previously, gja (Tejas Dinkar) wrote…
Another trick is to do
type BufferPool { // contains a sync.Pool internally Get() []bytes <- Clean out the buffer here Put([] bytes) }
Done. Created a new type.
table/table.go, line 645 at r3 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
Why not use y.Slice?
y.Slice contains a []byte slice and I don't see any benefit from using y.slice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 2 of 4 files reviewed, 6 unresolved discussions (waiting on @ashish-goswami, @gja, @golangcibot, and @manishrjain)
table/builder.go, line 121 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
Probably don't need a special struct.
Done.
table/builder.go, line 125 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
I'd suggest using y.Slice.
Done.
table/iterator.go, line 109 at r1 (raw file):
Previously, golangcibot (Bot from GolangCI) wrote…
S1002: should omit comparison to bool constant, can be simplified to
itr.compressed
(fromgosimple
)
Done.
table/table.go, line 644 at r2 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
The way Go typically uses sync.Pool is directly -- that's how we do it in codebase as well. So, let's keep it consistent and use sync.Pool directly.
Done
table/table.go, line 174 at r5 (raw file):
Previously, manishrjain (Manish R Jain) wrote…
if b, ok := ... ; ok { ... }
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissed @manishrjain, and @manishrjain from 6 discussions.
Reviewable status: 2 of 4 files reviewed, all discussions resolved (waiting on @ashish-goswami and @manishrjain)
@ashish-goswami tested this with Dgraph there is a reduction in the amount of memory allocated by the decompression. |
Yes, I saw reduction in the allocated memory size after this change. However there was no change in the inuse memory size(even if you leave cluster idle for sometime). First it was shown as part of
New profile(with this change):
|
This reverts commit aadda9a.
This reverts commit aadda9a.
This reverts commit aadda9a.
This reverts commit aadda9a. This commit is being reverted because we have seen some crashes which could be caused by it. We haven't been able to reproduce the crashes yet. Related to #1389, #1388, #1387 Also, see https://discuss.dgraph.io/t/current-state-of-badger-crashes/7602
Also, disable conflict detection in badger to save memory. ``` 0dfb8b4 Changelog for v20.07.0 (dgraph-io/badger#1411) 03ba278 Add missing changelog for v2.0.3 (dgraph-io/badger#1410) 6001230 Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) 800305e Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) 63d9309 Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) e0d058c Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) d981f47 return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) 7f4e4b5 add assert to check integer overflow for table size (dgraph-io/badger#1402) 8e896a7 Add a contribution guide (dgraph-io/badger#1379) b79aeef Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) 717b89c Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) 09dfa66 Update ristretto to commit f66de99 (dgraph-io/badger#1391) 509de73 Update head while replaying value log (dgraph-io/badger#1372) e013bfd Rework DB.DropPrefix (dgraph-io/badger#1381) 3042e37 pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) 675efcd Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) 158d927 Remove second initialization of writech in Open (dgraph-io/badger#1382) d37ce36 Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) 3f4761d Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) dd332b0 Avoid panic in filltables() (dgraph-io/badger#1365) c45d966 Fix assert in background compression and encryption. (dgraph-io/badger#1366) ```
This commit brings the following new changes from badger. This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ```
This commit brings following new changes from badger This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ```
This commit brings following new changes from badger This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ```
This commit brings following new changes from badger This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ```
* Update badger to v20.07.0-rc1 This commit brings following new changes from badger This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ``` * Remove unnecessary detect conflicts
* Update badger to v20.07.0-rc1 This commit brings the following new changes from badger. This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ``` * Remove unnecessary detect conflicts
* Update badger to v20.07.0-rc1 This commit brings following new changes from badger This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ``` * Remove unnecessary detect conflicts Co-authored-by: parasssh <paras@dgraph.io>
* Update badger to v20.0.7-rc1 This commit brings following new changes from badger This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ``` * Remove unnecessary detect conflicts Co-authored-by: parasssh <paras@dgraph.io>
* Update badger to v20.07.0-rc1 This commit brings the following new changes from badger. This commit also disable conflict detection in badger to save memory. ``` Fix assert in background compression and encryption. (dgraph-io/badger#1366) Avoid panic in filltables() (dgraph-io/badger#1365) Force KeepL0InMemory to be true when InMemory is true (dgraph-io/badger#1375) Tests: Use t.Parallel in TestIteratePrefix tests (dgraph-io/badger#1377) Remove second initialization of writech in Open (dgraph-io/badger#1382) Increase default valueThreshold from 32B to 1KB (dgraph-io/badger#1346) pre allocate cache key for the block cache and the bloom filter cache (dgraph-io/badger#1371) Rework DB.DropPrefix (dgraph-io/badger#1381) Update head while replaying value log (dgraph-io/badger#1372) Update ristretto to commit f66de99 (dgraph-io/badger#1391) Enable cross-compiled 32bit tests on TravisCI (dgraph-io/badger#1392) Avoid panic on multiple closer.Signal calls (dgraph-io/badger#1401) Add a contribution guide (dgraph-io/badger#1379) add assert to check integer overflow for table size (dgraph-io/badger#1402) return error if the vlog writes exceeds more that 4GB. (dgraph-io/badger#1400) Revert "add assert to check integer overflow for table size (dgraph-io/badger#1402)" (dgraph-io/badger#1406) Revert "fix: Fix race condition in block.incRef (dgraph-io/badger#1337)" (dgraph-io/badger#1407) Revert "Buffer pool for decompression (dgraph-io/badger#1308)" (dgraph-io/badger#1408) Revert "Compress/Encrypt Blocks in the background (dgraph-io/badger#1227)" (dgraph-io/badger#1409) Add missing changelog for v2.0.3 (dgraph-io/badger#1410) Changelog for v20.07.0 (dgraph-io/badger#1411) ``` * Remove unnecessary detect conflicts
This reverts commit aadda9a. This commit is being reverted because we have seen some crashes which could be caused by it. We haven't been able to reproduce the crashes yet. Related to #1389, #1388, #1387 Also, see https://discuss.dgraph.io/t/current-state-of-badger-crashes/7602
This PR is an attempt to reduce the memory usage of decompression. This PR uses a sync pool to hold decompression buffers. A buffer is added to the pool only if was used for decompression. We don't want to put buffers that were not used for decompression because these buffers are read from mmaped SST files and any changes to these buffers would lead to a segfault.
Fixes #1239
This change is