Making 10 POST requests from ASP.NET asynchronously

M

Mike C#

Hi all,

Is it possible to make 10 POST requests from ASP.NET asynchronously? I have
been working on this problem for a few days now, and I seem to keep running
up against IIS limitations. Basically here's the process as it works now
(synchronously):

Person visits mywebsite.com and fills out a form
mywebsite.com POSTs one request to providerwebsite.com
mywebsite.com receives response
mywebsite.com POSTs a second request to providerwebsite.com
mywebsite.com receives response
....
mywebsite.com POSTs a tenth request to providerwebsite.com
mywebsite.com receives response

What I would like to happen is (asynchronously):

Person visits mywebsite.com and fills out a form
mywebsite.com POSTs one request to providerwebsite.com
mywebsite.com POSTs a second request to providerwebsite.com
mywebsite.com receives a response to first request
....
mywebsite.com POSTs a tenth request to providerwebsite.com
mywebsite.com receives a response to ninth request
mywebsite.com receives a response to tenth request

The above is just an example - the responses should be able to arrive in any
order asynchronously. The problem is that each request can take up to 800
ms to respond, times 10 synchronous requests = 8 seconds... way too long...
The idea is that if I can send all ten requests asynchronously, the results
should start being returned much faster.

Is this even possible with ASP.NET and IIS?
 
P

Patrice

If 2.0 you could also try the Async methods of the WebClient object...

AFAIK if those requests are not seen by the external server as belonging to
the same session (which is likely the case unless you do something special),
it should work. I don't think you'll have this limitation on your own server
(as your server act as a client to the external web site).
 
J

John Saunders

Mike C# said:
Hi all,

Is it possible to make 10 POST requests from ASP.NET asynchronously? I
have been working on this problem for a few days now, and I seem to keep
running up against IIS limitations. Basically here's the process as it
works now (synchronously):

It is an IIS limit, as you say. It has nothing to do with ASP.NET.

The only ASP.NET relation is that you probably aren't calling Dispose on
your proxy objects, so you're not closing the connections.

John
 
J

Joerg Jooss

Thus wrote Mike C#,
Hi all,

Is it possible to make 10 POST requests from ASP.NET asynchronously?
I have been working on this problem for a few days now, and I seem to
keep running up against IIS limitations. Basically here's the process
as it works now (synchronously):

Person visits mywebsite.com and fills out a form
mywebsite.com POSTs one request to providerwebsite.com
mywebsite.com receives response
mywebsite.com POSTs a second request to providerwebsite.com
mywebsite.com receives response
...
mywebsite.com POSTs a tenth request to providerwebsite.com
mywebsite.com receives response
What I would like to happen is (asynchronously):

Person visits mywebsite.com and fills out a form
mywebsite.com POSTs one request to providerwebsite.com
mywebsite.com POSTs a second request to providerwebsite.com
mywebsite.com receives a response to first request
...
mywebsite.com POSTs a tenth request to providerwebsite.com
mywebsite.com receives a response to ninth request
mywebsite.com receives a response to tenth request
The above is just an example - the responses should be able to arrive
in any order asynchronously. The problem is that each request can
take up to 800 ms to respond, times 10 synchronous requests = 8
seconds... way too long... The idea is that if I can send all ten
requests asynchronously, the results should start being returned much
faster.

That is not likely -- the processing time for an individual request does
not improve by a client-side optimization. If resource contention comes into
play, it may even get worse. Yet, the overall processing time for the page
that kicks off those 10 requests should be reduced unless you have a severe
bottleneck in your system (such as a deadlock).
Is this even possible with ASP.NET and IIS?

The 10 connections limitation only applies for non-server Windows versions.
It is not an IIS issue per se.

For an asynchronous implementation of your web requests, look at asynchronous
pages, a feature introduced in ASP.NET 2.0: http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/

Cheers,
 
M

Mike C#

John Timney (MVP) said:
Have you looked up threading yet?

Not only did I look it up, I implemented it two different ways and both
times it crapped out with an error code 403, subcode 9.
 
M

Mike C#

Patrice said:
If 2.0 you could also try the Async methods of the WebClient object...

AFAIK if those requests are not seen by the external server as belonging
to the same session (which is likely the case unless you do something
special), it should work. I don't think you'll have this limitation on
your own server (as your server act as a client to the external web site).

