I have an app that communicates with up to 50 devices over serial ports. The communication takes place in threads, and the threads are throttled so that only a certain number are active at once. The threads are created as required, do their work, and terminate and free their used resources.
In some instances the serial ports are implemented with Moxa TCP/IP Ethernet ports. A Moxa driver runs on the PC which exposes the Moxa devices on the network as a COM Port.
In other cases the serial ports are implemented via USB hubs that provide 10 serial ports each.
Here's the problem. When only the Moxa serial ports are used, and (say) 8 are enabled, the CPU usage of the app wavers between 1% and 30%, depending on how many threads are active. The app behaves sensibly and the PC is responsive.
When 8 USB ports are then enabled, the CPU usage of the app peaks at 50-60% as I would expect, but the total PC CPU usage climbs to near 100% and stays there. Not surprisingly everything grinds to a halt.
I used Process Explorer and found that the bulk of the CPU usage outside of my app was in two tasks - System Idle Process/DPCs (Deferred Procedure Calls) and System Idle Process/System. The usage in these tasks peaks at around 40% each. When only Moxa ports are in use, these tasks show no significant CPU usage.
I've tried messing with the thread priority and it makes no difference. The ports run at a relatively low baudrate (2400).
Running a DPC latency checker tool shows up to 6ms latency when the USB serial ports are in use.