[英]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.我有一个 Visual Studio VB.NET 项目,它基本上对数据库运行大量查询。
After moving the database from a local on-premise SQL Server to Azure SQL, the performance dropped significantly.将数据库从本地本地 SQL 服务器移动到 Azure SQL 后,性能显着下降。
Of course it will be slower.当然会慢一些。 But it's 10 times slower... Latency is of-course the issue here.
但它慢了 10 倍……延迟当然是这里的问题。
Are there any ways to increase speed?有什么方法可以提高速度吗? Something "smart" in the connection string or command object?
连接字符串或命令 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).
必须有很多(5000+)个小查询返回一个值(当时运行一个)。
Here is an example of what I mean.这是我的意思的一个例子。 Running this on a "local" SQL Server takes 10 seconds - in Azure, it takes 200 seconds:
在“本地”SQL 服务器上运行它需要 10 秒 - 在 Azure 中,需要 200 秒:
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 /perove
I ran your code against an on-prem SQL Server instance and it ran in well under 1 second.我针对本地 SQL 服务器实例运行了您的代码,它运行时间不到 1 秒。 Same code against Azure SQL Database (basic tier) ran in 60 seconds.
针对 Azure SQL 数据库(基本层)的相同代码在 60 秒内运行。 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.我希望在 Azure 中运行代码,尤其是在与数据库相同的区域中,将提供与在本地运行两者相当的性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.