简体   繁体   中英

Azure SQL Server takes 10 times as long as a on-premise SQL Server

I have a Visual Studio VB.NET project that basically runs a large number of queries against a database.

After moving the database from a local on-premise SQL Server to Azure SQL, the performance dropped significantly.

Of course it will be slower. But it's 10 times slower... Latency is of-course the issue here.

Are there any ways to increase speed? Something "smart" in the connection string or command object?

I cannot change the "architecture" of the project (out of my hands). It has to be a lot (5000+) of small queries that return one value (running one at the time).

Here is an example of what I mean. Running this on a "local" SQL Server takes 10 seconds - in Azure, it takes 200 seconds:

Dim Server As String = "AZURE.poweranalyzedevazuretest.database.windows.net"
Dim User As String = "*****"
Dim password As String = "******!"
Dim PRODUCTIONDATABASE As String = "MYDB"

Dim SQL_CONNECTION_STRING As String = "Server=" & Server & "; Database=" & PRODUCTIONDATABASE & "; User Id=" & User & "; Password=" & password & ";"

Dim SDataSet = New DataSet
Dim SDataAdapter = New SqlClient.SqlDataAdapter
Dim SCommand As New SqlClient.SqlCommand
Dim CurrConnection = New SqlConnection(SQL_CONNECTION_STRING)
CurrConnection.Open()
Debug.Print(Now().ToString)

For i = 1 To 1000
    SCommand.Connection = CurrConnection
    SCommand.CommandText = "SELECT 'Hello World'"
    Dim p As Object = SCommand.ExecuteScalar()
Next

CurrConnection.Close()
Debug.Print(Now().ToString)

/perove

I ran your code against an on-prem SQL Server instance and it ran in well under 1 second. Same code against Azure SQL Database (basic tier) ran in 60 seconds. This test is measuring network latency rather than database performance.

I expect running the code in Azure, especially in the same region as the db, will provide performance comparable to running both on-prem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM