I have an application that performs HTTP posts at regular intervals (data retrieved from SQL). Every 30 seconds a maximum of 50 threads are spawned and run HTTP posts concurrently. If a post fails, it waits 2x as long as the interval is set to. This will happen twice. So for instance, 30s, 60s then 120s.
I am using a normal Thread.Start() to get this process rolling, however I have found that on the live server, it completely annihilates the CPU.
My questions are as follows:
- Is there a better class to use for thread performance?
- Is there a way to limit a threaded applications CPU usage in .NET?
Thanks,
Kyle
You should not be using threads for running multiple I/O streams. Since those threads are mostly blocking on I/O, you can more efficiently do this use non-blocking or asynchronous I/O. Instead of having one thread talk with one server, you have one thread talk with N servers.
Since you are using HttpWebRequest, you want to look at HttpWebRequest.BeginGetResponse and HttpWebRequest.BeginGetRequestStream.