Making 10 POST requests from ASP.NET asynchronously

Discussion in 'ASP .Net Web Services' started by Mike C#, Nov 14, 2006.

  1. Mike C#

    Mike C# Guest

    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?
    Mike C#, Nov 14, 2006
    #1
    1. Advertising

  2. Mike C#

    Patrice Guest

    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).

    --
    Patrice

    "Mike C#" <> a écrit dans le message de news:
    y6c6h.235$...
    > 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?
    >
    Patrice, Nov 14, 2006
    #2
    1. Advertising

  3. "Mike C#" <> wrote in message
    news:y6c6h.235$...
    > 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
    John Saunders, Nov 14, 2006
    #3
  4. Mike C#

    Joerg Jooss Guest

    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,
    --
    Joerg Jooss
    Joerg Jooss, Nov 14, 2006
    #4
  5. Mike C#

    Mike C# Guest

    "John Timney (MVP)" <> wrote in message
    news:...
    > 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.
    Mike C#, Nov 16, 2006
    #5
  6. Mike C#

    Mike C# Guest

    "Patrice" <> wrote in message
    news:emtNmn%...
    > 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.
    Mike C#, Nov 16, 2006
    #6
  7. Mike C#

    Mike C# Guest

    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.

    >> 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.


    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.
    Mike C#, Nov 16, 2006
    #7
  8. Mike C#

    Mike C# Guest

    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:u9myfH$...
    > "Mike C#" <> wrote in message
    > news:y6c6h.235$...
    >> 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


    I'm properly disposing of everything, so it falls back to IIS? Thanks.
    Mike C#, Nov 16, 2006
    #8
  9. Mike C#

    kferron Guest

    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.


    Mike C# wrote:
    > 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.
    >
    > >> 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.

    >
    > 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.
    kferron, Nov 16, 2006
    #9
  10. "Mike C#" <> wrote in message
    news:8bO6h.1097$...
    >
    > "John Saunders" <john.saunders at trizetto.com> wrote in message
    > news:u9myfH$...
    >> "Mike C#" <> wrote in message
    >> news:y6c6h.235$...
    >>> 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

    >
    > 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).
    John Saunders, Nov 16, 2006
    #10
  11. Mike C#

    Joerg Jooss Guest

    Thus wrote 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.
    >
    >>> 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.
    >>

    > 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,
    --
    Joerg Jooss
    Joerg Jooss, Nov 16, 2006
    #11
  12. Mike C#

    Joerg Jooss Guest

    Thus wrote Joerg,

    [...]

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


    Geez,

    make that "requests originate from the same site".

    --
    Joerg Jooss
    Joerg Jooss, Nov 16, 2006
    #12
  13. Mike C#

    Mike C# Guest

    "John Saunders" <john.saunders at trizetto.com> wrote in message
    news:...
    > 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.
    Mike C#, Nov 17, 2006
    #13
  14. Mike C#

    Mike C# Guest

    "Joerg Jooss" <> wrote in message
    news:...
    > 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.
    Mike C#, Nov 17, 2006
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yi
    Replies:
    3
    Views:
    5,480
  2. =?Utf-8?B?aW5ldG11Zw==?=
    Replies:
    0
    Views:
    449
    =?Utf-8?B?aW5ldG11Zw==?=
    May 27, 2005
  3. Rajiv Gupta
    Replies:
    0
    Views:
    706
    Rajiv Gupta
    Dec 8, 2005
  4. Mike C#
    Replies:
    14
    Views:
    620
    Mike C#
    Nov 17, 2006
  5. Replies:
    1
    Views:
    92
    Ian Wilson
    Nov 16, 2005
Loading...

Share This Page