开发者

Load Balancing webservers using Httpurlconnection on client side

开发者 https://www.devze.com 2023-02-23 07:37 出处:网络
My application needs to connect to a web service to get xml data. I have four web service endpoints. What is the best way to load balance between web service?

My application needs to connect to a web service to get xml data. I have four web service endpoints.

What is the best way to load balance between web service?

I know best way is to use Hardware/software Lo开发者_如何学Goad Balancer but i have to do on client side.

i have develop a client using HttpURLConnection which is working fine for any one end point.

I am planning to use hashmap for URL's and after that call one by one.

Regards, imran


Without a central point to co-ordinate distribution of connections between your service endpoints, you're pretty much limited to choosing an arbitrary one-of-four each time you establish a connection. A reasonable approach may be to use each endpoint in turn for successive interactions from the client (starting with one chosen at random to ensure that there isn't heavy bias towards a single endpoint at times when the clients may be restarted).

Alternatively, you could implement an endpoint that returns a preferred connection, from which the client will make subsequent calls. The implementation could then assign clients round robin style, or with reference to the load reported by each endpoint at any given time.

Of the two approaches, the former is by far the simpler and should give reasonably even distribution across the endpoints. The latter would allow additional endpoints to be added without requiring that the clients be updated.

0

精彩评论

暂无评论...
验证码 换一张
取 消