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

Made middleware path resolving lazy and refactored middleware names #5041

Merged
merged 3 commits into from
Dec 6, 2019

Conversation

NyanKiyoshi
Copy link
Member

Changes

  • Made graphql api path' resolving lazy in middlewares:
    When profiling, it was noticed that most of the CPU time is actually wasted in the middlewares when calling and resolving reverse("api"). For example, when querying the me object, 28 ms of CPU time were used by the reverse("api") and 5 ms were actually being the rest of the request being processed.

  • Renamed middleware functions to meaningful names for easier profiling:
    In the profiling trace we see "middleware" everywhere, making it impossible to know what middleware was being executed without having to lookup the path and line number that was provided by the trace.
    middleware -> middleware -> middleware -> middleware. Who is who?

Pull Request Checklist

  1. Privileged views and APIs are guarded by proper permission checks.
  2. All visible strings are translated with proper context.
  3. All data-formatting is locale-aware (dates, numbers, and so on).
  4. Database queries are optimized and the number of queries is constant.
  5. Database migration files are up to date.
  6. The changes are tested.
  7. GraphQL schema and type definitions are up to date.
  8. Changes are mentioned in the changelog.

When profiling, it was noticed that most of the CPU time is actually
wasted in the middlewares when calling and resolving `reverse("api")`.
In the profiling trace we see "middleware" everywhere, making it
impossible to know what middleware was being executed without having
to lookup the path and line number that was provided by the trace.
Copy link

django-queries commented Dec 5, 2019

Here is the report for fe22c73 (NyanKiyoshi/saleor @ middlewares/lazy)
Base comparison is e3af8be.

No differences were found. (click me)

# api.benchmark checkout
  test name                                  	left count 	right count	duplicate count
  -------------------------------------------	-----------	-----------	---------------
  add billing address to checkout            	         34	         34	             20
  add shipping to checkout                   	          7	          7	              0
  checkout payment charge                    	         10	         10	              0
  complete checkout                          	          8	          8	              0
  create checkout                            	         50	         50	             24

# api.benchmark homepage
  test name                                  	left count 	right count	duplicate count
  -------------------------------------------	-----------	-----------	---------------
  retrieve main menu                         	          5	          5	              0
  retrieve product list                      	          4	          4	              0
  retrieve secondary menu                    	          5	          5	              0
  retrieve shop                              	          2	          2	              0

# api.benchmark product
  test name                                  	left count 	right count	duplicate count
  -------------------------------------------	-----------	-----------	---------------
  product details                            	         15	         15	              3
  retrieve product attributes                	          9	          9	              0

# api.benchmark variant
  test name                                  	left count 	right count	duplicate count
  -------------------------------------------	-----------	-----------	---------------
  product variant bulk create                	         51	         51	              3
  retrieve variant list                      	         15	         15	              6

# api product sorting attributes
  test name                                  	left count 	right count	duplicate count
  -------------------------------------------	-----------	-----------	---------------
  sort product not having attribute data     	         21	         21	              0

@codecov
Copy link

codecov bot commented Dec 5, 2019

Codecov Report

Merging #5041 into master will increase coverage by <.01%.
The diff coverage is 87.5%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5041      +/-   ##
==========================================
+ Coverage   90.89%   90.89%   +<.01%     
==========================================
  Files         294      294              
  Lines       18273    18274       +1     
  Branches     1680     1681       +1     
==========================================
+ Hits        16610    16611       +1     
  Misses       1227     1227              
  Partials      436      436
Impacted Files Coverage Δ
saleor/graphql/views.py 84.91% <100%> (+0.25%) ⬆️
saleor/graphql/middleware.py 80% <100%> (-0.44%) ⬇️
saleor/core/middleware.py 52.5% <78.57%> (-0.4%) ⬇️

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 e3af8be...fe22c73. Read the comment docs.

Copy link
Member

@maarcingebala maarcingebala left a comment

Choose a reason for hiding this comment

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

Thanks for submitting the PR, this looks really good!

@maarcingebala maarcingebala merged commit 440c9b1 into saleor:master Dec 6, 2019
@NyanKiyoshi NyanKiyoshi deleted the middlewares/lazy branch December 6, 2019 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants