Search code examples
asp.net-mvc-3iis-6long-polling

Unable to service 20+ connections MVC3 IIS6 w long polling


It seems this is a common question/problem but despite checking out a number of proposed solutions nothing worked for us so far.

The app

It's a simple chat app, that puts a new interface on an existing app's JSON library. We proxy all the calls to their app to avoid x-domain restrictions (IE8). ASP.net MVC3 App;

It's hosted in IIS6, W2K3 SP2. DEV svr has 1gig ram, TEST svr has 4gig ram.

The problem

When we approach 20 concurrent users, requests start lagging - no issues in Event Viewer to be found. It looks like calls are just queued. There are NO 503's returned.

What we've tried

  • We're using AsyncController to long-poll a 3rd party webservice for results Hosted in IIS6
  • We're using the TPL to call their service in our AsyncController method
  • We've modified processModel and set maxWorkerThreads=100.
  • We've looked at this how-to but the HTTP.SYS config looks to service an infinite number of threads so we haven't bothered adding the reg keys.
  • The 3rd party service can handle lots of concurrent requests (and is in a web farm, so we're fairly confident we're the weakest link)

what are we missing? - any help greatly appreciated


Solution

  • Well... almost four weeks later and I thought I'd update this in case anyone wants to find out what helped us overcome these limitations (we're cramming around 100 simul connections on our DEV server, 1gig Xeon).

    AsyncControllers

    • If you've got a potentially long waiting request (i.e. long polling) then use them.
    • Feel free to use TaskFactory but be sure to mark it as a long running process, if there is risk you could exception in your thread, be sure to use ContinueWith so you can decrement the operations, and return the error to your caller.

    ServicePointManager

    • If you're making downstream calls (i.e. WebService/3rd party API) then make sure you have increased DefaultConnectionLimit from the default of 2 simultaneous connections.
    • A rough guide is 8 * Num cores so you don't starve outgoing connection resources.
    • See this MSDN article on DefaultConnectionLimit for more info.

    IOCP vs RestSharp

    In the end, our issue wasn't with incoming requests, it was with requests being proxied to a third party, we weren't supplying enough connections and thus they all queued up lagging the whole system. Happy to say after lots of reading, investigation and coding we've resolved it.