1.1. Error 403.9 after 4 async requests. Thanks.
 
M

Mike C#

Thus sayeth Joerg Jooss,
That is not likely -- the processing time for an individual request does
not improve by a client-side optimization. If resource contention comes
into play, it may even get worse. Yet, the overall processing time for the
page that kicks off those 10 requests should be reduced unless you have a
severe bottleneck in your system (such as a deadlock).

I'm not trying to reduce the processing time for individual requests. That
is a constant I have no control over, like the speed of light. I am trying
to reduce the load time of my page by making 10 requests asynchronously
instead of 1 request...wait...1 response...1 request...wait...etc.
synchronously.
The 10 connections limitation only applies for non-server Windows
versions. It is not an IIS issue per se.

I ran into this particular problem on Windows Server 2003. I'm told by a
co-worker that there are some limitations built into the HTTP standard which
may be the root of my problem. He also suggested there is some registry
setting to get around it, but he couldn't tell me where he found this
information, so I'll keep Googling it.
For an asynchronous implementation of your web requests, look at
asynchronous pages, a feature introduced in ASP.NET 2.0:
http://msdn.microsoft.com/msdnmag/issues/05/10/WickedCode/

2.0 is not an option right now. Thanks.
 
M

Mike C#

John Saunders said:
It is an IIS limit, as you say. It has nothing to do with ASP.NET.

The only ASP.NET relation is that you probably aren't calling Dispose on
your proxy objects, so you're not closing the connections.

John

I'm properly disposing of everything, so it falls back to IIS? Thanks.
 
K

kferron

It seems like a few of us are jumping to conclusions without actually
seeing how you are attempting to enqueue the calls for async
invocation.
 
J

John Saunders

Mike C# said:
I'm properly disposing of everything, so it falls back to IIS? Thanks.

It still has nothing to do with IIS, especially not on Windows Server 2003.
IIS is not involved - the network message goes straight from HTTP.SYS into
the ASP.NET worker process (w3wp).
 
J

Joerg Jooss

Thus wrote Mike C#,
Thus sayeth Joerg Jooss,

I'm not trying to reduce the processing time for individual requests.
That is a constant I have no control over, like the speed of light. I
am trying to reduce the load time of my page by making 10 requests
asynchronously instead of 1 request...wait...1 response...1
request...wait...etc. synchronously.

I ran into this particular problem on Windows Server 2003. I'm told
by a co-worker that there are some limitations built into the HTTP
standard which may be the root of my problem. He also suggested there
is some registry setting to get around it, but he couldn't tell me
where he found this information, so I'll keep Googling it.

Ah, silly me. Forgot that all these requests access the same site.

Yes, HTTP 1.1 recommends to limit the number of persistent and non-persistent
connections to a site to 2 and 4 respectively. In ASP.NET, this value is
10 by default.

You can override this value using ServicePointManager.DefaultPersistentConnectionLimit
or in config:

<configuration>
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "2" />
</connectionManagement>
</system.net>
</configuration>

BTW, the registry keys you're looking for have been described in microsoft.public.dotnet.languages.csharp
just two days ago.

Cheers,
 
M

Mike C#

John Saunders said:
It still has nothing to do with IIS, especially not on Windows Server
2003. IIS is not involved - the network message goes straight from
HTTP.SYS into the ASP.NET worker process (w3wp).

I gave up on it and created a separate class that calls WinHTTP directly.
It's a lot more work, but it's fasssst.

Thanks.
 
M

Mike C#

Joerg Jooss said:
Ah, silly me. Forgot that all these requests access the same site.

Yes, HTTP 1.1 recommends to limit the number of persistent and
non-persistent connections to a site to 2 and 4 respectively. In ASP.NET,
this value is 10 by default.

You can override this value using
ServicePointManager.DefaultPersistentConnectionLimit or in config:

<configuration>
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "2" />
</connectionManagement>
</system.net>
</configuration>

BTW, the registry keys you're looking for have been described in
microsoft.public.dotnet.languages.csharp just two days ago.

Thanks Joerg. I went ahead and wrote a class to access WinHttp functions
directly. It's hella fast, and works great.
 

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

Top