Skip to content

Use multiple linked lists to reduce contention in the segment pool#727

Merged
swankjesse merged 3 commits into
masterfrom
rewlad-jwilson.0527.segment_pool_buckets
Jul 6, 2020
Merged

Use multiple linked lists to reduce contention in the segment pool#727
swankjesse merged 3 commits into
masterfrom
rewlad-jwilson.0527.segment_pool_buckets

Conversation

@swankjesse
Copy link
Copy Markdown
Collaborator

This adds a commit to @rewlad's PR 725.

rewlad and others added 2 commits May 31, 2020 14:07
Also round up the number of cores to the nearest power of two.

Also change the behavior of SegmentPool.byteCount to only track
the parts of the pool accessible to the current caller.

This builds upon rewlad's fine work of tuning the segment pool.
Copy link
Copy Markdown
Collaborator Author

@swankjesse swankjesse left a comment

Choose a reason for hiding this comment

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

I’d like to land this PR and cut an Okio release!

actual val byteCount: Int
get() {
val first = firstRef().get() ?: return 0
return first.limit
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@rewlad rather than trying to make this correct, I’m just redefining the field to only return the byte count accessible to the current thread. That’s certainly enough to make our tests happy!

@swankjesse
Copy link
Copy Markdown
Collaborator Author

swankjesse commented Jun 13, 2020

I benchmarked 3 segment pool implementations. I used 128 threads on my 16 core MacBook Pro.

no pooling

memory: 0 KiB
CPU: 1.5M ops/sec

master

memory: 64 KiB
CPU: 3.2M ops/sec

hash buckets (this PR)

memory: 16 cores * 64 KiB = 1 MiB
CPU: 9.8M ops/sec

thread local segment pool

memory: 128 threads * 64 KiB = 8 MiB
CPU: 11.4M ops/sec

This implementation is definitely a compromise on memory vs. CPU.

@swankjesse
Copy link
Copy Markdown
Collaborator Author

Forgot to link the benchmark!
https://gist.github.com/swankjesse/95bf5687ad40b6dc47386d348079a623

@swankjesse swankjesse merged commit 6e9d468 into master Jul 6, 2020
@oldergod oldergod deleted the rewlad-jwilson.0527.segment_pool_buckets branch August 18, 2020 01:16
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.

3 participants