I need to develop a real-time (i.e., info is requested and received at least once per second) monitoring application in Delphi, which monitors multiple remote devices (can be hundreds). The communication is via TCP/IP.
I am looking for advice to develop this app avoiding 100% CPU consumption and minimizing the amount of RAM used. In other words, I want my application to remain responsive and not block the system or consume all resources.
My main concern is about using threads for monitoring each remote device. Is there a limit to the number of threads my application can create? Can the threads can be started using a low or medium priority to minimize the CPU consumption?
Advice about optimal memory usage is welcome, too.
Your instinct is right, you want to handle the logging in threads outside of the main thread. Create a simple tcp/ip server that creates a new thread for the incoming connection and handles the logging there. Obviously you'll want to do things like track each thread to be able to terminate it when your server application closes, and possibly implement a thread pool/queue if you want to re-use them rather than constantly creating and destroying them. But what you describe is actually a fairly simple server application in concept. There's no hard and fast limit to the # of threads you can create. But unless the connections are constant and kept open, you may be suprised how few actually get created simultaneously.
Good luck doing this yourself. I have invested a couple of years to develop a generic platform to do just this. If you want you can have a look at it here. At the very least you will need to use some comms components that already work very reliably, such as RemObjects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With