Skip to content
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

Use BufferPool for cleartext as well as ciphertext chunks #125

Merged
merged 9 commits into from
Mar 17, 2022

Conversation

overheadhunter
Copy link
Member

Previously, each chunk of data allocated a new 32kB ByteBuffer, which was in most cases very short-lived. This lead to both, massive allocations as well as garbage collection activity.

To reduce both memory as well as CPU pressure, this introduces a filesystem-scoped pooling mechanism. ByteBuffers should be returned to the pool but it will do no harm not to do so.

@overheadhunter overheadhunter self-assigned this Jan 26, 2022
@overheadhunter overheadhunter changed the title Use BufferPool for cleartext as well as ciphertext chunks Use BufferPool for cleartext as well as ciphertext chunks Jan 26, 2022
Copy link
Member

@infeo infeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work you did here 👍

@overheadhunter Did you considered the Chunk class implementing Autoclosable? In the close method, it could automatically call bufferpool.recycle().

  • Chunk implementing Autoclosable

@overheadhunter
Copy link
Member Author

Did you considered the Chunk class implementing Autoclosable?

The problem is that Chunk is passed around between classes a lot, i.e. try-with-resource can't be used. It is even cached, so analysis tools have a hard time tracking the lifecycle and will report false positive leaks.

Copy link
Member

@infeo infeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one naming thing

ChunkData chunkData = ChunkData.emptyWithSize(cleartextChunkSize);
chunkData.copyData().from(src);
chunkCache.set(chunkIndex, chunkData);
ByteBuffer cleartextChunk = bufferPool.getCleartextBuffer();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be named cleartextBuffer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is a chunk. I prefer to name variables according to semantics rather than to types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but from a technical perspective a chunk is an object derived from the Chunk class wrapping a buffer. Here those two definitions intersect, and to avoid confusion I would tend to the technical description. I mean, we are wrapping three lines later a "chunk" with "Chunk". And at creation, the "chunk" is not a "chunk" but just a buffer (the method even says it). Additionally, the naming scheme is also used in other places.

As a compromise, how about renaming it to cleartextChunkData ?

@sonarcloud
Copy link

sonarcloud bot commented Mar 17, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

@overheadhunter overheadhunter merged commit a0f156b into develop Mar 17, 2022
@overheadhunter overheadhunter deleted the feature/bytebuffer-pooling branch March 17, 2022 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants