I have to build a heartbeat system (i.e. some(about 10) nodes on a network send regular “heartbeats” every few seconds to a central node). These nodes are ubuntu machines. So what would you suggest for the following choices :
- TCP/UDP?
- Language/software to send the messages?
- Server architecture – multiple threads or multiple processes etc.?
The aim of the heartbeats is to quickly find any nodes that go down, or if nodes can’t communicate with the central server. Performance on the client nodes is an issue, so I don’t want to use java (because that would require installing a jvm).
PS: We may later need to also pass some text with the “heartbeat” messages, so we want to develop the system keeping that in mind.
A really simple one-directional “ping” application should suffice. I’d use a single UDP socket at the server, listing for incoming messages on port foo and send “i’m alive” messages from the clients with a single UDP socket at each client with
sendToin an infinite loop with asleep. No fancy threads/processes needed.You can distinguish the clients at the server either by their
recvFromaddress or by including a client id in the packet payload. You can then keep track of the last time each client sent a ping. You might need more than one thread on the server to make use of blocking receives while checking for timeouts. Or useselectand a small timeout/pause to poll the socket.Beej has an excellent guide how to do all of this in C: http://beej.us/guide/bgnet/output/html/multipage/index.html