Load balancing without Eureka in AWS ECS
kwiwon opened this issue · 1 comments
Hello,
I was hoping that route53 could cover the service-discovery part which it should be. So theoretically Zuul could use the service list to start to do load balancing. But looks like the routing will be hot-hitting the service instance 1 for a while, and then switching to the service instance 2.
After taking a look at the ribbon configuration, maybe the "listOfServers" could be the reason because it is not a list but just the server-id say "xxx.service.es".
So I tried to override the getUpdatedListOfServers()
in ConfigurationBasedServerList
like this
@Override
public List<Server> getUpdatedListOfServers() {
List<Server> listOfServers = super.getUpdatedListOfServers();
List<Server> newListOfServers = new ArrayList<>();
for (Server server: listOfServers){
try {
final InetAddress[] inetAddresses = SocketUtils.allAddressesByName(server.getHost());
for (InetAddress addr: inetAddresses){
newListOfServers.add(new Server(addr.getHostAddress(), server.getPort()));
}
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
if (newListOfServers.isEmpty()){
// There is no IP to be resolved, maybe the service is down. So return the same listofservers to have another chance to resolve.
return listOfServers;
}
// Sort the list so it can remain the same order so the Load Balancing Rule can keep the consistency
newListOfServers =
newListOfServers.stream().sorted(Comparator.comparing(Server::getHost)).collect(Collectors.toList());
return newListOfServers;
}
My idea is, instead of getting a single listOfServers
in configuration, I use that domain name to get all IP addresses so the LB rule can at least have a list to pick.
And with all others are default setting, I can see now Zuul starts to do round-robin LB.
Out of curiosity, is this the best way to work with route53? Or I have just misconfigured something like I shouldn't use listOfServers
.
Thanks for your time.