2012-03-12 18 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請求,並在結果得到的網格被填滿。直到那時應用程序進行進一步處理。

相關問題