Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make my application behave well while monitoring hundreds of real-time devices?

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.

like image 758
Salvador Avatar asked May 03 '11 19:05

Salvador


2 Answers

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.

like image 131
GrandmasterB Avatar answered Sep 17 '22 13:09

GrandmasterB


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.

like image 38
Misha Avatar answered Sep 21 '22 13:09

Misha