wankdanker / node-discover

Automatic and decentralized discovery and monitoring of nodejs instances with built in support for a variable number of master processes, service advertising and channel messaging.
229 stars 59 forks source link

performance: Cache hello packet encoding/decoding #40

Closed aikar closed 4 years ago

aikar commented 4 years ago

Hello packets for the most part will never change. JSON and encryption are blocking operations that occur some performance cost to use.

We can cache our outgoing hello packet, and clear the cache anytime the payload is expected to be manipulated by .advertise().

Likewise, we can cache received hello messages based on IP+Port+data.

The size of these messages are small and should result in negligible memory increase, but at the benefit of a major reduction in CPU cost to avoid repeatedly calling encrypt/encrypt and JSON stringify/parse.

In a large ensemble of nodes, this can add significant CPU reduction.

aikar commented 4 years ago

not sure how I ended up duplicating this.