-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Description
Describe the bug
When Spring Cloud Gateway is first launched, NamedCextFactory.getContext has a lock; The creatContext method calls context.refresh, which has a lock and is very time-consuming. High concurrency can lead to a large number of blocked items.
Sample
org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter#choose:

org.springframework.cloud.context.named.NamedContextFactory#getContext:

org.springframework.cloud.context.named.NamedContextFactory#createContext:

My Gateway has 10000 routes, including 3000 services, all of which are registered on Nacos. When Spring Cloud Gateway is first launched, the first request from each service, ReactiveLoadBalancerClientFilter will call NamedCextFactory.creatContext. When the concurrency of a service is high, all subsequent requests (reactor-http-nio threads) will be blocked at NamedCextFactory.getContext until the lock is released. The context.refresh in creatContext is very time-consuming, resulting in a large number of request timeouts. After the Gateway was started, I actively called the clientFactory.getInstance (serviceId) to warmup it. The clientFactory is org.springframework.cloud.loadbalancer.support.LoadBalancerClientFactory, but due to a lock, it is very slow and affects the service startup time. Moreover, because there are many business services, it is impossible to warmup all services.
I hope this point can be improved. Thank you!
I have reviewed the latest version of Spring Cloud code and this issue has not been resolved.
