Stateful server load balancing method, system, device and storage medium

CN112506647BActive Publication Date: 2025-02-28HANGZHOU ELECTRONICS SOUL NETWORK TECH
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011301122.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-11-19
Publication Date
2025-02-28
Estimated Expiration
2040-11-19

AI Technical Summary

Technical Problem

[0005]本申请实施例提供了有状态服务器负载均衡的方法、系统、装置和存储介质,至少解决相关技术中在有状态服务器中对游戏资源进行分配时,负载分配不均、系统出现单点故障和服务器难以动态扩容的问题

Benefits of technology

[0030]相比于相关技术,本申请实施例提供的一种有状态服务器负载均衡的方法,获取后端服务器中的空闲服务器,该空闲服务器为第一服务器,通过redis的setex指令将游戏资源分配到第一服务器上,然后将游戏资源连接到第一服务器进行服务,并在预设间隔时间内,第一服务器通过redis与游戏资源的绑定关系进行续期,最后在经过redis中的预设时间没有续期的情况下,第一服务器与游戏资源的绑定关系过期,游戏资源进行重新分配,解决了在有状态服务器中对游戏资源进行分配时,负载分配不均、系统出现单点故障和服务器难以动态扩容的问题,实现了游戏资源的动态负载均衡,以及服务器的动态扩容,去除了系统的单点故障。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112506647B_ABST
    Figure CN112506647B_ABST
Patent Text Reader

Abstract

The present application relates to a method, system, device and storage medium for stateful server load balancing, wherein the method for stateful server load balancing includes: obtaining an idle server in a backend server, the idle server being a first server, allocating game resources to the first server through the setex instruction of redis, and then connecting the game resources to the first server for service, and within a preset interval, the first server renews the binding relationship with the game resources through redis, and finally, if there is no renewal after the preset time in redis, the binding relationship between the first server and the game resources expires, and the game resources are reallocated. Through this application, the problems of uneven load distribution, single point failure of the system and difficulty in dynamic expansion of the server when allocating game resources in a stateful server are solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computers, and in particular to a method, system, device and storage medium for stateful server load balancing. Background Art

[0002] There are two important basic assumptions for server programs, namely whether the server is based on stateful requests or stateless requests. Among them, game servers are generally stateful servers. Stateful servers maintain the state information of each connection on the server side. When the server receives the request sent by each connection, it can reproduce the context from the locally stored information. In this way, the client can easily use the default information, and the server can also easily manage the state. For example, when a game user logs in, the server can obtain his previous game registration information based on the user name; and in subsequent processing, the server can easily find the user's historical information.

[0003] In the related art, one way to load balance a stateful server is through hashing. However, this method is difficult to dynamically expand and there will be problems with uneven load distribution. Another way is to distribute the load through a central server, but there will be problems with single point failure of the server.

[0004] In the related art, when allocating game resources in a stateful server, there is no effective solution to the problems of uneven load distribution, single point failure in the system, and difficulty in dynamic capacity expansion of the server. Summary of the invention

[0005] The embodiments of the present application provide a method, system, device and storage medium for stateful server load balancing, which at least solve the problems in the related art of uneven load distribution, single point failure of the system and difficulty in dynamic expansion of the server when distributing game resources in a stateful server.

[0006] In a first aspect, an embodiment of the present application provides a method for stateful server load balancing, the method comprising:

[0007] Acquire an idle server from the backend server, where the idle server is a first server;

[0008] Allocate game resources to the first server through the redis setex instruction;

[0009] Connecting the game resource to the first server for service, and renewing the binding relationship between the first server and the game resource through the redis within a preset interval;

[0010] When there is no renewal after a preset time in the redis, the binding relationship between the first server and the game resource expires, and the game resource is reallocated.

[0011] In some embodiments, before connecting the game resource to the first server for service, the method includes:

[0012] The server where the game resource is currently located is always obtained through the redis get instruction, and the server is the second server.

[0013] In some embodiments, obtaining an idle server in the backend server includes:

[0014] Obtain the ID of the idle server stored in the redis;

[0015] The service discovery protocol locates the idle server through the ID.

[0016] In some embodiments, the expiration of the binding relationship between the first server and the game resource includes:

[0017] When the first server crashes or the game player logs out, the binding relationship between the first server and the game resource expires.

[0018] In a second aspect, an embodiment of the present application provides a system for stateful server load balancing, the system comprising:

[0019] An acquisition module, used for acquiring an idle server in a backend server, wherein the idle server is a first server;

