I have a C#.NET application that needs to inform anywhere from 4000 to 40,000 connected devices to perform a task all at once (or as close to simultaneous as possible).
The application works well; however, I am not satisfied with the performance. In a perfect world, as soon as I send the command I would like to see all of the devices respond simultaneously. Yet, there seems to be a delay as all the threads I have created spin up and perform the task.
I have used the .NET 4.0 ThreadPool, created my own solution using custom threads and I have even tweaked the existing ThreadPool to allow for more threads to be executed at once.
I still want better performance and that is why I am here. Any ideas? Comments? Suggestion? Thank you.
-Shaun
Let me add that the application notifies these ‘connected devices’ that they need to go listen for audio on a multicast address.
A dual-core hyperthreaded processor MAY be able to execute 4 threads simultaneously – depending on what the thread is doing (no contention on IO or memory access, etc). A quad-core hyperthread perhaps 8. But 40K just can’t physically happen.
If you want near simultaneous, you’re better off spinning up just as many threads as the computer has free cores and having each thread fire off notifications then end. You’ll get rid of a bunch of context switching this way.
Or, look elsewhere. As SB recommended in the comments, use a UDP multicast to notify listening machines that they should do something.