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

Performance decrease (10 second delay) in database migration 8.0.0 vs 8.0.3 #33399

Closed
EvgenyMuryshkin opened this issue Mar 25, 2024 · 34 comments
Labels
area-external area-perf area-sqlserver closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Milestone

Comments

@EvgenyMuryshkin
Copy link

EvgenyMuryshkin commented Mar 25, 2024

Hi,

After upgrading from 8.0.0 to 8.0.3, get a large performance decrease during database creation.

https://github.com/EvgenyMuryshkin/EF8PPerf

image

EF 9 also has the same issue

image

Include provider and version information

.NET 8/.NET 9
EF 8.0.0 => 8.0.3, 9.0.0-preview.2.24128.4
Windows 11 Pro
VS 2022 17.9.4/17.10.0 Preview 2.0

Thank you

@roji
Copy link
Member

roji commented Mar 26, 2024

@EvgenyMuryshkin looks like a duplicate of #33176, which has already been fixed for 8.0.4. Can you please try the workaround in this comment and confirm?

@EvgenyMuryshkin
Copy link
Author

EvgenyMuryshkin commented Mar 26, 2024

@roji nope, did not work.
I think my issue is not model creation, but database creation.
Model is already created

image

image

@roji
Copy link
Member

roji commented Mar 26, 2024

This doesn't repro for me (MacOS Sonoma):

image

I'm noticing that EF upgraded patch versions of SqlClient between 8.0.0 (SqlClient 5.1.1) and 8.0.3 (SqlClient 5.1.5). Can you try to take a dependency on SqlClient 5.1.1 when using EF Core 8.0.0 to see if the problem comes form there? I'm thinking possibly of #7283 or similar.

@EvgenyMuryshkin
Copy link
Author

EvgenyMuryshkin commented Mar 26, 2024

@roji EF 8.0.1 fast, 8.0.2 slow.

with 8.0.0
5.1.1 - fast
5.1.2 - slow

@roji
Copy link
Member

roji commented Mar 26, 2024

Thanks for confirming!

The 5.1.2 release notes are here, the culprit may be dotnet/SqlClient#1983. This may very well be a dup of #7283.

/cc @David-Engel @cheenamalhotra

@cheenamalhotra
Copy link
Member

Have you tried setting ConnectRetryCount=0 on the connection string to disable transient fault handling?

@ajcvickers
Copy link
Contributor

@cheenamalhotra This should not be needed. Issue #7283 goes into this in detail.

@ajcvickers
Copy link
Contributor

/cc @SamMonoRT

@roji
Copy link
Member

roji commented Mar 27, 2024

@cheenamalhotra in addition to #7283, see dotnet/SqlClient#29 and dotnet/SqlClient#463 on the SqlClient side where this was discussed at length (especially why the connection string-based approach is insufficient here).

@EvgenyMuryshkin
Copy link
Author

EvgenyMuryshkin commented Mar 27, 2024

Have you tried setting ConnectRetryCount=0 on the connection string to disable transient fault handling?

it actually worked, thanks :)
for 8.0.3 and 9.0.0 as well

image

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 27, 2024

@roji
Copy link
Member

roji commented Mar 27, 2024

it actually worked, thanks :)

The problem with setting ConnectRetryCount=0 in your actual connection string is that is disables connection retrying everywhere, not just in the database existence check.

@cheenamalhotra
Copy link
Member

cheenamalhotra commented Mar 27, 2024

@cheenamalhotra in addition to #7283, see dotnet/SqlClient#29 and dotnet/SqlClient#463 on the SqlClient side where this was discussed at length (especially why the connection string-based approach is insufficient here).

Thanks for the context, I think we should also make sure FailFast is supported for OpenAsync() as well, now that Transient fault handling is enabled.. This probably skipped our minds and we didn't realize before.

The problem with setting ConnectRetryCount=0 in your actual connection string is that is disables connection retrying everywhere, not just in the database existence check.