[0020] An allocation module, used for allocating game resources to the first server through the setex instruction of redis;

[0021] A timed renewal module, used to connect the game resource to the first server for service, and within a preset interval, the first server renews the binding relationship between the redis and the game resource;

[0022] The reallocation module is used to reallocate the game resources if the binding relationship between the first server and the game resources expires without renewal after a preset time in the redis.

[0023] In some embodiments, the allocation module is further configured to, before connecting the game resource to the first server for service,

[0024] The server where the game resource is currently located is always obtained through the redis get instruction, and the server is the second server.

[0025] In some embodiments, the acquisition module is further used to obtain the ID of the idle server stored in the redis;

[0026] The service discovery protocol locates the idle server through the ID.

[0027] In some embodiments, the reallocation module is also used to expire the binding relationship between the first server and the game resource when the first server crashes or the game player logs out.

[0028] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute any of the above-described stateful server load balancing methods.

[0029] In a fourth aspect, an embodiment of the present application provides a storage medium, in which a computer program is stored, wherein the computer program is configured to execute any of the above-mentioned stateful server load balancing methods when running.

[0030] Compared with the related art, the embodiment of the present application provides a method for stateful server load balancing, which obtains an idle server in the back-end server, which is the first server, allocates game resources to the first server through the setex instruction of redis, and then connects the game resources to the first server for service, and within a preset interval, the first server renews the binding relationship with the game resources through redis, and finally, if there is no renewal after the preset time in redis, the binding relationship between the first server and the game resources expires, and the game resources are reallocated, which solves the problems of uneven load distribution, single point failure of the system and difficulty in dynamic expansion of the server when allocating game resources in a stateful server, realizes dynamic load balancing of game resources and dynamic expansion of servers, and eliminates single point failures of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0031] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0032] Figure 1 It is a schematic diagram of an application environment of a stateful server load balancing method according to an embodiment of the present application;

[0033] Figure 2 is a flow chart of a stateful server load balancing method according to an embodiment of the present application;

[0034] Figure 3 is a schematic diagram of dynamically allocating backend servers according to an embodiment of the present application;

[0035] Figure 4 is a structural block diagram of a stateful server load balancing system according to an embodiment of the present application;

[0036] Figure 5 It is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0037] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is described and illustrated below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments provided in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present application. In addition, it can also be understood that although the efforts made in this development process may be complex and lengthy, for ordinary technicians in the field related to the contents disclosed in the present application, some changes such as design, manufacturing or production based on the technical contents disclosed in the present application are only conventional technical means, and should not be understood as insufficient contents disclosed in the present application.

[0038] Reference to "embodiments" in this application means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those of ordinary skill in the art that the embodiments described in this application may be combined with other embodiments without conflict.

[0039] Unless otherwise defined, the technical terms or scientific terms involved in this application should be understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the" and the like involved in this application do not indicate a quantity limitation, and may indicate the singular or plural. The terms "include", "comprise", "have" and any of their variations involved in this application are intended to cover non-exclusive inclusions; for example, a process, method, system, product or device that includes a series of steps or modules (units) is not limited to the listed steps or units, but may also include steps or units that are not listed, or may also include other steps or units inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The "multiple" involved in this application means greater than or equal to two. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. The terms "first", "second", "third" and the like involved in the present application are merely used to distinguish similar objects and do not represent a specific ordering of the objects.

[0040] The stateful server load balancing method provided in this application can be applied to Figure 1 In the application environment shown, Figure 1 is a schematic diagram of an application environment of a stateful server load balancing method according to an embodiment of the present application, such as Figure 1 As shown, the system of the application environment includes a server 10 and an intelligent terminal device 11, wherein the server 10 obtains an idle server in the back-end server, which is the first server, and then allocates the game resources to the first server through the setex instruction of redis, and then connects the game resources to the first server for service, and within a preset interval, the first server renews the binding relationship with the game resources through redis, and finally, if there is no renewal after the preset time in redis, the binding relationship between the first server and the game resources expires, and the game resources applied to the intelligent terminal device 11 are reallocated, which solves the problems of uneven load distribution, single point failure of the system and difficulty in dynamic expansion of the server when allocating game resources in a stateful server, realizes dynamic load balancing of game resources and dynamic expansion of the server, and eliminates the single point failure of the system.

[0041] This embodiment provides a method for stateful server load balancing. Figure 2 is a flow chart of a stateful server load balancing method according to an embodiment of the present application, such as Figure 2As shown, the process includes the following steps:

[0042] Step S201, obtain an idle server from the backend servers, the idle server is the first server, optionally, assuming that there are 3 servers available for service, this embodiment selects a relatively idle server from the 3 backend servers, the idle server is the first server. Compared with the prior art that uses a hash method for load balancing, this embodiment can directly add backend servers externally to achieve dynamic expansion of the server;

[0043] Step S202, allocate the game resources to the first server through the setex instruction of redis, wherein redis is a key-value pair storage database that contains multiple data structures, supports network, is memory-based, and has optional persistence. In addition, the setex instruction of redis is used to set the string value of the key in the specified timeout in the redis key, that is, to specify the key setting value and its expiration time, for example, setex A 60 S, wherein A represents the game resources, S represents the first server, and 60 represents the expiration time is 60 seconds. Figure 3 is a schematic diagram of dynamically allocating backend servers according to an embodiment of the present application, such as Figure 3 As shown, optionally, in this embodiment, game resources A, such as players, unions, etc., are allocated to the first server S through the setex A 60 S instruction of redis. In this embodiment, game resources are allocated to the first server through the redis cluster. Compared with the prior art in which load resources are allocated through a central server and a single point of failure occurs, the redis cluster can effectively avoid the single point problem, that is, when the master node fails, the slave node can replace the failed master node for service;

[0044] Step S203, connecting the game resource to the first server for service, and renewing the binding relationship between the first server and the game resource through redis within a preset interval. Optionally, in this embodiment, after the game resource is notified by the system to be allocated to the first server, the game resource is connected to the first server for service, and every certain period of time, such as 30 seconds, the first server renews the binding relationship between the game resource A and redis;

[0045] Step S204: If the binding relationship between the first server and the game resource is not renewed after the preset time in redis, the game resource is reallocated. Optionally, in this embodiment, if the binding relationship between the first server S and the game resource A is not renewed after the 60-second expiration time preset in redis, the binding relationship will expire. At this time, the game resource A will be reallocated to other servers. This embodiment implements an atomic operation through the Lua script of redis, that is, dynamically allocates game resources, and can achieve dynamic load balancing of resources.

[0046] Through the above steps S201 to S204, compared with the prior art, the stateful server realizes load balancing through hashing, which will lead to the problem that the server is difficult to dynamically expand and the load is unevenly distributed; and the problem of single point failure of the server will exist when the load is distributed through a central server. In this embodiment, an idle server in the back-end server is obtained, and the idle server is the first server. Then, the game resources are allocated to the first server through the setex instruction of redis, and then the game resources are connected to the first server for service. Within the preset interval, the first server renews the binding relationship with the game resources through redis. Finally, if there is no renewal after the preset time in redis, the binding relationship between the first server and the game resources expires, and the game resources applied to the smart terminal device 11 are reallocated, which solves the problems of uneven load distribution, single point failure of the system and difficulty in dynamic expansion of the server when allocating game resources in the stateful server, realizes dynamic load balancing of game resources, dynamic expansion of the server, and eliminates the single point failure of the system.

[0047] In some embodiments, before connecting the game resource to the first server for service, the server where the game resource is currently located is always obtained through the redis get command, which is the second server, wherein the redis get command is used to obtain the value of the specified key, and if the key does not exist, nil is returned; if the value stored in the key is not a string type, an error is returned, for example, get A means obtaining the second server where the game resource A is currently located. Optionally, due to concurrent operations, that is, when a game player's account logs in on two terminal devices, the game resource A (player account) at this time will be allocated to the second server, which is different from the first server. Therefore, before connecting the game resource A to the first server for service, it is necessary to always obtain the second server where the game resource A is currently located through the redis get A command, which is conducive to connecting to the second server where the game resource A is actually located in the subsequent resource connection.

[0048] In some of the embodiments, obtaining an idle server in the backend server includes: obtaining the ID of the idle server stored in redis, and the service discovery protocol locates the idle server through the ID, wherein there are many service discovery protocols, such as Consul, Zookeeper, Etcd, and Eureka. Optionally, the system process obtains the ID of the idle server stored in redis, and the service discovery protocol locates the obtained idle server through the ID through load balancing algorithms such as polling, random method, hash method, minimum number of connections and weight. In addition, as long as the system process is started, the newly added backend server can be obtained through the service discovery protocol.

[0049] In some embodiments, the expiration of the binding relationship between the first server and the game resource includes: when the first server crashes or the game player logs out, the binding relationship between the first server and the game resource expires. Optionally, when the server crashes or the game player logs out, the binding relationship between the server and the game resource will expire and the game resource will be reallocated.

[0050] It should be noted that the steps shown in the above process or the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0051] This embodiment also provides a stateful server load balancing system, which is used to implement the above embodiments and preferred implementations, and will not be repeated here. As used below, the terms "module", "unit", "subunit", etc. can implement a combination of software and / or hardware for a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0052] Figure 4 is a structural block diagram of stateful server load balancing according to an embodiment of the present application, such as Figure 4 As shown, the system includes an acquisition module 41, an allocation module 42, a timed renewal module 43 and a redistribution module 44:

[0053] The acquisition module 41 is used to acquire an idle server in the back-end server, which is the first server; the allocation module 42 is used to allocate game resources to the first server through the setex instruction of redis; the timed renewal module 43 is used to connect the game resources to the first server for service, and within a preset interval, the first server renews the binding relationship with the game resources through redis; the reallocation module 44 is used to reallocate the game resources when the binding relationship between the first server and the game resources expires without renewal within the preset time in redis.

[0054] Through the above system, compared with the hash method used in the prior art for load balancing distribution, the acquisition module 41 of this embodiment can directly add a back-end server externally to realize the dynamic expansion of the server; the allocation module 42 allocates the game resources to the first server through the redis cluster. Compared with the single point failure caused by the allocation of load resources through a central server in the prior art, the single point problem can be effectively avoided through the redis cluster, that is, when the master node fails, the slave node can replace the failed master node for service; the timed renewal module 43 can connect the game resources to the first server for service after the game resources are notified by the system to be allocated to the first server, and the first server will renew the binding relationship between redis and game resource A every once in a while, such as 30 seconds; the redistribution module 44 implements an atomic operation through the redis lua script, that is, dynamically allocates the game resources, and can realize the dynamic load balancing of resources. The whole system solves the problems of uneven load distribution, single point failure in the system and difficulty in dynamic expansion of the server when allocating game resources in a stateful server, realizes the dynamic load balancing of game resources, and the dynamic expansion of the server, and eliminates the single point failure of the system.

[0055] In some embodiments, the allocation module 42 is also used to obtain the server where the game resource is currently located through the redis get command before connecting the game resource to the first server for service, and the server is the second server, wherein the redis get command is used to obtain the value of the specified key, and if the key does not exist, nil is returned; if the value stored in the key is not a string type, an error is returned, for example, get A means obtaining the second server where the game resource A is currently located. Optionally, due to concurrent operations, that is, when a game player's account logs in on two terminal devices, the game resource A (player account) at this time will be allocated to the second server, which is different from the first server. Therefore, before connecting the game resource A to the first server for service, it is necessary to always obtain the second server where the game resource A is currently located through the redis get A command, which is conducive to connecting to the second server where the game resource A is actually located in the subsequent resource connection.

[0056] In some embodiments, the acquisition module 41 is also used to obtain the ID of the idle server stored in redis, and the service discovery protocol locates the idle server through the ID, wherein there are many service discovery protocols, such as Consul, Zookeeper, Etcd and Eureka. Optionally, the system process obtains the ID of the idle server stored in redis, and the service discovery protocol locates the acquired idle server through the ID through load balancing algorithms such as polling, random method, hash method, minimum number of connections and weight. In addition, as long as the system process is started, the newly added backend server can be obtained through the service discovery protocol.

[0057] In some of the embodiments, the reallocation module 44 is also used to expire the binding relationship between the first server and the game resources when the first server crashes or the game player logs out. Optionally, when the server crashes or the game player logs out, the binding relationship between the server and the game resources will expire and the game resources will be reallocated.

[0058] The present invention is described in detail below in conjunction with application scenarios.

[0059] The purpose of the present invention is to provide a method and system for stateful server load balancing. The process steps of the technical solution for stateful server load balancing in this embodiment include:

[0060] S1, when game resource A needs to apply for a stateful server, first obtain a relatively idle first server S in the backend server through the service discovery protocol;

[0061] S2, try to bind the game resource A to the first server S through redis setex A 60 S, and then use redis get A to always obtain the second server where the game resource A is currently located. Due to the existence of concurrent operations, the second server here is not necessarily the first server;

[0062] S3, the game resource A is informed that it is allocated to the first server S, and then the game resource A is connected to the first server S for service;

[0063] S4, when the game resource A is served on the first server S, the first server S will renew the binding relationship with the game resource A through redis at regular intervals, such as 30 seconds;

[0064] S5, if there is no renewal after 60 seconds, the binding data of game resource A will expire, and resource A will redistribute the load through the above steps. Generally speaking, if the server SS crashes or the game player logs out, the binding relationship will expire.

