"Reading notes" to understand service routing and load Balancing, micro-services to get up
1 Basic Concepts
Soa
The public business is split up to form a shared service that maximizes the reuse of code and logic and avoids duplication of construction, a design called an SOA.
Routing
In the SOA architecture, service Consumers find the address list of services to invoke in many service centers through service names, called service routes.
Load Balancing
For a high load of services, there are generally multiple servers consisting of clusters, when the request arrives, in order to allocate the request evenly to the back-end server, the load balancer will select a server to access through the corresponding load balancing algorithm and the rule in the corresponding address list of the service, which is called the service load balancing.
Service Configuration Center
When the service is growing, the scale becomes larger, manual management or simple maintenance configuration has been unable to meet, and single hardware and software load scheduling single point of failure problem highlighted, so need a dynamic registration and access to service information, to unify the management of service name and its corresponding server list information, this is the Service configuration center.
--> Working principle
When the service provider starts, registers the provided service name and server address with the Service configuration center
Service consumers get a list of service machines that need to be scheduled through the Service configuration center
After the load balancing algorithm, select a server call
When the server down or offline, the corresponding machine dynamic from the service configuration center removed, and notify the corresponding service consumers
After a service consumer accesses a service configuration center, the information that is queried is cached locally, followed by a call to check the cache, thereby reducing service configuration center pressure
Zookeeper
2 Load Balancing algorithm
Use
When a service consumer obtains a service's address list from the Service configuration center, it needs to select one of the initiating RPC calls, which requires a specific load balancing algorithm.
Common types
Polling method, stochastic method, source address hashing method, weighted polling method, weighted random method, minimum connection method, etc.
Polling method
Assign requests to the back-end servers in turn, balancing each server in the back-end without caring about the actual number of connections to the server and the current system load
Pseudo code
Create static variable pos=0;
Create a HashMap to map the server address and weights. (For comparison with back weighted polling method)
Create a new keylist to remove the server address from the map
Synchronized (POS) {
If exceed keylist length, pos resets 0;
Otherwise remove keylist.get (POS); POS + +;
}
Returns the retrieved server
Weighted Polling method
Each server is configured differently, so a higher weight of the configured, lower-load machine should be configured to handle more requests. The weighted polling algorithm assigns the order of request to the backend by weight
Pseudo code
Create static variable pos=0;
Create a HashMap to map the server address and weights.
Create a new keylist add the server address in the map to the list according to the number of times the cycle weights, such as 4, then add 4 times to the server address in keylist.
Synchronized (POS) {
If exceed keylist length, pos resets 0;
Otherwise remove keylist.get (POS); POS + +;
}
Returns the retrieved server