Skip to content

High concurrency, NamedCextFactory.getContext will result in a large number of blocks #4021

@Burt-L

Description

@Burt-L

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

Blocked jstack:
Image

org.springframework.cloud.gateway.filter.ReactiveLoadBalancerClientFilter#choose:
Image

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

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

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions