CN109819055B - Method for realizing load balance by simultaneously supporting Ribbon and Eureka - Google Patents
Method for realizing load balance by simultaneously supporting Ribbon and Eureka Download PDFInfo
- Publication number
- CN109819055B CN109819055B CN201910197691.1A CN201910197691A CN109819055B CN 109819055 B CN109819055 B CN 109819055B CN 201910197691 A CN201910197691 A CN 201910197691A CN 109819055 B CN109819055 B CN 109819055B
- Authority
- CN
- China
- Prior art keywords
- client
- eureka
- load balancing
- ribbon
- server
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Landscapes
- Stored Programmes (AREA)
- Information Transfer Between Computers (AREA)
Abstract
The invention discloses a method for realizing load balancing by simultaneously supporting Ribbon and Eureka, which comprises the following steps: the method combines the content of the Cloud configuration file and the starting command of the Docker container to respectively specify a client for realizing load balancing by Ribbon and a client for realizing load balancing by Eureka, and comprises the following steps: configuring a mapping relation between a client name and a client path in a configuration file of a server; when a dispatcher server is started by using a Docker container, a load balancing implementation mode of each client is specified by setting environment variables. By means of load balancing of Eureka and/or load balancing of Ribbon of the appointed client, the single or multiple clients accessing the same server can adopt different load balancing modes and can switch the load balancing implementation modes by changing the environment variable value of the docker container.
Description
Technical Field
The invention relates to the technical field of computers, in particular to a method for realizing load balancing by simultaneously supporting Ribbon and Eureka.
Background
With the increasing number of users and the increasing amount of user requests, the requirements on the server are higher and higher. The performance of stand-alone servers is easily limited, and therefore a cluster of servers is needed to improve the overall performance of the web site. Then, since it is a clustered server, it is naturally also necessary to have one server, which plays the responsibility of the dispatcher. All requests sent by a user from a client browser are intercepted and received by the client browser, and then a dispatcher server selects a background server to process the request of the user according to the load condition of each server and a certain strategy method. In this process, it is necessary to ensure that the performance of each backend server is fully exerted, and the overall performance of the server cluster system is optimal. How to reasonably distribute tasks by the dispatcher server is the problem of load balancing. Load balancing is divided into server side and client side, and the load balancing of the service period side is most commonly realized by using Nginx at present. The main concern and applicability of this patent technology is client load balancing Ribbon. Spring Cloud is rapidly being updated and developed in the field of thunderstorm as an open source framework that can provide developers with tools (such as configuration management, service discovery and registration, circuit breakers, intelligent routing, control buses) for rapidly building some common modes in distributed systems. Especially in the API gateway of the microservice, plays an irreplaceable important role. The most common micro service is the integrated registration service center Eureka, and all services are registered on Eureka in turn and are uniformly managed by the service registration center Eureka. Therefore, the problem of Ribbon load balancing is also processed by Eureka, and the method is very convenient, simple and efficient. However, this configuration is not perfect, since in a microservice project, there is often not only one client service but a plurality of services. Two load balancing implementation modes supported by Spring Cloud at present are configured globally, that is, all clients accessing the server use one set of configuration in a unified way. Or using ribbon, Eureka, enabled, to hand all the load balancing implementations to Eureka processing; or the combined configuration of rim, eureka, enabled, false and Client Name, rim, listofservers is used to deliver the implementation of load balancing to the rim process. That is, accessing multiple clients of the same server, we cannot realize: the load balancing function of the client A is processed by a registration center Eureka, and the load balancing function of the client service B is processed by Ribbon. However, such a requirement is needed in the actual development process, so a way that each client under the same server can customize its own load balancing and can switch at any time is desired.
Disclosure of Invention
The invention aims to provide a method for realizing load balancing by simultaneously supporting Ribbon and Eureka, which is used for solving the problem that client load balancing in the prior art cannot simultaneously support Ribbon and Eureka.
The invention solves the problems through the following technical scheme:
a method for realizing load balancing by simultaneously supporting Ribbon and Eureka comprises the following steps:
the contents of the Cloud configuration file and the starting command of the Docker container are combined to respectively specify the client side which adopts Ribbon to realize load balance and Eureka to realize load balance.
Further, the method specifically comprises:
step S100: configuring a mapping relation between a client name and a client path in a configuration file of a server;
step S200: when a dispatcher server is started by using a Docker container, a load balancing implementation mode of each client is specified by setting environment variables.
Further, the step S100 specifically includes:
registering client resources adopting load balancing of Eureka in a service registration center;
and writing the complete request address of the client resource adopting the Ribbon load balancing into a configuration file of the server.
Further, the step S200 specifically includes:
step S210: when a dispatcher server is started by using a Docker container, defining an EUREKA array and a RIBBON array, adding a client adopting the load balance of the Eureka to the EUREKA array, and adding a client adopting the load balance of the Ribbon to the RIBBON array;
step S220: a user sends a request URL of a resource to be accessed through a client browser, a dispatcher server intercepts the request URL, then searches a client path which is in accordance with the request URL in a configuration file according to the request URL, then obtains a corresponding client name according to the mapping relation between the client name and the client path, and judges:
if the client adopts the load balance of the Eureka, the Eureka forwards the request URL to the back-end service according to the client name and the distribution strategy;
and if the client side adopts the load balance of the Ribbon, the Ribbon forwards the load to the back-end service according to the Ribbon Server List in the configuration file and the distribution strategy.
Further, the method further comprises: if a new client is accessed to the dispatcher server, judging:
if the new client realizes load balancing through the Eureka, inserting the name of the client into the EUREKA array as a new element in a starting command of the docker container;
if the new client side realizes load balancing through Ribbon, the name of the client side is only needed to be inserted into the RIBBON array as a new element in a starting command of the docker container.
Further, the method further comprises: when the load balancing implementation mode of a certain client needs to be switched, the environment variable value of the docker container starting command is changed, and then the container is restarted.
Compared with the prior art, the invention has the following advantages and beneficial effects:
according to the invention, by specifying the client side to adopt the load balance of Eureka and/or the load balance of Ribbon, the single or multiple client sides accessed to the same server side can adopt different load balance modes and can switch the load balance realization modes by changing the environment variable value of the docker container.
Drawings
FIG. 1 is a flow chart of the present invention.
Detailed Description
The present invention will be described in further detail with reference to examples, but the embodiments of the present invention are not limited thereto.
Example 1:
referring to fig. 1, a method for simultaneously supporting libbon and Eureka to implement load balancing is disclosed, which is based on a SpringCloud open source framework and a Docker application container engine, and respectively specifies a client that implements load balancing by libbon and a client that implements load balancing by Eureka by using the content of a cloud configuration file and a start command of a Docker container, and the two clients are used in combination to implement compatible sharing of the two load balancing manners of libbon and Eureka, and specifically includes:
step S100: configuring a mapping relation between a client name and a client path in a configuration file of a server;
if the load balancing of the Eureka is adopted, a plurality of client resources are required to be registered in the service registration center, and if the load balancing is not realized by the Eureka all the time, the registration is not required. If the load balancing of the Ribbon is adopted, the complete request addresses of a plurality of client resources are required to be written into a configuration file of the server, and if the load balancing is not realized by the Ribbon, the configuration can be omitted.
Step S200: when a dispatcher server is started by using a Docker container, a load balancing implementation mode of each client is specified by setting environment variables.
(1) When a dispatcher server is started by using Docker, a load balancing implementation mode of each client is specified in an environment variable mode, specifically, two arrays are defined, one is EUREKA [ ], the other is RIBBON [ ], the load balancing client of Ribbon is added into the RIBBON array, and the load balancing client of Eureka is added into the EUREKA array. Namely: -e "EUREKA [ client1, client3] ═ true" indicating that client1 and client3 implement load balancing functions using EUREKA, -e "rib [ client2] ═ true" indicating that client2 implements load balancing functions using rib bon;
(2) a user sends requests of http://127.0.0.1:8080/app1/xxx and http://127.0.0.1:8080/app2/xxx through a client browser respectively; the service dispatcher intercepts the request, searches a path/app 1/'and a path/app 2/' in a configuration file according to the request URL, determines that the request of/app 1/is actually forwarded to the client1 and the request of/app 2/is actually forwarded to the client2 according to the mapping relation between the client name and the client path.
Example 2:
on the basis of embodiment 1, the method further comprises the following steps: if a new client accesses the dispatcher server, if the implementation mode of the load balancing is handed over to Eureka, the relevant content of the start command of the docker container is modified to-e "Eureka [ client1, client3, client4] (true"); if the implementation manner of the load balancing is to be handed over to the robbon, a real rear-end request address needs to be added to the configuration file, and the content related to the start command of the docker container is modified to "e" rib on [ client2, client4] ═ true ".
Example 3:
on the basis of embodiment 1 or 2, the method further comprises the following steps: when the load balancing implementation mode of a certain client needs to be switched, the operation can be directly carried out through the starting command of the docker container, and then the container is restarted to take effect. The complexity that the content in the configuration file needs to be modified, recompiled, packaged and deployed when the load balancing implementation mode needs to be changed at present is avoided. The method realizes the load balance by simultaneously supporting Ribbon and Eureka under the same service. Load balancing can be realized by different modes for each micro service instance accessed in the service.
Although the present invention has been described herein with reference to the illustrated embodiments thereof, which are intended to be preferred embodiments of the present invention, it is to be understood that the invention is not limited thereto, and that numerous other modifications and embodiments can be devised by those skilled in the art that will fall within the spirit and scope of the principles of this disclosure.
Claims (4)
1. A method for realizing load balancing by simultaneously supporting Ribbon and Eureka is characterized by comprising the following steps:
the method specifically comprises the following steps of combining the content of the Cloud configuration file and a starting command of the Docker container, and respectively specifying a client for realizing load balancing by Ribbon and realizing load balancing by Eureka:
step S100: configuring a mapping relation between a client name and a client path in a configuration file of a server;
step S200: when a Docker container is used for starting a dispatcher server, a load balancing implementation mode of each client is specified by setting an environment variable;
the step S200 specifically includes:
step S210: when a dispatcher server is started by using a Docker container, defining an EUREKA array and a RIBBON array, adding a client adopting the load balance of the Eureka to the EUREKA array, and adding a client adopting the load balance of the Ribbon to the RIBBON array;
step S220: a user sends a request URL of a resource to be accessed through a client browser, a dispatcher server intercepts the request URL, then searches a client path which is in accordance with the request URL in a configuration file according to the request URL, then obtains a corresponding client name according to the mapping relation between the client name and the client path, and judges:
if the client adopts the load balance of the Eureka, the Eureka forwards the request URL to the back-end service according to the client name and the distribution strategy;
and if the client side adopts the load balance of the Ribbon, the Ribbon forwards the load to the back-end service according to the Ribbon Server List in the configuration file and the distribution strategy.
2. The method of claim 1, wherein the step S100 specifically includes:
registering client resources adopting load balancing of Eureka in a service registration center;
and writing the complete request address of the client resource adopting the Ribbon load balancing into a configuration file of the server.
3. The method for realizing load balancing by simultaneously supporting Ribbon and Eureka according to claim 2, further comprising: if a new client is accessed to the dispatcher server, judging:
if the new client realizes load balancing through the Eureka, inserting the name of the client into the EUREKA array as a new element in a starting command of the docker container;
if the new client side realizes load balancing through Ribbon, the name of the client side is only needed to be inserted into the RIBBON array as a new element in a starting command of the docker container.
4. The method for realizing load balancing by simultaneously supporting Ribbon and Eureka according to claim 3, further comprising: when the load balancing implementation mode of a certain client needs to be switched, the environment variable value of the docker container starting command is changed, and then the container is restarted.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910197691.1A CN109819055B (en) | 2019-03-15 | 2019-03-15 | Method for realizing load balance by simultaneously supporting Ribbon and Eureka |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201910197691.1A CN109819055B (en) | 2019-03-15 | 2019-03-15 | Method for realizing load balance by simultaneously supporting Ribbon and Eureka |
Publications (2)
Publication Number | Publication Date |
---|---|
CN109819055A CN109819055A (en) | 2019-05-28 |
CN109819055B true CN109819055B (en) | 2020-07-07 |
Family
ID=66609076
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201910197691.1A Active CN109819055B (en) | 2019-03-15 | 2019-03-15 | Method for realizing load balance by simultaneously supporting Ribbon and Eureka |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN109819055B (en) |
Families Citing this family (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110505427A (en) * | 2019-08-27 | 2019-11-26 | 杭州觅境寻味农业科技有限公司 | Electric business shopping platform system and method based on video calling and intelligent electronic-scale |
CN112291099B (en) * | 2020-11-02 | 2022-07-29 | 西南电子技术研究所(中国电子科技集团公司第十研究所) | Multi-mode registration center architecture switching method under mobile environment |
CN112633664A (en) * | 2020-12-17 | 2021-04-09 | 苏州莫普迪拉信息科技有限公司 | Internet digital operation system |
CN113572828B (en) * | 2021-07-13 | 2024-04-09 | 壹药网科技(上海)股份有限公司 | System for improving client load balance based on URL grouping granularity |
CN113778653A (en) * | 2021-09-22 | 2021-12-10 | 苏州莫普迪拉信息科技有限公司 | Flat-panel player service end system |
CN114726785A (en) * | 2022-04-07 | 2022-07-08 | 深圳市铱云云计算有限公司 | Directional routing debugging mechanism based on request label expression |
CN115987547A (en) * | 2022-11-02 | 2023-04-18 | 四川大学 | Multi-platform interconnection cloud connector system |
Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB249716A (en) * | 1925-06-24 | 1926-04-01 | Watson Ex Lab Company | Improvements in and relating to computing weighing scales |
CN108052640A (en) * | 2017-12-21 | 2018-05-18 | 泰康保险集团股份有限公司 | The interlock method and device of status information change |
CN108933832A (en) * | 2018-07-17 | 2018-12-04 | 河北中科恒运软件科技股份有限公司 | A method of realizing that full stage grid is shared |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107885822A (en) * | 2017-11-07 | 2018-04-06 | 厦门安胜网络科技有限公司 | The generation method and device of a kind of operation code |
CN108446111A (en) * | 2018-03-26 | 2018-08-24 | 国家电网公司客户服务中心 | A kind of micro services construction method based on Spring cloud |
-
2019
- 2019-03-15 CN CN201910197691.1A patent/CN109819055B/en active Active
Patent Citations (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
GB249716A (en) * | 1925-06-24 | 1926-04-01 | Watson Ex Lab Company | Improvements in and relating to computing weighing scales |
CN108052640A (en) * | 2017-12-21 | 2018-05-18 | 泰康保险集团股份有限公司 | The interlock method and device of status information change |
CN108933832A (en) * | 2018-07-17 | 2018-12-04 | 河北中科恒运软件科技股份有限公司 | A method of realizing that full stage grid is shared |
Also Published As
Publication number | Publication date |
---|---|
CN109819055A (en) | 2019-05-28 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109819055B (en) | Method for realizing load balance by simultaneously supporting Ribbon and Eureka | |
JP7101319B2 (en) | Multi-cluster ingress | |
WO2020147466A1 (en) | Method for invoking server and proxy server | |
EP3316532B1 (en) | Computer device, system and method for implementing load balancing | |
US7548945B2 (en) | System, network device, method, and computer program product for active load balancing using clustered nodes as authoritative domain name servers | |
EP1116112B1 (en) | Load balancing in a network environment | |
US8037025B2 (en) | Method and approach to hosting versioned web services | |
US20120290643A1 (en) | Client-server system | |
US20180007178A1 (en) | Method and system of decoupling applications from underlying communication media through shim layers | |
US20020004796A1 (en) | System and method for providing distributed database services | |
KR20150121713A (en) | Allocating resources between network nodes for providing a network node function | |
CN113645304B (en) | Data service processing method and related equipment | |
US10579432B1 (en) | Load balancing deterministically-subsetted processing resources using fractional loads | |
EP2126718A1 (en) | Method and system for a context manager for a converged services framework | |
EP2523423B1 (en) | Method and system for providing a distributed scalable hosting environment for web services | |
KR20050021751A (en) | Distributed Web Caching System with Client-Based | |
CN116248683A (en) | Cloud load balancing system and cloud load balancing method | |
KR20030046911A (en) | A web application sever and method for providing dynamic contents thereof | |
CN116684419A (en) | Soft load balancing system | |
Sit et al. | Cluster-Based Web Server with Socket Cloning |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
TA01 | Transfer of patent application right | ||
TA01 | Transfer of patent application right |
Effective date of registration: 20200110 Address after: 610000 Chengdu City, Sichuan Province, China (Sichuan) Free Trade Pilot Area, No. 199 Tianfu Fourth Street, Chengdu High-tech Zone, 33 floors Applicant after: Panovasic Co., Ltd. Address before: 621000 Mianyang province high tech Zone, East Hing Road, No. 35 cotton Applicant before: Sichuan Changhong Electrical Appliance Co., Ltd. |
|
GR01 | Patent grant | ||
GR01 | Patent grant |