KBMMW provides a good mechanism for balancing load and disaster recovery, supports multiple implementations, and now looks at the simplest, client-controlled disaster recovery and simple load balancing.
Now, we deploy Kbmmwserver to different servers, or deploy multiple instances on the same server, so we have a service access list:
192.168.0.88:9000
192.168.0.88:9001
192.168.0.89.9000
192.168.0.89.9001
The service is ready, now, to transform the client's transport, disaster tolerance and load balancing can be achieved. Specifically, it is the use of Clienttransport's two attributes with an event:
Two properties:
Maxretrires: When the Clienttransportreconnect event is triggered, the parameter alternative is false
Maxretriesalternative: The number of times the transport address is changed, the parameter alternative is true when the Clienttransportreconnect event is triggered
The system first tries to join the service by the number of times defined by Maxretries, if it is unsuccessful, and then tries to join the server by the number of times defined by maxretriesalternative, and does not succeed, eventually triggering the Onconnectionlost event. If you do not handle the Onconnectionlost event, an exception connectionlost is generated. Each time the Clienttransportreconnect event is triggered, in this event, the parameter alternative can be used to determine whether the transport service address needs to be redefined, and if a new service address is changed, the system will re-cascade the server by the new address. Assuming that the maxretries definition 3,maxretriesalternative is defined as 2, then a total of five tries to focus on the server 5 times, the last two times, in triggeringClienttransportreconnect
An event that has three parameters:
Sender:transport Object
Alternative: True to indicate that a service address should be replaced
Retriesleft: remaining number of re-associated
The following code shows how to replace the server address with this event:
Proceduretwpmainmodule.kbmmwhttpsysclienttransport1reconnect ( Sender:tobject;
Alternative:boolean; Retriesleft:integer);
var
I:integer;
Const
Althosts:array [0..5] of String = (
' 192.168.0.88:9000 ',
' 192.168.0.88:9001 ',
& nbsp ' 192.168.0.88:9002 ',
' 192.168.0.89:9000 ',
' 192.168.0.89:9001 ',
' 192.168.0.89:9002 '
);
Begin
If alternative then
begin
i:=random (High (althosts)-1);
tkbmmwcustomclienttransport (Sender). Host:=althosts[i];
END;
End;
OK, the simplest load of equalization is done!
This process looks simple, but there is a problem, the first is that each client should know the list of services, if the list changes, inconvenient to maintain, in addition, without real balance, the user may run to a service. In order to solve these problems, tomorrow plan to organize the "centralized balanced load implementation mode."
Reference KBMMW Author's description document
KBMMW balanced load and disaster recovery (1) (reproduced Red fish)