spring-cloud / spring-cloud-consul

Spring Cloud Consul
http://cloud.spring.io/spring-cloud-consul/
Apache License 2.0
805 stars 543 forks source link

Catalog Watch uses blocking queries incorrectly #827

Open kisunji opened 11 months ago

kisunji commented 11 months ago

Hello, I'm working on Consul and have seen several users face issues around how spring-cloud-consul interfaces with Consul so I've been trying to investigate.

I've noticed that spring-cloud-consul-discovery polls the Consul catalog very frequently with short-lived blocking queries (specifically the call to /v1/catalog/services?wait=2s&index=<index> at default 1s intervals).

The intention for blocking queries is that you wait on one connection which will hold until any catalog changes are detected by the agent. It is meant to be an efficient alternative to frequent polling.

It should be enough to make one call to /v1/catalog/services?index=<index> without the default deadline of wait=2s. In fact, removing the ?wait= would drastically reduce the network traffic to Consul clients with no impact to service discovery.

kisunji commented 11 months ago

A solution could be to make the default catalogServicesWatchTimeout -1 and only add timeout to the catalog request if the value is > 0.