Problem: Huge overhead from making asynchronous SOAP calls...

U

usenetaccount

In a newly created test app, to maximize client performance I tried to
make two SOAP method calls in tandem (the soap methods execute some
specified query), as each call includes a large amount of idle time by
the client as it waits for a query to execute and return a dataset.

As a test, I initially wrote two versions:
' // Sequential & Synchronous
Dim webobj As com.mycompany.webobject
Dim ds1 As System.Data.DataSet
Dim ds2 As System.Data.DataSet


webobj = new com.mycompany.webobject
ds1 = webobj.Test("qry_1")
ds2 = webobj.Test("qry_2")
MsgBox "Done!"


' // Asynchronous
Dim webobj As com.mycompany.webobject
Dim arQry1 As IAsyncResult
Dim arQry2 As IAsyncResult
Dim ds1 As System.Data.DataSet
Dim ds2 As System.Data.DataSet


webobj = new com.mycompany.webobject
arQry1 = webobj.BeginTest("qry_1", Nothing, Nothing)
arQry2 = webobj.BeginTest("qry_2", Nothing, Nothing)


ds1 = webobj.EndTest(arQry1)
ds2 = webobj.EndTest(arQry1)
MsgBox "Done!"

.....

Query 1 returns about 18,000 rows while Query 2 returned about 200.
The surprising result was that the asynchronous way took about 30
seconds while the synchronous way took about 13.

As a reality check, I then changed Query 2 to a longer running query
which returned about 10,000 rows. I also created a third,
multi-threaded version of the test. Each thread calls the SYNCHRONOUS
SOAP method and for the most part, it should be approximately the same
as the asynchronous version.

As expected, the multi-threaded version outperforms the sequential
version. But even with TWO long-running queries, the asynchronous
version STILL underperforms the sequential version!


Someone suggested updating the file machine.config with
maxconnections="10" (from "2") but this had no effect in my cas.

Any ideas as to what's going on? I have no problems creating a
multi-threaded application if that's what it takes, but for
maintainability I'd rather keep the code as simple as possible if I
can.

Thanks!
 
K

Ken Tucker [MVP]

Hi,

A synchronous doesnt let anything else run until that call is done.
An asynchronous call runs in the background so it takes longer. The biggest
advantage of asynchronous call is that the function call will not lock up
the computer and make it seam unresponsive.

Ken
------------
In a newly created test app, to maximize client performance I tried to
make two SOAP method calls in tandem (the soap methods execute some
specified query), as each call includes a large amount of idle time by
the client as it waits for a query to execute and return a dataset.

As a test, I initially wrote two versions:
' // Sequential & Synchronous
Dim webobj As com.mycompany.webobject
Dim ds1 As System.Data.DataSet
Dim ds2 As System.Data.DataSet


webobj = new com.mycompany.webobject
ds1 = webobj.Test("qry_1")
ds2 = webobj.Test("qry_2")
MsgBox "Done!"


' // Asynchronous
Dim webobj As com.mycompany.webobject
Dim arQry1 As IAsyncResult
Dim arQry2 As IAsyncResult
Dim ds1 As System.Data.DataSet
Dim ds2 As System.Data.DataSet


webobj = new com.mycompany.webobject
arQry1 = webobj.BeginTest("qry_1", Nothing, Nothing)
arQry2 = webobj.BeginTest("qry_2", Nothing, Nothing)


ds1 = webobj.EndTest(arQry1)
ds2 = webobj.EndTest(arQry1)
MsgBox "Done!"

.....

Query 1 returns about 18,000 rows while Query 2 returned about 200.
The surprising result was that the asynchronous way took about 30
seconds while the synchronous way took about 13.

As a reality check, I then changed Query 2 to a longer running query
which returned about 10,000 rows. I also created a third,
multi-threaded version of the test. Each thread calls the SYNCHRONOUS
SOAP method and for the most part, it should be approximately the same
as the asynchronous version.

As expected, the multi-threaded version outperforms the sequential
version. But even with TWO long-running queries, the asynchronous
version STILL underperforms the sequential version!


Someone suggested updating the file machine.config with
maxconnections="10" (from "2") but this had no effect in my cas.

Any ideas as to what's going on? I have no problems creating a
multi-threaded application if that's what it takes, but for
maintainability I'd rather keep the code as simple as possible if I
can.

Thanks!
 
U

usenetaccount

I would whole-heartedly agree, except for the following:
- Most of the processing time is on the back-end server, which is IIS
(for the SOAP call) and SQL Server (for the database query).
- I created a third, multi-threaded version which makes two SOAP calls
at once; neither SOAP calls are on the main thread, which means both
threads are effectively in the background.

However, in my multi-threaded version I put the main thread to sleep
for 0.3 seconds between checks. To see what I mean...

' // WebObjWrapper wraps the SOAP object
com.mycompany.webobject
' // and adds covenience functions for threading.
Dim qry1 As com.mycompany.WebObjWrapper
Dim qry2 As com.mycompany.WebObjWrapper
Dim thrd1 As System.Threading.Thread
Dim thrd2 As System.Threading.Thread
Dim time1 As System.DateTime
Dim time2 As System.DateTime

qry1 = New com.mycompany.WebObjWrapper("qry_1")
qry2 = New com.mycompany.WebObjWrapper("qry_2")

thrd1 = New Thread(AddressOf qry1.ThreadProc)
thrd2 = New Thread(AddressOf qry2.ThreadProc)

thrd1.Start()
thrd2.Start()

While (Not qry1.IsFinished Or Not qry2.IsFinished)
Thread.Sleep(300)
End While

ds1 = qry1.DataSet
ds2 = qry2.DataSet
MsgBox("Done")


Perhaps it's possible that in the asynchronous version, the main thread
is soaking up a lot more processing power?
 
U

usenetaccount

FYI for anyone that's curious:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenetchapt10.asp
Note You should not use asynchronous Web methods when accessing a
database. ADO.NET does not provide asynchronous implementation for
handling database calls. Wrapping the operation in a delegate is not an
option either because you still block a worker thread.

I'm not sure what's the difference internally (client OR server)
between making a synchronous and asynchronous call, but apparently
ADO.NET isn't happy with asynchronous calls.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top