Archived
This forum has been archived. Please start a new discussion on GitHub.
Custom Locator
Hi,
I am interested in using IceGrid allocate resources from a cluster of nodes using a custom load-balancing metric. It seems that the best way to do this would be to write a custom locator. Is there an example of how to create a custom locator?
If I were to use the built-in IceGrid allocator to do the custom load-balancing my understanding is the I would have to do something like the following which seems non-optimal. Is this correct?
Thanks
Client side using findAllReplicas
// Custom load-balancing
Ice::ObjectPrx proxy = communicator()->stringToProxy("DemoIceGrid/Query");
IceGrid::QueryPrx query = IceGrid::QueryPrx::checkedCast(proxy);
Ice::ObjectProxySeq seq = query->findAllReplicas(obj);
// Call each proxy and get it's health. Select the healthiest
HelloPrx healthiestObj = NULL;
Ice::Int health = 0;
for(Ice::ObjectProxySeq::iterator ii = seq.begin(); ii != seq.end(); ++ii) {
HelloPrx hObj = HelloPrx::checkedCast(*ii);
if (hObj) {
Ice::Int h = hObj->getHealth();
if (h > health)
{
health = h;
healthiestObj = hObj;
}
}
}
I am interested in using IceGrid allocate resources from a cluster of nodes using a custom load-balancing metric. It seems that the best way to do this would be to write a custom locator. Is there an example of how to create a custom locator?
If I were to use the built-in IceGrid allocator to do the custom load-balancing my understanding is the I would have to do something like the following which seems non-optimal. Is this correct?
Thanks
Client side using findAllReplicas
// Custom load-balancing
Ice::ObjectPrx proxy = communicator()->stringToProxy("DemoIceGrid/Query");
IceGrid::QueryPrx query = IceGrid::QueryPrx::checkedCast(proxy);
Ice::ObjectProxySeq seq = query->findAllReplicas(obj);
// Call each proxy and get it's health. Select the healthiest
HelloPrx healthiestObj = NULL;
Ice::Int health = 0;
for(Ice::ObjectProxySeq::iterator ii = seq.begin(); ii != seq.end(); ++ii) {
HelloPrx hObj = HelloPrx::checkedCast(*ii);
if (hObj) {
Ice::Int h = hObj->getHealth();
if (h > health)
{
health = h;
healthiestObj = hObj;
}
}
}
0
Comments
-
Hi,
Yes, there's currently no way to add a custom load balancing strategy to the IceGrid registry (as a plugin for example). This is something we could add however if you have a commercial interest for such a feature. If that's the case, please contact us at info@zeroc.com
Otherwise, you'll need to implement this yourself. You can implement it like you described. Another solution would be for your services to push health information to a load balancer service and have your clients use this load balancer service to retrieve the "best" replica.
Cheers,
Benoit.0