2012-03-12 31 views
0

我正在攻击企业应用程序中的性能问题。我的一个SQL Proc返回超过2 MB的数据(XML纯文本)。为了执行该SP,它仅在数据库服务器上花费约600毫秒。但是,它需要大约30秒才能在我的用户界面中获得响应。SQL Server与.Net客户端 - 从服务器返回大量数据的最佳实践 - 性能改进

的SQL Server 2008/.NET 4.0(IIS托管的Windows应用程序)

注:在以前的性能迭代 - 太多的DB调用凑钱,因此avioded许多DB调用。但是现在返回的数据非常庞大并面临着这个问题。

请帮助确定此处提供的任何标准或限制最佳实践以提高性能。

根据收到的意见如下思路添加此位置: -

  1. 但我发现这一点的同时,我在执行从我当地的SQLserver查询分析器与现场服务器的连接同一个SP的呼叫。 2.它不是内联网,而是通过互联网在美国/印度之间进行通讯。 3.我也使用dottrace工具和源分析。 4.这个数据没有绑定的瓶颈。之前在Loop中有大约15个Db电话(每个电话都带有小号的Kbs),但现在减少到单人通话但携带大数据量的MB。

问候, Karthikeyan.G

+0

如果本地需要600ms,则表明这是带宽问题;但2MB虽然不重要,但远非“巨大” - 服务器和客户端之间的连接是什么? – 2012-03-12 09:43:13

+0

2mb现在也很严重琐碎 - 不是说它不应该被避免,而是20秒内通过局域网,无线或DSL传输30秒也是不现实的。 – TomTom 2012-03-12 09:44:38

+0

请检查时间已到。我认真地认为你看错了一个项目。 CHeck没有UI绑定,然后检查UI绑定需要多长时间。我觉得你简单的在UI中使用那段时间。 – TomTom 2012-03-12 09:45:26

回答

0

当然看起来UI结合。通过互联网2Mb不大可能需要30秒,但它可能取决于您的连接速度。

考虑到它只需要600ms来执行SP,它有点长,所以最好缓存它。无论如何,2MB的缓存并不多(只要不是每个用户)。

获取2MB的数据,缓存它,分割它。比如获得前100条记录,然后将这些行绑定到您的UI控件并实现分页。

但是,如果没有代码,我看不到哪种类型和数据的深度与哪种类型的控件绑定。

0

可以使用异步编程:

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 

在此,应用程序将产生asynchrnous方法的ExecuteReader请求,并在结果得到的网格被填满。直到那时应用程序进行进一步处理。

相关问题