runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Performance issues using SQLClient

Open ice-bin-ux opened this issue 8 years ago • 10 comments

i use system.data.sqlclient in my aps.net core project,but why the first time i request it's very slow,after request it's faster.about few minutes later the request change slow again。

  using (IDbConnection conn = DBFactory.GetDbConnection(serviceInfo.DBType))
                {
                    conn.ConnectionString = serviceInfo.ConnectionString;
                    conn.Open();
                    IEnumerable<dynamic> ret = await conn.QueryAsync(serviceInfo.CommandText, _paramsValue);
                    var response = new { error_code = 0, error_desc = "", data = ret };
                    return JsonConvert.SerializeObject(response);
                }

first request 4479ms second request 269ms
i use Dapper,but when i remove it,the test result is same.
i used Connection Pool

Server=xxxx;Database=xxxx;UID=xxx;PWD=xxxx;Max Pool Size=50;Min Pool Size=10;

ice-bin-ux avatar Feb 05 '18 02:02 ice-bin-ux

Cc @geleems

saurabh500 avatar Feb 05 '18 07:02 saurabh500

thanks @saurabh500 @geleems @danmosemsft

ice-bin-ux avatar Feb 05 '18 09:02 ice-bin-ux

@ICE2017 Which OS are you running the App on? What version of System.Data.SqlClient are you consuming? Can you give us a repro project as well?

saurabh500 avatar Feb 06 '18 18:02 saurabh500

thanks @saurabh500 windows server 2008 R2
System.Data.SqlClient, Version=4.2.0.0
the sql server version is 2008
the code is simple just like

using (IDbConnection conn = DBFactory.GetDbConnection(serviceInfo.DBType))
                {
                    conn.ConnectionString = serviceInfo.ConnectionString;
                    conn.Open();
                    IEnumerable<dynamic> ret = await conn.QueryAsync(serviceInfo.CommandText, _paramsValue);
                    var response = new { error_code = 0, error_desc = "", data = ret };
                    return JsonConvert.SerializeObject(response);
                }

ice-bin-ux avatar Feb 07 '18 00:02 ice-bin-ux

Is the .Net code running on Windows or Linux?

saurabh500 avatar Feb 07 '18 02:02 saurabh500

on windows the version is winserver 2008 R2

ice-bin-ux avatar Feb 07 '18 03:02 ice-bin-ux

I found some new things ,when i request the sqlserver,.NET Core Clinet will produce lot's pageiolatch_sh, but i test .net framework 4.5 it's not.
f6ca700

ice-bin-ux avatar Feb 07 '18 04:02 ice-bin-ux

@ICE2017 There was a problem with async query execution in SqlClient where the executions can happen in a sync manner. @geleems had submitted a fix at https://github.com/dotnet/corefx/pull/26595 Can you try out a nightly build from https://dotnet.myget.org/feed/dotnet-core/package/nuget/System.Data.SqlClient e.g. 4.5.0-preview2-26225-02 to see if this fixes your problem?

saurabh500 avatar Feb 26 '18 18:02 saurabh500

@saurabh500 thanks very much i will try

ice-bin-ux avatar Feb 28 '18 01:02 ice-bin-ux

@ice2017 I also want to mention that based on the docs I read online that increase in pageiolatch on Sql could mean I/O issues on the server side. I don't know how strong is the correlation between increased pageiolatch and .Net core but you may want to look into it separately. .Net core uses pretty much the same code on windows to interact with Sql server as .Net framework does

saurabh500 avatar Feb 28 '18 04:02 saurabh500