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

Skip middleware code when there are no user middlewares installed #2629

Merged
merged 5 commits into from
Dec 28, 2017

Conversation

pfreixes
Copy link
Contributor

What do these changes do?

Fixes performance issue introduced by #2577, boosting from 8K req/sec
to almost 9K req/sec.

If there are no middlewares installed by the user the attribute
request._match_info.current_app already looks at to the right app,
this is by design.

Are there changes in behavior for the user?

No

Fixes performance issue introduced by #2577, boosting from 8K req/sec
to almost 9K req/sec.

If there are no middlewares installed by the user the attribute
`request._match_info.current_app` already looks at to the right app,
this is by design.
@pfreixes
Copy link
Contributor Author

Test numbers

$ python3 benchmark.py --reference=origin/master --wrk-path=/home/ec2-user/wrk/wrk /home/ec2-user/aiohttp
[origin/master] Benchmark req/sec 8206

$ python3 benchmark.py --reference=origin/fix_degradation_performance_middleware --wrk-path=/home/ec2-user/wrk/wrk /home/ec2-user/aiohttp-pfreixes
[origin/fix_degradation_performance_middleware] Benchmark req/sec 9049

I've used this benchmark [1]

[1] https://github.com/pfreixes/aiohttp_regression_performance_test

@codecov-io
Copy link

codecov-io commented Dec 28, 2017

Codecov Report

Merging #2629 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2629      +/-   ##
==========================================
+ Coverage   97.92%   97.92%   +<.01%     
==========================================
  Files          38       38              
  Lines        7261     7265       +4     
  Branches     1260     1261       +1     
==========================================
+ Hits         7110     7114       +4     
  Misses         47       47              
  Partials      104      104
Impacted Files Coverage Δ
aiohttp/web_app.py 98.84% <100%> (+0.02%) ⬆️

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 16e7d1b...7d7cf7f. Read the comment docs.


for subapp in self._subapps:
subapp.freeze()
self._run_middlewares |= len(subapp._middlewares) > 0
Copy link
Member

Choose a reason for hiding this comment

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

The line is cryptic a little.
Please replace with self._run_middlewares = self._run_middlewares or subapp._run_middlewares
The change respects middlewares from deep nested subapps: app -> subapp1 -> subapp2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, done. Added also a bit of internal documentation about this flag and the root cause of its usage.

Copy link
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

Please merge when green

@pfreixes pfreixes merged commit af3cb34 into master Dec 28, 2017
@asvetlov asvetlov deleted the fix_degradation_performance_middleware branch December 28, 2017 17:24
@lock
Copy link

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs.
If you feel like there's important points made in this discussion, please include those exceprts into that [new issue].
[new issue]: https://github.com/aio-libs/aiohttp/issues/new

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bot:chronographer:provided There is a change note present in this PR outdated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants