Skip to content

Conversation

@jpbetz
Copy link
Contributor

@jpbetz jpbetz commented Feb 6, 2020

Remove use of sync.Pool entirely and add a Allocator interface that works like so:

allocator := value.NewFreelistAllocator()
val := m.GetUsing(allocator, "key")
...
// when done with the object:
allocator.Free(val)

The freelists themselves are pooled. The typical usage is to get a freelist from a pool when starting a traversal (e.g. validationWalker or mergeWalker) and then returned at the end of the traversal.

Callers that don't opt in to use the allocator by calling the "Using" functions get heap allocation by default.

The eliminates the contention observed by sync.Pool particularly when concurrency is high.

Test: Compare cpu=32 RunParallel benchmark that calls ObjectToTyped and then Compare, just like updater.Update does
Baseline: master + #153

name                               old time/op    new time/op    delta
Compare/Pod/structured-32            64.6µs ± 8%    44.5µs ± 5%  -31.17%  (p=0.008 n=5+5)
Compare/Pod/unstructured-32          74.9µs ± 7%    66.0µs ±43%     ~     (p=0.151 n=5+5)
Compare/Node/structured-32            110µs ±11%      82µs ± 3%  -25.38%  (p=0.008 n=5+5)
Compare/Node/unstructured-32          126µs ± 5%     105µs ± 6%  -16.28%  (p=0.008 n=5+5)
Compare/Endpoints/structured-32      1.00ms ± 9%    0.85ms ± 6%  -14.92%  (p=0.008 n=5+5)
Compare/Endpoints/unstructured-32    2.04ms ± 5%    1.87ms ± 6%   -8.12%  (p=0.008 n=5+5)

name                               old alloc/op   new alloc/op   delta
Compare/Pod/structured-32            26.1kB ± 0%    26.5kB ± 0%   +1.42%  (p=0.008 n=5+5)
Compare/Pod/unstructured-32          59.6kB ± 0%    60.2kB ± 0%   +0.97%  (p=0.008 n=5+5)
Compare/Node/structured-32           54.3kB ± 0%    54.4kB ± 0%   +0.21%  (p=0.008 n=5+5)
Compare/Node/unstructured-32          106kB ± 0%     110kB ± 0%   +4.24%  (p=0.008 n=5+5)
Compare/Endpoints/structured-32       349kB ± 0%     332kB ± 0%   -4.84%  (p=0.008 n=5+5)
Compare/Endpoints/unstructured-32    2.04MB ± 0%    2.10MB ± 0%   +2.87%  (p=0.008 n=5+5)

name                               old allocs/op  new allocs/op  delta
Compare/Pod/structured-32               799 ± 0%       809 ± 0%   +1.25%  (p=0.008 n=5+5)
Compare/Pod/unstructured-32           1.23k ± 0%     1.26k ± 0%   +2.19%  (p=0.008 n=5+5)
Compare/Node/structured-32            1.62k ± 0%     1.63k ± 0%   +0.43%  (p=0.016 n=4+5)
Compare/Node/unstructured-32          2.45k ± 0%     2.62k ± 0%   +7.19%  (p=0.008 n=5+5)
Compare/Endpoints/structured-32       8.20k ± 0%     8.20k ± 0%     ~     (p=0.333 n=5+5)
Compare/Endpoints/unstructured-32     32.4k ± 0%     37.0k ± 0%  +14.03%  (p=0.008 n=5+5)

/sig api-machinery
cc @apelisse @jennybuckley @lavalamp

@k8s-ci-robot k8s-ci-robot added sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 6, 2020
@jpbetz jpbetz force-pushed the freelist-optimization branch from c2b8c41 to b321ad9 Compare February 6, 2020 03:00
Copy link
Contributor

@apelisse apelisse left a comment

Choose a reason for hiding this comment

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

This looks good, it's mostly mechanical after all. It clearly needs to be rebased/squashed though, thanks!

@jpbetz jpbetz force-pushed the freelist-optimization branch from b321ad9 to c9bdf8e Compare February 6, 2020 06:02
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 6, 2020
@jpbetz
Copy link
Contributor Author

jpbetz commented Feb 6, 2020

This looks good, it's mostly mechanical after all. It clearly needs to be rebased/squashed though, thanks!

Thanks for looking at it so quickly. I've squashed and reduced the copy-paste in the allocator code.

@jpbetz jpbetz force-pushed the freelist-optimization branch from c9bdf8e to 0e517d5 Compare February 6, 2020 06:08
@jpbetz
Copy link
Contributor Author

jpbetz commented Feb 6, 2020

Rebased

@apelisse
Copy link
Contributor

apelisse commented Feb 6, 2020

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 6, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse, jpbetz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 6, 2020
@k8s-ci-robot k8s-ci-robot merged commit 1791273 into kubernetes-sigs:master Feb 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants