Skip to content

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

Merged
pfreixes merged 5 commits intomasterfrom
fix_degradation_performance_middleware
Dec 28, 2017
Merged

Skip middleware code when there are no user middlewares installed#2629
pfreixes merged 5 commits intomasterfrom
fix_degradation_performance_middleware

Conversation

@pfreixes
Copy link
Copy Markdown
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

Pau Freixes added 3 commits December 28, 2017 01:18
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
Copy Markdown
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
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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