Skip to content

Fix #6102 - Intense CPU utilization on page change (#6542) #6658

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

Merged
merged 1 commit into from
Jan 16, 2019

Conversation

rynowak
Copy link
Member

@rynowak rynowak commented Jan 14, 2019

Description

#6543

The routing system in ASP.NET Core supports changing when a Razor Page is added, removed, or edited. 2.2.0 has a bug where the address table in Endpoint Routing subscribes to route table change notifications an additional time each time a change occurs. This means that each route table change is processed N additional times when it occurs - where N is the number of changes so far.

Customer Impact

Developers can see high CPU and memory utilization when they make a change that triggers rebuilding of the route table (edit a Razor Page while the site is running). This will escalate over time as more changes are made until the application becomes unusable. Customers will primarily hit this in inner-loop development, but this can also happen in production. We know that many developers like to have recompilation available in production.

Regression?

Yes, this is a bug in a new 2.2 feature.

Risk

Low. The fix is to remove the offending line of code. Additional steps are taken to harden the code, and add IDisposable support so that infrastructure pieces unsubscribe from change notifications when disposed.

Since these changes are infrastructure, there is no impact in the user-visible behavior.


The issue here was that every time a Razor Page changed, we would
subscribe an additional time to the endpoint change notifications. This
means that if you tweaked a page 30 times, we would update the address
table 31 times when you save the file. If you were doing a lot of editing
then this would grow to a really large amount of computation.

The fix is to use DataSourceDependentCache, which is an existing utility
type we developed for this purpose. I'm not sure why it wasn't being
used for this already. We're already using DataSourceDependentCache in a
bunch of other places, and it's well tested.

I also tweaked the stucture of this code to be more similar to
EndpointNameAddressScheme. This involved some test changes that all
seemed like good cleanup. The way this was being tested was a little
wonky.

(cherry picked from commit a5658a8)

@rynowak
Copy link
Member Author

rynowak commented Jan 14, 2019

This is a straightforward cherry-pick of the fix from master.

@JamesNK
Copy link
Member

JamesNK commented Jan 14, 2019

You need to put your description into the ship room template and tag with servicing consider 😋

e.g. #6645

@rynowak
Copy link
Member Author

rynowak commented Jan 14, 2019

Updated

@rynowak rynowak added Servicing-consider Shiproom approval is required for the issue and removed patch-proposed labels Jan 14, 2019
@JamesNK JamesNK added this to the 2.2.x milestone Jan 14, 2019
Copy link
Contributor

@mkArtakMSFT mkArtakMSFT left a comment

Choose a reason for hiding this comment

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

Just couple of notes to consider.

@leecow leecow added Servicing-approved Shiproom has approved the issue and removed Servicing-consider Shiproom approval is required for the issue labels Jan 15, 2019
@leecow leecow modified the milestones: 2.2.x, 2.2.2 Jan 15, 2019
@natemcmaster
Copy link
Contributor

Can you please update eng/PatchConfig.props to list the packages which need to ship an update?

@leecow
Copy link
Member

leecow commented Jan 15, 2019

Approved. Merge soon ;-)

@rynowak
Copy link
Member Author

rynowak commented Jan 15, 2019

@natemcmaster @mikaelm12 @dougbu - could one of you review the last commit?

@dougbu
Copy link
Contributor

dougbu commented Jan 15, 2019

@rynowak I'm surprised you don't have merge conflicts because the 2.2.2 section already exists and contains a few rows. The changes otherwise look fine.

@mikaelm12
Copy link
Contributor

I'm surprised you don't have merge conflicts because the 2.2.2 section already exists and contains a few rows.

Yeah, I figured you would need to rebase. Not sure why github isn't reporting a conflict there since there definitely are changes in the PatchConfig.props in the 2.2 branch.

@JamesNK
Copy link
Member

JamesNK commented Jan 15, 2019

A patch PR of mine will add Microsoft.AspNetCore.Routing to the file.

* Fix #6102 - Intense CPU utilization on page change

The issue here was that every time a Razor Page changed, we would
subscribe an additional time to the endpoint change notifications. This
means that if you tweaked a page 30 times, we would update the address
table 31 times when you save the file. If you were doing a lot of editing
then this would grow to a really large amount of computation.

The fix is to use DataSourceDependentCache, which is an existing utility
type we developed for this purpose. I'm not sure why it wasn't being
used for this already. We're already using DataSourceDependentCache in a
bunch of other places, and it's well tested.

I also tweaked the stucture of this code to be more similar to
EndpointNameAddressScheme. This involved some test changes that all
seemed like good cleanup. The way this was being tested was a little
wonky.

(cherry picked from commit a5658a8)
@rynowak
Copy link
Member Author

rynowak commented Jan 15, 2019

I was also surprised not to see it. Should I rebase?

@mikaelm12
Copy link
Contributor

James already added the package to the PatchConfig.props so you're change to it is no longer showing up. You could rebase to be safe but I don't think it's necessary.

@rynowak rynowak merged commit 3e5b37f into release/2.2 Jan 16, 2019
@rynowak rynowak deleted the rynowak/fix-6543 branch January 16, 2019 00:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Servicing-approved Shiproom has approved the issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants