开发者

simple load balancing alghorithm

Im trying to write app, which will redirect or not some web traffic. Suppose, i want to redirect 10 % of movement on to another web server. The thing is, that i dont know how to transfer that conditon into logical condition in my app. As the input i got number of reque开发者_StackOverflow中文版stes. How to obtain which request should be redirected, and which not, if number of requestes is still changing ?

Thx for all help


Get random number from <0;10) range and then if this number is equal to 0. Redirect to another webserver.

Or

You can use for this http://en.wikipedia.org/wiki/Round_robin algorithm.

Or

You can forget about this 10%, and write some functions to obtain free resources on a servers, then you can choice server who have in choice time more free resources and if all servers is full you can drop connection with error or push to the random server.

Or

Think about do this on a web proxy server layer, i think is a better solution.

Read this http://en.wikipedia.org/wiki/Reverse_proxy


The Apache docs have a section on load balancing (Ctrl+F for it on that page).

It's normally best to keep requests from the same IP address going to the same server. As long as you don't have too many requests from 1 IP address, something like the following pseudo-code should work:

servers = [0: server0.com, 1: server1.com, ...];
server_count = 10;
# split the crc32 range into server_count chunks
server = crc32(get_client_ip_address()) % (4294967296 / server_count);
redirect(servers[server]);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