1

Task: I'm using static classes, so everyone shares data that's been already loaded. If someone makes a change, that request will put an item in a list with an incremental ID, and my idea would be that every client has it's version on client side and requests if there's any change.

My solution: For this I use a $.post with a timeout of 5000ms and sending the client version, on server side I have a 500 cycle for loop which checks if there's something newer and breaks the loop, returns the changes and have a 10ms Thread.Sleep in every cycle so it wouldn't hog the cpu. Either if on the client it times out, has an error, I call the post again, if it succeeds I process the return data, than call the post again. This way I always should get the changes almost instantly without an overwhelming number of requests, and if something fails, I only need to wait 5secs for it to resume.

My problem is that when this loop runs, other requests aren't handled. With asp.net development server, that's okay, because it's single threaded. But that's also the case with win7hp iis7.5.

What I tried: Set it in the registry (HKLM\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0\MaxConcurrentRequestsPerCPU), increasing the worker threads for the application pool, updating the aspnet.config file with maxConcurrentRequestsPerCPU="12" maxConcurrentThreadsPerCPU="0" requestQueueLimit="5000" settings, and I also read that my win7hp should be able to use 3 threads. I also thought it's an optimization, that I use same variables in one request so it queues the others, so I commented those lines, left the for loop with the sleep only, but same result.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
user1269009
  • 463
  • 3
  • 13
  • Please consider formatting future questions with more than single paragraph... – Alexei Levenkov Jul 05 '12 at 08:01
  • How many users do you want to support simultaneously? (1-10, 10-100,100-1000, >1000) How big is the data set that you are passing to the client? does "sending the client version" mean the "incremental ID" or the whole data set? – Jason Hernandez Jul 07 '12 at 00:03
  • It would be an internal syncing for a company so, between 10-100 would be sufficient. And I only want to send changes, so below 1KB responds – user1269009 Jul 10 '12 at 06:59

1 Answers1

1

Don't use Thread.Sleep on threads handling requests in ASP.Net. This will essentially consume thread and prevent more requests to be started. There is restriction on number of threads ASP.Net will create to handle requests that you've tried to change, but high number of threads will make process less responsive and can easily cause OutOfMemeoryException for 32bit proceses - so it is not a good route.

There are several other threads discussing implemeting long poll requests with ASP.Net like this one - Can ASP.NET MVC's AsyncController be used to service large number of concurrent hanging requests (long poll)? and obviously Comet questions like this - Comet implementation for ASP.NET?.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • I've tried increasing the worker threads as I said, but resulted in hanging requests also. I'm expecting it to handle other requests even though that one requests is working (or sleeping) – user1269009 Jul 05 '12 at 08:40
  • I looked into the suggested links. I've tried websync, and saw that it does the same thing, that it starts a query and when a message comes, it immediately returns (and creates a new query), if it times out it just starts a new query. Is it really that hard to handle other queries while this waits for a message to send? – user1269009 Jul 05 '12 at 10:54