spring-cloud / spring-cloud-consul

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

Make profile specific context paths optional to improve performance #787

Closed DanielYWoo closed 1 year ago

DanielYWoo commented 2 years ago

Is your feature request related to a problem? Please describe. Provide a flag to disable profiles. e.g., currently we always have a default profile appended, so typically we watch 4 paths for a normal application:

config/testApp,default/
config/testApp/
config/application,default/
config/application/

In our deployments we have 40+ data centers to support 150M users, we have so many requests to Consul that we have to keep it lean, and we want to remove the profile-specific paths and only keep two of them:

config/testApp/
config/application/

Describe the solution you'd like After reading the source code it seems we can do it in ConsulPropertySources.generateAutomaticContexts(...) to skip the calls to addProfiles(). I propose to have a flag likespring.cloud.consul.config.profileEnabled, and default to true to keep it compatible with the current behavior. e.g.,

if (properties.isProfileEnabled()) {
    for (String suffix : suffixes) {
        addProfiles(contexts, defaultContext, profiles, suffix);
    }
}

Describe alternatives you've considered We can tune waitTime and delay to make our services have less pressure on Consul, but it sacrifices the latency, and we still want to detect changes fast enough. By removing the profiles we can get rid of 50% of unnecessary traffic to Consul, which sounds like a low-hanging fruit. If you agree with this option, I can raise a PR.

Additional context N/A

spencergibb commented 1 year ago

Closing in favor of #788