Yes, that is true.


For @roji and @ajcvickers
Can you confirm the reason why dotnet/SqlClient#29 regressed was due to the change we made on OpenAsync() API to enable Transient Fault Handling? And that Open() API works as expected with Fail fast option defined?

@cheenamalhotra
Copy link
Member

Interestingly, this test is not failing: https://github.com/dotnet/SqlClient/blob/main/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ConnectivityTest.cs#L364

Note that it's only testing Open() and not OpenAsync()..

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 27, 2024

But does OpenAsync support the new overload?

@ErikEJ
Copy link
Contributor

ErikEJ commented Mar 27, 2024

Ah, I found: dotnet/SqlClient#615

@ajcvickers
Copy link
Contributor

Confirmed the regression is for async only.

@ajcvickers
Copy link
Contributor

Verified this is fixed with SqlClient 5.2.1.

@EvgenyMuryshkin
Copy link
Author

@ajcvickers which version of EF will get this fix? 8.0.7?

@ErikEJ
Copy link
Contributor

ErikEJ commented Jun 5, 2024

@EvgenyMuryshkin You can just add an explicit PackageReference to 5.2.1

@EvgenyMuryshkin
Copy link
Author

@ErikEJ I tried but I got lots of failed tests due to transient connection failures, will try to create repro soon

@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 5, 2024
@ajcvickers
Copy link
Contributor

Re-opening to consider updating the 8.0 dependency, which is currently at 5.1.5.

@ajcvickers ajcvickers reopened this Jun 5, 2024
@ajcvickers ajcvickers removed this from the 9.0.0 milestone Jun 5, 2024
@roji
Copy link
Member

roji commented Jun 5, 2024

@ajcvickers isn't SqlClient planning to revert their change in the 5.1 branch? I haven't been following closely...

@ajcvickers
Copy link
Contributor

@roji Not sure. Will try to pull together the relevant info for the team to discuss.

@ErikEJ
Copy link
Contributor

ErikEJ commented Jun 5, 2024

@ajcvickers @roji This will be fixed in 5.1.6 https://github.com/dotnet/SqlClient/projects/20

@EvgenyMuryshkin
Copy link
Author

@ErikEJ looks like my transient connectivity errors were something random and gone after PC restart (Windows update forced me to do that).
EF 8.0.6 + direct reference 5.2.1 seems to be working fine.
Thanks.

@MichaCo
Copy link

MichaCo commented Jul 5, 2024

Our unit test performance for some apps degraded like crazy after updating from .NET 6 to .NET 8.

After trying many things for hours I finally found this issue and the connection string workaround...
At least this time it wasn't the huge performance issue with OPENJSON in EF 8.

Build and test duration jumped from 5 to 20minutes on average for some CI builds (which runs integration tests and create a lot of databases)

image

This problem still exists today when using EF Core 8.0.6.

Changing the connection string to include ;ConnectRetryCount=0 fixed all the problems... For us this problem only affects unit tests where its fine to disable retry (at least as long as we do not actually use certain features I guess).
But it would be really great if that could be fixed in EF 8.0.x soon

@ajcvickers ajcvickers added this to the 9.0.0 milestone Aug 14, 2024
@roji roji added the blocked label Aug 14, 2024
@ajcvickers ajcvickers removed this from the 9.0.0 milestone Aug 27, 2024
@ajcvickers
Copy link
Contributor

Note: this is now fixed for 9.0 RC2 with an LTS SqlClient by changing to SqlClient 5.1.6. We plan to also patch 8.0 for this, but we're going to let 5.1.6 have a bit of time in the wild first.

@ajcvickers ajcvickers removed their assignment Aug 31, 2024
@AndriySvyryd
Copy link
Member

Fixed in 576f0d0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-external area-perf area-sqlserver closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported regression Servicing-approved type-bug
Projects
None yet
Development

No branches or pull requests

9 participants