我正在攻击企业应用程序中的性能问题。我的一个SQL Proc返回超过2MB的数据(XML纯文本)。对于执行该SP,它仅在DB服务器中占用大约600 ms。但是,在我的UI中需要大约30秒才能得到响应。
SQL server 2008 / .NET 4.0 (IIS承载的windows应用程序)
注意:在以前的性能迭代中--太多的DB调用聚集在一起,因此产生了许多DB调用。但是现在返回的数据是巨大的,并且面临着这个问题。
请帮助确定任何标准或限制,这里提供的最佳做法,以提高性能。
根据以下收到的意见,请在此添加以下内容:
中携带大量数据。
你好,Karthikeyan.G
发布于 2012-03-26 12:36:59
当然看起来像UI绑定。2Mb的互联网不太可能需要30秒,但它可能取决于你的连接速度。
考虑到它只需要600毫秒来执行SP,它是有点长,所以最好是缓存它。无论如何,2MB并不需要缓存太多(只要它不是每个用户)。
获取2MB的数据,缓存它,分割它。例如获取前100条记录,然后将这些行绑定到UI控件并实现分页。
但是,如果没有代码,我就无法看到您要绑定到哪种类型的控件的数据的类型和深度。
发布于 2012-04-27 11:58:36
您可以使用异步编程:
Dim connectionString As String = "server=.\SQLEXPRESS; database=master; Integrated Security=true; Asynchronous Processing=true"
Private Sub btnDisplayCustomersCallback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplayCustomersCallBack.Click
Dim sqlConnection As New SqlConnection(connectionString)
Dim sqlCommand As SqlCommand = sqlConnection.CreateCommand()
Dim asyncResult As IAsyncResult
'Example of Asynchronous Callback Model
sqlCommand.CommandText = "SELECT * FROM [customer]"
sqlCommand.CommandType = CommandType.Text
sqlConnection.Open()
btnDisplayCustomersCallBack.Enabled = False
Dim callback As AsyncCallback = New AsyncCallback(AddressOf DisplayCustomers)
asyncResult = sqlCommand.BeginExecuteReader(callback, sqlCommand, CommandBehavior.CloseConnection)
End Sub
Private Sub DisplayCustomers(ByVal result As IAsyncResult)
Dim dr As SqlDataReader
Dim command As SqlCommand
Dim del As DelFillGrid
Try
command = CType(result.AsyncState, SqlCommand)
dr = command.EndExecuteReader(result)
del = New DelFillGrid(AddressOf FillGrid)
Threading.Thread.Sleep(5000)
Me.Invoke(del, dr)
Finally
If (Not dr.IsClosed) Then
dr.Close()
End If
End Try
End Sub
Private Sub FillGrid(ByVal dr As SqlDataReader)
Try
Dim dt As New DataTable()
dt.Load(dr)
Me.DataGridView1.DataSource = dt
Catch ex As Exception
' Because you're guaranteed this procedure
' is running from within the form's thread,
' it can directly interact with members of the form.
Finally
btnDisplayCustomersCallBack.Enabled = True
If dr IsNot Nothing Then
dr.Close()
End If
End Try
End Sub在这种情况下,应用程序将在异步方法中生成一个ExecuteReader请求,当得到结果时,网格将被填充。在此之前,应用程序将进行进一步处理。
https://stackoverflow.com/questions/9664659
复制相似问题