What would be the way of going about creating a heartbeat table server side to monitor response times to each of the servers clients. I have been exploring this but am unsure on how to send a message from server to client and only know how to do client to server messages. To measure response time I can use a timer just unsure on how to go about sending the message?
Hi,
Is there a specific reason for server>client?
I have tried to cover both below, hopefully it is at least a starter for you and helps..
q)/server process
q)\p 50001
q)/ heartbeat table to log hbs
q)heartbeat:([host:$();port:
long$()];hdl:int$();lastPing:
timestamp$();pings:long$()) q)/function to log hearbeat on server q)registerHeartBeat:{[hst;prt]
heartbeat upsert (hst;prt;.z.w;.z.p;)1+0^first exec pings from heartbeat where host=hst,port=prt }
q)/client process
q)\p 50000
q)/ hdl to server
q).R.Server:hopen ::50001 q)/ send heartbeat from client to server q)sendHeartBeat:{ .R.Server (
registerHeartBeat;.z.h;system “p”)}
q)/ call send a heart beat from client to server
q)sendHeartBeat / this could be on a timer
`heartbeat
// check on the server
q)heartbeat
host port | hdl lastPing pings |
---|---|
desktop 50000 | 9 2022.03.04D12:31:48.583133000 1 |
/ initiating from server side
/ have each client process register with the server on startup (for this I have just manually called sendHeartBeat from client)
/ to add hdls to heartbeat table
q)/ callback type idea to initiate a registerHeartBeat call
q)reportToServer:{ .z.w (registerHeartBeat;.z.h;system "p")} q)/ this function on server would request a heart beat from each hdl in the heartbeat table q)getHeartBeatFromServer:{ (exec distinct hdl from heartbeat)@\:(reportToServer;
)}
q)/ call above function, which could be on a timer
q)getHeartBeatFromServer
,`heartbeat
q)heartbeat
host port | hdl lastPing pings |
---|---|
desktop 50000 | 9 2022.03.04D12:33:28.583133000 2 |
Thanks
Hey Patrick, thanks again for the detailed response its much appreciated, I believe it is requested to be done server side so no setup has to be done client side regardless of which clients are connecting in.
Yea Ok, that’s a fair point. In that case hopefully the 2nd point above helps get you started… if not let me know.
thanks