Implement heartbeat and measuring latency