How to make time-costing web service Asynchronous?

M

Morgan Cheng

I have one webservice that involves time-costing computation. For each
request, it consumes about 2 seconds computation. Since ASP.NET has 25
threads per CPU to handle requests, this delay turns to be bottleneck
if webservice is synchronous. Say, the webserivce is called ABC, then
one thread is arranged for one call to ABC, and the thread is not
released until the result is returned.

I once configured to implement it as Asynchronous webmethod. That is,
implement BeginABC and EndABC webmethod. But, it seems asynchronous
webmethod only fit for handle I/O or invocation to other webservice.
The time-costing computation is local and is not I/O. So,
Delegate.BeginInvoke is used; but this also involves ThreadPool and no
benefits at all.

Any idea to design such time-costing-computation webserivce with high
throughput?
Thanks in advance.
Morgan
 
B

bruce barker

if the work can not be sent to another server, then starting a new
thread only makes it worse.

as long as you have more threads than cpus you will max the throughput.
if you want the waits to be less queued (but longer for each request)
then bump up the number of asp.net threads. you overall thoughput will
be less (more context switches), but the request will be served fairly.

as you are compute bound there is no magic bullet. say you have a 4 proc
server, and 12 concurrent request. you have 24 secs of cpu, which can be
done in 6 secs if all 4 procs work at the same time. if you had 4
threads, then request would take 2 secs to process and be first come
first served. so some would be return in 2 secs, some in 4 secs, and
some after 6. if you had 12 threads, then all would return after 6 seconds.


your best bet is to lower the cost to < 1 sec by recoding the computation.

-- bruce (sqlwork.com)
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top