[0065] This embodiment further provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.

[0066] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0067] In addition, in combination with the stateful server load balancing method in the above embodiment, the embodiment of the present application can provide a storage medium for implementation. The storage medium stores a computer program; when the computer program is executed by a processor, any stateful server load balancing method in the above embodiment is implemented.

[0068] In one embodiment, Figure 5 is a schematic diagram of the internal structure of an electronic device according to an embodiment of the present application, such as Figure 5 As shown, an electronic device is provided, which may be a server, and its internal structure diagram may be as shown in Figure 5As shown. The electronic device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the electronic device is used to provide computing and control capabilities. The memory of the electronic device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the electronic device is used to store data. The network interface of the electronic device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a method for stateful server load balancing is implemented.

[0069] Those skilled in the art will understand that Figure 5 The structure shown in the figure is merely a block diagram of a partial structure related to the scheme of the present application, and does not constitute a limitation on the electronic device to which the scheme of the present application is applied. The specific electronic device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.

[0070] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

[0071] Those skilled in the art should understand that the technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0072] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A method for stateful server load balancing, characterized in that: The method comprises: Obtaining an idle server in the backend server, wherein the idle server is the first server, comprises: obtaining the ID of the idle server stored in redis, and locating the obtained idle server by the ID through any one of a polling method, a random method, a hash method, a minimum number of connections, and a weighted load balancing algorithm; Allocate game resources to the first server through the setex instruction of redis, wherein redis is a key-value pair storage database that contains multiple data structures, supports networks, is memory-based, and has optional persistence. The setex instruction of redis is used to set the string value of the key at a specified timeout in the redis key, that is, to set the value of the key and its expiration time, wherein the game resources include players and unions; The game resource is connected to the first server for service, and within a preset interval, the first server renews the binding relationship between the game resource and the redis, and when the master node of redis fails, the slave node can replace the failed master node for resource allocation service; When there is no renewal after a preset time in the redis, the binding relationship between the first server and the game resource expires, and the game resource is reallocated.

2. The method according to claim 1, characterized in that Before connecting the game resource to the first server for service, the method includes: The server where the game resource is currently located is always obtained through the redis get command, and the server is the second server. The redis get command is used to obtain the setting value of the specified key. If the key does not exist, nil is returned; if the value stored in the key is not a string type, an error is returned.

3. The method according to claim 1, characterized in that The binding relationship between the first server and the game resource expires including: When the first server crashes or the game player logs out, the binding relationship between the first server and the game resource expires.

4. A stateful server load balancing system, characterized in that: The system comprises: An acquisition module is used to acquire an idle server in a backend server, wherein the idle server is a first server and includes: acquiring an ID of the idle server stored in redis, and locating the acquired idle server by ID through any one of a polling method, a random method, a hash method, a minimum number of connections, and a weighted load balancing algorithm; an allocation module, for allocating game resources to the first server through a setex instruction of redis, wherein redis is a key-value pair storage database that includes multiple data structures, supports networks, is memory-based, and has optional persistence, and the setex instruction of redis is used to set a string value of a key at a specified timeout in a redis key, that is, to set a value and an expiration time of the specified key, wherein the game resources include players and unions; A timed renewal module, used to connect the game resource to the first server for service, and within a preset interval, the first server renews the game resource through the binding relationship between the redis and the game resource. When the master node of redis fails, the slave node can replace the failed master node for resource allocation service; The reallocation module is used to reallocate the game resources if the binding relationship between the first server and the game resources expires without renewal after a preset time in the redis.

5. The system according to claim 4, characterized in that The allocation module is also used for, before connecting the game resource to the first server for service, The server where the game resource is currently located is always obtained through the redis get command, and the server is the second server. The redis get command is used to obtain the setting value of the specified key. If the key does not exist, nil is returned; if the value stored in the key is not a string type, an error is returned.

6. The system according to claim 4, characterized in that The acquisition module is also used to obtain the ID of the idle server stored in the redis; The service discovery protocol locates the idle server through the ID.

7. The system according to claim 4, characterized in that The reallocation module is also used to expire the binding relationship between the first server and the game resource when the first server crashes or the game player logs out.

8. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to execute the stateful server load balancing method according to any one of claims 1 to 3.

9. A storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the stateful server load balancing method according to any one of claims 1 to 3 when running.

Citation Information

Patent Citations

  • Method and equipment for dynamic load balancing of game servers

    CN103546524A

  • Method, device and apparatus for keeping login state and storage medium

    CN110166529A