Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yarp is greatly affected by downstream services #2582

Open
zhenlei520 opened this issue Aug 26, 2024 · 4 comments
Open

Yarp is greatly affected by downstream services #2582

zhenlei520 opened this issue Aug 26, 2024 · 4 comments
Assignees
Labels
Type: Bug Something isn't working
Milestone

Comments

@zhenlei520
Copy link

Describe the bug

When the response time of the downstream service of the reverse-proxy service fluctuates, the CPU fluctuation is very obvious

To Reproduce

Downstream.zip

  1. Deploy Downstream on a Windows machine
  2. Deploy the reverse-proxy service on the Linux server, and point the proxy address to the Downstream service on the Windows machine.
  3. Use hey or other stress testing tools to stress test the reverse-proxy service according to the specified qps
  4. By changing the sleep time of Downstream, check the CPU fluctuation of reverse-proxy service.

img_v3_02e4_6a73b5ff-ad9f-4097-9b08-5598cecfe6ag
Reproduce the problem
It is found that the service where reverse-proxy is located is greatly affected by the downstream. When the downstream service responds slowly, the QPS of the reverse-proxy service will decrease, and the corresponding requests being processed will increase. When the downstream service returns to normal, the CPU of the reverse-proxy service increases rapidly. In other words, the reverse-proxy service is greatly affected by the downstream. I hope that the CPU can be more stable, even if the CPU is occupied in advance, the same principle applies to threads. I don’t want the CPU to surge or plummet when there is a burst of traffic, because the response time of the downstream service is completely uncontrollable. How to deal with this problem?

Further technical details

  • Include the version of the packages you are using
  • Downstream
    • deploy Windows System
    • .net version: .net 8.0
  • reverse-proxy
    • deplpy Linux System
    • .net version: .net 9.0
@zhenlei520 zhenlei520 added the Type: Bug Something isn't working label Aug 26, 2024
@zhenlei520
Copy link
Author

zhenlei520 commented Aug 26, 2024

The reverse-proxy service only adds

ThreadPool.SetMinThreads(200, 200);
ThreadPool.SetMaxThreads(1000, 1000);

and does not do any other processing. I want to know how I can make the CPU usage of the reverse-proxy service more stable.

@microsoft microsoft deleted a comment Aug 26, 2024
@microsoft microsoft deleted a comment Aug 26, 2024
@MihaZupan
Copy link
Member

Did you see a positive change after setting the min/max threads configuration / why is it necessary?

Generally, as long as you're not doing any blocking, you shouldn't need that many threads as handing a request from YARP's perspective is fully async.

Linking other threads in runtime for reference: dotnet/runtime#107017, dotnet/runtime#107013

@zhenlei520
Copy link
Author

zhenlei520 commented Aug 27, 2024

Did you see a positive change after setting the min/max threads configuration / why is it necessary?

Generally, as long as you're not doing any blocking, you shouldn't need that many threads as handing a request from YARP's perspective is fully async.

Linking other threads in runtime for reference: dotnet/runtime#107017, dotnet/runtime#107013

What I hope is that after setting MinThreads, when the downstream response time fluctuates and causes the reverse-proxy service to be blocked, more threads can be quickly started to help process the accumulated requests faster. But in fact, the MinThreads I set does not have much effect. I don’t know if this is related to connection reuse. And when the downstream response time becomes faster, fewer threads are blocked and fewer threads are needed to handle the problem. At this time, the threads in the thread pool will quickly decrease. I don’t know what I should do at this time to make the CPU of the reverse-proxy service more stable. The response time of the downstream service is not controllable by reverse-proxy service.

@zhenlei520
Copy link
Author

The reason why I set MinThreads is that when reverse-proxy is blocked, it takes several minutes to create threads, and the corresponding CPU fluctuations are relatively large at this time. I hope that setting MinThreads can avoid wasting more time on thread creation and hope to process the blocked requests as soon as possible.

@MihaZupan MihaZupan added this to the Backlog milestone Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants
@zhenlei520 @MihaZupan and others