N
Norm
Hi,
I have an page that accesses a lot of different tables in a database.
I am upgrading this page to use async tasks to increase performance.
The problem is that through tracing, I see that the callbacks are
running on different threads, but they are not running in parrallel.
Here is an example/psuedo-code.
Page PreRender
Public Conn as new SqlConnection("Data Source=***;Initial
Catalog=***;Integrated Security=True;Asynchronous
Processing=True;MultipleActiveResultSets=True;")
Conn.open()
UserControl
Private Cmd as SqlCommand
UserControl PreRender
Cmd = new SqlCommand("...",Page.Conn)
Page.RegisterAsyncTask(New PageAsyncTask(AddressOf BeginGetItems,
AddressOf EndGetItems, AddressOf GetItemsTimeout, Nothing, True))
Public Function BeginGetItems(ByVal sender As Object, ByVal e As
System.EventArgs, ByVal cb As System.AsyncCallback, ByVal extraData As
Object) As System.IAsyncResult
Trace.Write("ShowItemControls:" & Me.ID, "Async Start.
Thread ID:" & Threading.Thread.CurrentThread.ManagedThreadId)
Return Cmd(cb, Nothing)
End Function
Public Sub EndGetItems(ByVal ar As System.IAsyncResult)
Trace.Write("ShowItemControls:" & Me.ID, "Async Return.
Thread ID:" & Threading.Thread.CurrentThread.ManagedThreadId)
Dim reader As SqlDataReader
Dim InventoryDT As New CartDataSet.InventoryDataTable
reader = RelatedItemsCommand.EndExecuteReader(ar)
InventoryDT.Load(reader)
reader.close
DataList1.DataSource = InventoryDT
DataList1.DataBind
Trace.Write("ShowItemControls:" & Me.ID, "Async Finished.
Thread ID:" & Threading.Thread.CurrentThread.ManagedThreadId)
End Sub
Page PreRenderComplete
Conn.Close()
Please note that this code is not complete, it is a summary. There are
no errors, no timeouts, its just that the callback functions wait for
a previous callback function to execute. Here is a copy of the trace
for this page:
ShowItem:ShowItem1 Async Start. Thread ID:17 49.5234514 0.000250
ShowItemControls:RelatedItems1 Async Start. Thread ID:17 51.8805972
2.357146
ShowItemControls:RelatedItems2 Async Start. Thread ID:17 51.88228508
0.001688
ShowItemControls:ItemNotes1 Async Start. Thread ID:17 51.88273976
0.000455
ShowItemControls:ItemNotes2 Async Start. Thread ID:17 51.88332104
0.000581
ShowItemControls:Applications Async Start. Thread ID:17 51.88357552
0.000254
ShowItem:ShowItem1 Async Return. Thread ID:17 51.88891436 0.005339
ShowItem:ShowItem1 Async Finished. Thread ID:17 54.955182 3.066268
ShowItemControls:RelatedItems1 Async Return. Thread ID:16 54.95535484
0.000173
ShowItemControls:RelatedItems1 Async Finished. Thread ID:16
54.96175108 0.006396
ShowItemControls:RelatedItems2 Async Return. Thread ID:15 54.96197228
0.000221
ShowItemControls:RelatedItems2 Async Finished. Thread ID:15
54.96671028 0.004738
ShowItemControls:ItemNotes1 Async Return. Thread ID:18 54.9668546
0.000144
ShowItemControls:ItemNotes1 Async Finished. Thread ID:18 54.96698548
0.000131
ShowItemControls:ItemNotes2 Async Return. Thread ID:19 54.9670866
0.000101
ShowItemControls:ItemNotes2 Async Finished. Thread ID:19 54.96721528
0.000129
ShowItemControls:Applications Async Return. Thread ID:20 54.967299
0.000084
ShowItemControls:Applications Async Finished. Thread ID:20 54.97696712
0.009668
Note: There is a thread.sleep(3000) immediatly after
ShowItem:ShowItem1 Async Return. This shows that all threads are
waiting on that thread.
I would appreciate any help or information. The only thing that I can
think of is some lock behind the scenes that is blocking these
threads, but what lock? Anyway, thanks in advance!
Norm
I have an page that accesses a lot of different tables in a database.
I am upgrading this page to use async tasks to increase performance.
The problem is that through tracing, I see that the callbacks are
running on different threads, but they are not running in parrallel.
Here is an example/psuedo-code.
Page PreRender
Public Conn as new SqlConnection("Data Source=***;Initial
Catalog=***;Integrated Security=True;Asynchronous
Processing=True;MultipleActiveResultSets=True;")
Conn.open()
UserControl
Private Cmd as SqlCommand
UserControl PreRender
Cmd = new SqlCommand("...",Page.Conn)
Page.RegisterAsyncTask(New PageAsyncTask(AddressOf BeginGetItems,
AddressOf EndGetItems, AddressOf GetItemsTimeout, Nothing, True))
Public Function BeginGetItems(ByVal sender As Object, ByVal e As
System.EventArgs, ByVal cb As System.AsyncCallback, ByVal extraData As
Object) As System.IAsyncResult
Trace.Write("ShowItemControls:" & Me.ID, "Async Start.
Thread ID:" & Threading.Thread.CurrentThread.ManagedThreadId)
Return Cmd(cb, Nothing)
End Function
Public Sub EndGetItems(ByVal ar As System.IAsyncResult)
Trace.Write("ShowItemControls:" & Me.ID, "Async Return.
Thread ID:" & Threading.Thread.CurrentThread.ManagedThreadId)
Dim reader As SqlDataReader
Dim InventoryDT As New CartDataSet.InventoryDataTable
reader = RelatedItemsCommand.EndExecuteReader(ar)
InventoryDT.Load(reader)
reader.close
DataList1.DataSource = InventoryDT
DataList1.DataBind
Trace.Write("ShowItemControls:" & Me.ID, "Async Finished.
Thread ID:" & Threading.Thread.CurrentThread.ManagedThreadId)
End Sub
Page PreRenderComplete
Conn.Close()
Please note that this code is not complete, it is a summary. There are
no errors, no timeouts, its just that the callback functions wait for
a previous callback function to execute. Here is a copy of the trace
for this page:
ShowItem:ShowItem1 Async Start. Thread ID:17 49.5234514 0.000250
ShowItemControls:RelatedItems1 Async Start. Thread ID:17 51.8805972
2.357146
ShowItemControls:RelatedItems2 Async Start. Thread ID:17 51.88228508
0.001688
ShowItemControls:ItemNotes1 Async Start. Thread ID:17 51.88273976
0.000455
ShowItemControls:ItemNotes2 Async Start. Thread ID:17 51.88332104
0.000581
ShowItemControls:Applications Async Start. Thread ID:17 51.88357552
0.000254
ShowItem:ShowItem1 Async Return. Thread ID:17 51.88891436 0.005339
ShowItem:ShowItem1 Async Finished. Thread ID:17 54.955182 3.066268
ShowItemControls:RelatedItems1 Async Return. Thread ID:16 54.95535484
0.000173
ShowItemControls:RelatedItems1 Async Finished. Thread ID:16
54.96175108 0.006396
ShowItemControls:RelatedItems2 Async Return. Thread ID:15 54.96197228
0.000221
ShowItemControls:RelatedItems2 Async Finished. Thread ID:15
54.96671028 0.004738
ShowItemControls:ItemNotes1 Async Return. Thread ID:18 54.9668546
0.000144
ShowItemControls:ItemNotes1 Async Finished. Thread ID:18 54.96698548
0.000131
ShowItemControls:ItemNotes2 Async Return. Thread ID:19 54.9670866
0.000101
ShowItemControls:ItemNotes2 Async Finished. Thread ID:19 54.96721528
0.000129
ShowItemControls:Applications Async Return. Thread ID:20 54.967299
0.000084
ShowItemControls:Applications Async Finished. Thread ID:20 54.97696712
0.009668
Note: There is a thread.sleep(3000) immediatly after
ShowItem:ShowItem1 Async Return. This shows that all threads are
waiting on that thread.
I would appreciate any help or information. The only thing that I can
think of is some lock behind the scenes that is blocking these
threads, but what lock? Anyway, thanks in advance!
Norm