spring-cloud / spring-cloud-stream

Framework for building Event-Driven Microservices
http://cloud.spring.io/spring-cloud-stream
Apache License 2.0
988 stars 603 forks source link

StreamBridge is a singleton, and its send() method has performance issues. #2976

Closed imgoby closed 1 week ago

imgoby commented 1 month ago

Describe the issue

During high concurrency, StreamBridge's send() calls are frequent, and the internal synchronization of send() prevents applications from fully utilizing the multi-core capabilities of the CPU.

To Reproduce Steps to reproduce the behavior:

  1. Run a application built Spring Cloud Stream and RocketMQ,Spring Cloud Stream Version:
   <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream</artifactId>
      <version>4.0.0</version>
    </dependency>
  1. Message concurrency is 10000 messages per second
  2. We can see : thread wait (blocked) in the StreamBridge's send() method image

Additional context I tried to increase the number of instances of StreamBridge through certain methods, and CPU usage began to rise. Concurrent performance improves.

So,I know :Default situation,StreamBridge is a singleton, and its send() method has performance issues.

Does spring cloud stream team know this issue? Can it be optimized?

sobychacko commented 1 month ago

@imgoby Thanks for the report. We will triage the issue and get back to you.

olegz commented 1 week ago

You can set it to async. StreamBridge.setAsync() and then your sends will be asynchronous

olegz commented 1 week ago

I am closing it as an answered question. If you still believe there is an issue please describe and more details and we'll reopen

imgoby commented 1 week ago

there is not setAsync() method in spring cloud 2022.

olegz commented 1 week ago

Please upgrade ;)

imgoby commented 1 week ago

OK,Thank you