Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Reduce allocations to store config on context in Activator #11013

Merged
merged 2 commits into from
Mar 24, 2021

Conversation

markusthoemmes
Copy link
Contributor

Proposed Changes

The current store implementation has 5 allocations in its HTTP Middleware

  • 2 in the call for r.WithContext(ctx)
  • 1 to allocate the new value context
  • 1 to allocate a new *Config
  • 1 to load the untyped config

This reduces the footprint of the store to just one allocation by

  1. Storing the intermediate Config until it needs to be updated.
  2. Collapsing r.WithContext(ctx) calls with the context handler.

Release Note

NONE

/assign @julz @vagababov

@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Mar 23, 2021
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/autoscale area/networking labels Mar 23, 2021
@codecov
Copy link

codecov bot commented Mar 23, 2021

Codecov Report

Merging #11013 (fe1c849) into main (b5d1348) will increase coverage by 0.05%.
The diff coverage is 94.44%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #11013      +/-   ##
==========================================
+ Coverage   87.95%   88.01%   +0.05%     
==========================================
  Files         188      189       +1     
  Lines        9116     9133      +17     
==========================================
+ Hits         8018     8038      +20     
+ Misses        842      839       -3     
  Partials      256      256              
Impacted Files Coverage Δ
cmd/activator/main.go 0.00% <0.00%> (ø)
pkg/activator/config/store.go 100.00% <100.00%> (ø)
pkg/activator/handler/context_handler.go 96.15% <100.00%> (+0.32%) ⬆️
pkg/activator/net/revision_backends.go 91.32% <0.00%> (+0.91%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5d1348...fe1c849. Read the comment docs.

@markusthoemmes
Copy link
Contributor Author

/retest

HTTP2 probe stuff. Alerted the networking team.

@markusthoemmes
Copy link
Contributor Author

With the benchmark in #11014 the results are as following:

benchmark                               old ns/op     new ns/op     delta
BenchmarkHandlerChain/sequential-16     21752         20881         -4.00%
BenchmarkHandlerChain/parallel-16       20981         20270         -3.39%

benchmark                               old allocs     new allocs     delta
BenchmarkHandlerChain/sequential-16     125            121            -3.20%
BenchmarkHandlerChain/parallel-16       125            121            -3.20%

benchmark                               old bytes     new bytes     delta
BenchmarkHandlerChain/sequential-16     7626          7145          -6.31%
BenchmarkHandlerChain/parallel-16       7801          7314          -6.24%

Copy link
Contributor

@vagababov vagababov left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve
👍

@knative-prow-robot knative-prow-robot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Mar 23, 2021
The current store implementation has 5 allocations in its HTTP Middleware

- 2 in the call for `r.WithContext(ctx)`
- 1 to allocate the new value context
- 1 to allocate a new *Config
- 1 to load the untyped config

This reduces the footprint of the store to just one allocation by

1. Storing the intermediate Config until it needs to be updated.
2. Collapsing `r.WithContext(ctx)` calls with the context handler.
@knative-prow-robot knative-prow-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 23, 2021
Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

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

spotted tiny nit, sorry; lgtm otherwise

Copy link
Member

@julz julz left a comment

Choose a reason for hiding this comment

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

/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 24, 2021
@knative-prow-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: julz, vagababov

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

@knative-prow-robot knative-prow-robot merged commit d5d489c into knative:main Mar 24, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/autoscale area/networking cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants