airbnb / synapse

A transparent service discovery framework for connecting an SOA
MIT License
2.07k stars 251 forks source link

Reduce zk calls with enhanced zk event processing #331

Closed gmcatsf closed 4 years ago

gmcatsf commented 4 years ago

Summary

Current ZookeeperWatcher's watch_callback accepts zk event as parameter but ignores it during processing. Every time a zk event is received, watch_callback does all three things regardless of which zk event:

But each zk event always contains single change(e.g. child and data event are mutually exclusive) and performing all three calls above are not necessary. For example below are a list of methods supported on zk event:

This PR adds a few boolean checks to handle children change and data change separately, and should reduce three zk calls to one in most cases since children change is the most frequent ones.

During watch startup, the three calls will still be executed to read data and set watches in zk.

Test

Reviewer

@airbnb/traffic @panchr @austin-zhu @Jason-Jian

gmcatsf commented 4 years ago

@austin-zhu could you please help check the code change?