마이크로서비스 소개 pt. 4
목차
3부에서는 에 대해 이야기했습니다. 이제 게이트웨이를 개선하고 Service Registry에서 제공하는 여러 인스턴스의 가능성을 활용할 것입니다.
우리는 무엇을 해결하려고 합니까?
So far, we've implemented an API Gateway that receives all the requests and routes them accordingly. Also, our services/instances are registered with our Service Registry and the Gateway checks the service's location with it. But how can we make so that our Gateway uses all available instances of a service and no instance becomes overloaded?
솔루션: 로드 밸런서
To insure that, we need to implement a Load Balancer. This pattern will leverage the requests between available instances of our services. Ocelot gives us a simple way to implement a Load Balancer. Also, it provides a few different algorithms of load balancing:
- Round Robin - Imagine that you have three instances of a given service. The algorithm will make so that the first request is handled by instance #1, the second by instance #2, the third by instance #3, the fourth by #1 again, and so on;
- Least Connections - Every new request is sent to the instance with the least amount of active connections;
- Cookies Sticky Sessions - Uses a cookie to direct all request to a specific instance.
IMPORTANT: Keep in mind that other load balancing solutions might have different algorithms.
코드를 보여주세요
To implement our Load Balancer, Ocelot makes it very easy. All we need to do is add a new property to our 'ocelot.json' file. This property needs to be added on a route per route basis:
{
"Routes": [
{
// ...
"LoadBalancerOptions": {
"Type": "RoundRobin"
}
},
{
// ...
}
],
// ..
}
That's it! Our API Gateway can now balance the load between all of our services instances!
On the next article, we'll talk about the pattern. Until next time.
서지
Reference
이 문제에 관하여(마이크로서비스 소개 pt. 4), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/bernas1104/an-introduction-to-microservices-pt-4-5he2텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)