Reduce the number of allocations in heartbeater

Use bytearray to receive server heartbeat instead of a newly allocated
string.  This reduces the number of allocations and garbage-collections,
which helps with memory performance, as the daemon may sit there working
for days or even months.
Flatten the call stack to unwind "rich" functions.