2

We deploy two service instance in difference machine using CXF distributed OSGi. we want to give the system the load balancing feature. All we know the OSGi don't provide any load balancing feature. Does anyone know how to do it ?

2 Answers2

2

Load balancing is a concern that is meant to be implemented by the Topology Manager (TM). It would be useful to read the Remote Services Admin specification, which addresses exactly this kind of question.

As far as I know, the CXF implementation of Remote Services only implements a single TM, which is "promiscuous", i.e. it publishes every available service in every listening framework. It is possible however to write your own TM to perform load balancing and failover etc.

The Remote Services spec is written in such a way that a TM implementation can be developed completely independently of any specific Remote Services implementation.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • Hi Neil, this sounds like a good enhancement even for the default TopologyManager of CXF DOSGi. I am not sure though how it would work. Would the TopologyManager create a service proxy that implements the loadbalancing / failover logic? – Christian Schneider Jul 21 '13 at 18:01
  • @ChristianSchneider Essentially yes.... remember that all Remote Services are proxies by nature. However it's difficult to do load balancing generically. How will you measure the load? There are many and various ways of measuring load, and of course it can fluctuate rapidly as well. – Neil Bartlett Jul 21 '13 at 18:31
  • Hi, @NeilBartlett , it mean that I have to implements my own TM to do load balancing, isn't it? Right now, I want to access my remote services using Round-Robin algorithm. How to implement it? My idea is:1.get the available services via ServiceTracker.getServices(); 2. access the service iteration. Is that correct? I am lack of experience for load balancing thing. :) – Allen Xudong Cheng Jul 22 '13 at 02:52
0

You should be able to get the complete list of services using a ServiceTracker. So a nice way to create a load balancer should be to create a proxy service yourself that does the load balancing and publish it locally as a service with a special property. So your business application can use the service without knowing anything about the details of load balancing.

Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Yes, that is the goal I want to achieve. How about create a proxy bundle, it pulish a service, e.g. queryInLoadBalancing(), which will get two instance of query() service and do some load balancing stuff, e.g. Round-Robin, etc. – Allen Xudong Cheng Jul 22 '13 at 11:33
  • I would use the original interface of the service you proxy. So your business logic does not have to know it talks to a special proxy. By using a property to mark the load balancing service your business logic can filter for the special service to not get the unproxied ones. – Christian Schneider Jul 22 '13 at 12:05
  • ServiceTrackers can only see locally published services, so this solution makes 2 big assumptions. First, the TM is promiscuous and therefore all remote services are visible locally. Second, that the TM pulls through some kind of load information into the properties of the local service proxies. Really the TM is the right place to do load balancing since it has visibility of Endpoint attributes that are not necessarily reflected in the service proxy. – Neil Bartlett Jul 23 '13 at 01:34
  • @NeilBartlett , thus you suggestion is that implementing my own TM like CXF to handle the communication between the service and service endpoint instead of using another service to proxy them? – Allen Xudong Cheng Jul 24 '13 at 01:48
  • You should be able to use the source code of the CXF TM as a starting point if you want to go this way. If you have some ideas how to integrate load balancing into the CXF TM we can discuss them on the CXF list. Of course you can also just create a special implementation for your case. – Christian Schneider Jul 24 '13 at 23:13
  • Hi @ChristianSchneider , you are working on CXF D-OSGi, aren't you? Thus you mean the D-OSGi is using the CXF TM feature? I have done some research on Google, some guy have say he can enable the load balancing and failover in Apache CXF(Link: http://www.javacodegeeks.com/2011/06/apache-cxf-load-balancing-failover.html and http://nurkiewicz.blogspot.com/2011/05/enabling-load-balancing-and-failover-in.html). Do you think this configuration is working for D-OSGi? – Allen Xudong Cheng Jul 25 '13 at 02:30
  • Unfortunately this will not work out of the box. DOSGi creates one OSGi service per endpoint. For the described configuration you would need one CXF client with several endpoints configured. Btw. while DOSGi does not support load balancing it already supports failover if that is you main concern. – Christian Schneider Jul 25 '13 at 05:51
  • Thanks, @ChristianSchneider , and how to enable the failover feature of DOSGi? Is there any document or tutorial? By the way, is any plan to implement load balancing in DOSGi? Right now, I thinks the best solution for me is create a load balancing version service to handle this thing. – Allen Xudong Cheng Jul 25 '13 at 08:23
  • The failover should work if you use for example blueprint to bind a service using reference. Blueprint will install a proxy instead of the plain service. This proxy will detect if the bound OSGi service goes away and switch to another if it is present. So this is handled by blueprint. @NeilBartlett I hope this is correct. Please correct me if I am wrong. – Christian Schneider Jul 25 '13 at 08:34
  • It's not quite that simple. If TM knows that the remote service is gone then it can unpublish the local proxy. If not (e.g. network fail) then the proxy remains in place and the client only finds out when he actually tries to call a service method. Blueprint/DS/whatever can't really help here, you just have to treat services as inherently unreliable. – Neil Bartlett Jul 25 '13 at 09:26
  • A failover solution would catch the exception and blacklist the service. You are right. This is not yet implemented in DOSGi. Though we already have part of the solution. The endpoint is published to zookeeper as a transient node. So if the container with the service goes down the endpoint will be removed by zookeeper. – Christian Schneider Jul 25 '13 at 12:31
  • As Neil said, On previous version of DOSGi, we have encountered a problem is that if a service go down abnormally (e.g. kill the karaf process). The ServiceTrack still can get the service and cause access failed. – Allen Xudong Cheng Jul 25 '13 at 15:25
  • Interesting .. can you describe how to reproduce this and open an issue for it. I think this might be a bug then. – Christian Schneider Jul 25 '13 at 16:00