Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Heartbeat Size #9

Open
ryanhlewis opened this issue Jun 21, 2021 · 1 comment
Open

Heartbeat Size #9

ryanhlewis opened this issue Jun 21, 2021 · 1 comment

Comments

@ryanhlewis
Copy link
Contributor

As far as I can tell using this relay, connections are made and stay alive for approx. 55 seconds before they are deemed "idle" and closed. This is prevented by the use of the heartbeat signal made every five seconds, as seen in your code.

const HEARTBEAT = JSON.stringify({ type: 'Heartbeat' })
this.heartbeat = setInterval(() => socket.send(HEARTBEAT), 5000)

My question is, if this is a relay server and intended to have minimal load and bandwidth between the connections, would it not be better to send off a Heartbeat message as something incredibly short (1 bit?).

It doesn't even have to be proper JSON, as it would simply be ensuring that a connection exists.

The heartbeat receiver and the default unknown data receiver both essentially return the same output:

case 'Heartbeat':        // nothing to do       
this.log('♥')        
break

default:        
break

Am I overthinking this? Is the small bit difference between a "{ type:'Heartbeat' }" string and a 0/1 negligible?
Does the understanding behind knowing a heartbeat signal is being received outweigh the tiny increase in possible performance or bandwidth?

Thanks,

@okdistribute
Copy link
Contributor

okdistribute commented Jun 21, 2021

In general I agree, perhaps the whole protocol could also be more efficient to not use JSON and use something like protobuf (or whatever is the latest and greatest) instead. This is more refactoring to do and would be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants