WO2022252631A1 - 分布式应用方法、装置、计算机设备、存储介质 - Google Patents
分布式应用方法、装置、计算机设备、存储介质 Download PDFInfo
- Publication number
- WO2022252631A1 WO2022252631A1 PCT/CN2022/071838 CN2022071838W WO2022252631A1 WO 2022252631 A1 WO2022252631 A1 WO 2022252631A1 CN 2022071838 W CN2022071838 W CN 2022071838W WO 2022252631 A1 WO2022252631 A1 WO 2022252631A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- server
- servers
- heartbeat
- target
- sequence
- Prior art date
Links
- 238000000034 method Methods 0.000 title claims abstract description 44
- 238000004590 computer program Methods 0.000 claims description 17
- 230000008859 change Effects 0.000 claims description 6
- 238000012423 maintenance Methods 0.000 abstract description 8
- 238000005516 engineering process Methods 0.000 abstract description 7
- VYPSYNLAJGMNEJ-UHFFFAOYSA-N silicon dioxide Inorganic materials O=[Si]=O VYPSYNLAJGMNEJ-UHFFFAOYSA-N 0.000 abstract description 4
- 238000012545 processing Methods 0.000 description 10
- 238000010586 diagram Methods 0.000 description 8
- 230000006870 function Effects 0.000 description 7
- 230000007246 mechanism Effects 0.000 description 6
- 238000004891 communication Methods 0.000 description 5
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000011161 development Methods 0.000 description 3
- 238000012986 modification Methods 0.000 description 3
- 230000004048 modification Effects 0.000 description 3
- 230000008901 benefit Effects 0.000 description 2
- 239000012634 fragment Substances 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 239000010453 quartz Substances 0.000 description 2
- 230000005540 biological transmission Effects 0.000 description 1
- 238000004422 calculation algorithm Methods 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000007774 longterm Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000000737 periodic effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5027—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/48—Program initiating; Program switching, e.g. by interrupt
- G06F9/4806—Task transfer initiation or dispatching
- G06F9/4812—Task transfer initiation or dispatching by interrupt, e.g. masked
Definitions
- the present application relates to the field of distributed deployment, and in particular to a distributed application method, device, computer equipment and storage medium.
- Distributed task scheduling refers to assigning multiple tasks divided by an application or business to multiple servers for processing. Distributed task scheduling can solve the problem of insufficient resources of a single server and achieve the purpose of large-scale data computing.
- the existing distributed framework elects a leader server and a follower server through third-party components, such as Zookeeper, Redis and other third-party plug-ins, and uses the leader server as the respective center of the distributed system to manage the follower servers.
- third-party components such as Zookeeper, Redis and other third-party plug-ins
- the inventor realizes that since the third-party components often need to manage many application servers, the operation is more difficult. And the use of third-party components also requires additional maintenance costs.
- Embodiments of the present application provide a distributed application method, device, computer equipment, and storage medium, aiming to solve the problem of increased difficulty in operation and maintenance caused by distributed application programs using third-party components in the prior art.
- the embodiment of the present application provides a distributed application method, which includes: after determining that the target server is started, writing the heartbeat information of the target server to the heartbeat table in the database, the heartbeat table is used to record heartbeat information of servers in the network system; acquiring heartbeat information of at least three servers in the heartbeat table, the at least three servers including the target server; according to the heartbeat information of the at least three servers, sorting the sort the at least three servers to obtain a server sequence; if the target server is the first in the server sequence, then determine that the target server is the leading server; if the target server is not the first in the server sequence One bit, it is determined that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
- the embodiment of the present application provides a distributed application device, which includes: a writing unit, configured to write the heartbeat information of the target server into the heartbeat table in the database after it is determined that the target server is started, so that The heartbeat table is used to record the heartbeat information of servers in the network system; the obtaining unit is used to obtain the heartbeat information of at least three servers in the heartbeat table, and the at least three servers include the target server; the sorting unit is used for According to the heartbeat information of the at least three servers, sort the at least three servers in chronological order to obtain a server sequence; a determining unit configured to determine if the target server is the first in the server sequence The target server is the leading server; the determining unit is further configured to determine that the target server is a follower server or a working server if the target server is not the first in the server sequence, and the working server is The backup server of the follower server.
- the embodiment of the present application further provides a computer device, which includes a memory, a processor, and a computer program stored on the memory and operable on the processor, and the processor executes the computer program.
- the following steps are implemented during the program: after determining that the target server starts, write the heartbeat information of the target server to the heartbeat table in the database, and the heartbeat table is used to record the heartbeat information of the server in the network system; obtain the heartbeat information in the heartbeat table Heartbeat information of at least three servers, the at least three servers including the target server; according to the heartbeat information of the at least three servers, sort the at least three servers in chronological order to obtain a server sequence; if the If the target server is the first in the server sequence, it is determined that the target server is the leading server; if the target server is not the first in the server sequence, then it is determined that the target server is a follower server or a working server server, the working server is the backup server of the following server.
- the embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor performs the following operations : After determining that the target server is started, write the heartbeat information of the target server to the heartbeat table in the database, and the heartbeat table is used to record the heartbeat information of the server in the network system; obtain the at least three servers in the heartbeat table Heartbeat information, the at least three servers include the target server; according to the heartbeat information of the at least three servers, sort the at least three servers in time order to obtain a server sequence; if the target server is the If the target server is the first in the server sequence, it is determined that the target server is the leading server; if the target server is not the first in the server sequence, it is determined that the target server is a follower server or a working server, and the working The server is a backup server of the follower server.
- the embodiment of the present application provides a distributed application method, device, computer equipment and storage medium, through the heartbeat mechanism and database of the server, determine the leading server and follower server in the distributed framework to run the distributed application without the need for a third party
- the component solves the problem of increased difficulty in operation and maintenance caused by the use of third-party components in distributed applications in the prior art, improves the simplicity of distributed applications, and reduces the difficulty of maintaining network systems.
- FIG. 1 is a schematic diagram of an application scenario of a distributed application method provided in an embodiment of the present application
- FIG. 2 is a schematic flowchart of a distributed application method provided by an embodiment of the present application
- FIG. 3 is a schematic flowchart of another distributed application method provided by the embodiment of the present application.
- FIG. 4 is a schematic block diagram of a distributed application device provided by an embodiment of the present application.
- Fig. 5 is a schematic block diagram of a computer device provided by an embodiment of the present application.
- the embodiment of this application provides a distributed application method to describe the solution of this application more clearly. Let's first introduce some knowledge related to distribution.
- Distributed task scheduling refers to assigning multiple tasks divided by an application or business to multiple servers for processing.
- Distributed task scheduling can solve the problem of insufficient resources of a single server and achieve the purpose of large-scale data computing.
- technologies such as Quartz and Zookeeper can implement distributed task scheduling.
- the clustering method of Quartz uses the lock of the database. Only one server is allowed to get the lock to execute the task at the same time. It does not take advantage of the advantages of the cluster to perform parallel execution, and the processing speed is relatively slow.
- Zookeeper is a distributed application coordination service. It fragments the data and assigns it to multiple application servers for processing, which realizes parallel execution and thus improves the processing speed.
- Zookeeper often needs to manage many application servers, the records of the start and end of each task also need to be written into Zookeeper, resulting in a relatively heavy burden on Zookeeper, and if you want to add a new application server, you also need to operate on Zookeeper, further increased its burden.
- nodes distributed on different hosts need to detect the status of other nodes, for example, a server node needs to detect whether a slave node is invalid.
- a message is sent to the peer at regular intervals, and the peer replies with a message. If no reply is received from the peer for a long time, the connection with the peer is disconnected.
- the sender can be either a server or a client, depending on the specific implementation. Because it is sent every fixed time, similar to a heartbeat, the fixed information sent is called a heartbeat packet. Heartbeat packets are mainly used for long-term connections and short-term connections.
- Figure 1 is a schematic diagram of the application scenario of the distributed application method provided by the embodiment of the present application
- Figure 2 is a schematic flow diagram of the distributed application method provided by the embodiment of the present application, the distributed application method is applied to In the server, the method is executed by application software installed in the server.
- the method includes steps S101-S105.
- the distributed application device After the distributed application device determines that the target server is started, it writes the heartbeat information of the target server into the heartbeat table in the database, and the heartbeat table is used to record the heartbeat information of the server in the network system.
- the heartbeat information of the server includes multiple heartbeat time points.
- the distributed application device will periodically write the heartbeat information of the target server to the heartbeat table.
- the heartbeat mechanism of the server is a mechanism to regularly send a custom structure, which is also called a heartbeat packet, to ensure the validity of the connection.
- the distributed application device takes the time point when the server heartbeat packet is detected each time as the heartbeat time point of the server.
- the distributed application device detects the heartbeat packet of a server for the first time within a period of time, it can be determined that the server is started for the first time within the period of time.
- the distributed application device obtains the heartbeat information of at least three servers in the heartbeat table, and the at least three servers include the target server. It can be understood that the at least three servers are in the above network system. After any server of the network system is started, the distributed application device will detect the heartbeat packet of the server, and write the heartbeat information of the server into the heartbeat table.
- the at least three servers are the three servers determined to be activated in the network system. In this embodiment, the three servers determined to be activated can ensure the normal operation of the distributed application. In some other embodiments, the at least three servers are all servers in the network system, and this embodiment can ensure that all servers in the network system can share data and resources of the network system.
- the distributed application device sorts the at least three servers in chronological order according to the heartbeat information of the at least three servers to obtain a server sequence.
- the server sequence sorted by the distributed application device is used to elect a leader server, a follower server and a worker server.
- the distributed application device determines the first heartbeat time point of the at least three servers from the heartbeat information of the at least three servers.
- the first heartbeat time point of the server is the heartbeat time point when the server is written into the heartbeat table by the distributed application device for the first time.
- the distributed application device sorts the at least upper jaw servers in order from far to near on the time axis according to the first heartbeat time point of the at least three servers to obtain a server sequence.
- the heartbeat information of server A includes heartbeat time points: "12:10:12", “12:10:18" and "12:10:24", then the heartbeat time point "12:10 12 seconds" is the first heartbeat time point of server A.
- the time point of the first heartbeat is In order from far to near on the time axis, the server sequence obtained by the distributed application device is server C, server A and server B.
- the distributed application device determines that the target server is the leading server.
- the leading server is mainly responsible for maintaining the distributed cache of the network system, distributed locks and global uniqueness attributes of certain business requirements. If a server is not the dominant server, if the server needs to obtain distributed locks and distributed caches, the server sends an acquisition request to the dominant server, and the server can only be used after receiving the return information that the dominant server agrees to obtain. Requested distributed locks and distributed caches. This method is used to ensure the performance and stability of distributed applications.
- the first server in the server sequence as the leading server can ensure that when there is a server starting up in the network system, the existing server acts as the leading server and allocates resources as the allocation center, which improves the stability of the network system.
- the target server is not the first in the server sequence, determine that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
- the distributed application device determines that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
- the follower server is the backup server of the master server. After the distributed application device determines that the leading server is disconnected, the distributed application device changes a follower server into a leading server to work instead of the original leading server.
- the working (worker) server is a backup server of the follower server in the network system, and works instead of the original follower server after the follower server is disconnected.
- the distributed application device determines that the target server is a follower server; if the target server ranks after the third in the server sequence, the distributed application The device determines that the target server is a working server.
- the preferred setting number of follower servers is 2.
- the 2 follower servers set by the distributed application device facilitate the work of the follower server instead of the original lead server after the lead server is disconnected.
- the server can also ensure that when any follow-up server fails, the other follow-up server can work normally to maintain the stability of the system. At the same time, there is no need to set too many follow-up servers, which reduces the complexity and maintenance difficulty.
- the distributed application device sets the number of following servers as an integer greater than 2. This implementation manner can further maintain the stability of the network system.
- the method realizes the determination of the leading server and the following server in the distributed framework through the heartbeat mechanism and the database of the server, so as to run the distributed application without third-party components, and solves the problem caused by the use of third-party components by the distributed application in the prior art
- the problem of increased difficulty in operation and maintenance improves the simplicity of distributed applications and reduces the difficulty of maintaining network systems.
- FIG. 3 is a schematic flowchart of a distributed application method provided by an embodiment of the present application.
- the distributed application method is applied in a server, and the method is executed by application software installed in the server.
- the method includes steps S201-S210.
- target server is not the first in the server sequence, determine that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
- steps S201-S205 are similar to the steps S101-S105 shown in the embodiment of FIG. 2 , and will not be repeated here.
- the distributed application device After the distributed application device determines the server type of the target server, it adds the type identifier of the target server in the heartbeat table to ensure that each server in the network system can query the role types of all servers in the heartbeat table, so that each server can be classified according to The server type work, maintain the stability of the system.
- the distributed application device checks whether the follower server is disconnected every other time period. It can be that the distributed application device checks whether the follower server is disconnected every other fixed time period. For example, the fixed time period is 2 heartbeat cycle. The distributed application device can also check whether the follower server is disconnected every non-fixed period, which is not limited here and can be adjusted according to specific conditions.
- the distributed application device can determine whether the server is down or disconnected according to the detected heartbeat packet.
- the heartbeat period of the server is fixed. If the distributed application device does not detect the heartbeat packet of the server within two heartbeat periods of the server, it can be determined that the server is down or disconnected.
- the distributed application device selects N work servers to change to follow-up servers, where N is a positive integer.
- N is a positive integer.
- sequence of server startup in the network system indicates the demand structure of servers in the network system, and prioritizing the server that starts up faster in the network system as the leading server can improve the stability of distributed applications.
- the distributed application device checks whether the server whose type is identified as the leading server in the heartbeat table is disconnected at intervals. Wherein, the distributed application device checks whether the leading server is disconnected every other time period. It may be that the distributed application device checks whether the leading server is disconnected every other fixed time period. For example, the fixed time period is 2 heartbeat cycle. The distributed application device can also check whether the leading server is disconnected every non-fixed period, which is not limited here and can be adjusted according to specific conditions.
- the distributed application device determines that the leading server is disconnected, it changes a follower server into a leading server, and broadcasts the changed leading server in the network system. After the distributed application device determines that the leading server is disconnected, it changes the target server to the leading server to replace the original leading server, so as to maintain the normal operation of the network system and improve the stability of the distributed application.
- the distributed application system selects one of the follow-up servers to be the master server.
- the distributed application device selects one of the multiple follower servers to be the master server according to the above server sequence. This method can further improve the stability of distributed applications.
- the method realizes the determination of the leading server and the following server in the distributed framework through the heartbeat mechanism and the database of the server, so as to run the distributed application without third-party components, and solves the problem caused by the use of third-party components by the distributed application in the prior art
- the problem of increased difficulty in operation and maintenance improves the simplicity of distributed applications and reduces the difficulty of maintaining network systems.
- An embodiment of the present application further provides a distributed application device, which is used to execute any embodiment of the foregoing distributed application method.
- FIG. 4 is a schematic block diagram of a distributed application device provided by an embodiment of the present application.
- the distributed application device 100 can be configured in a server.
- the distributed application device 100 includes: a writing unit 110 , an acquiring unit 120 , a sorting list 130 , and a determining unit 140 .
- the writing unit 110 is used to write the heartbeat information of the target server to the heartbeat table in the database after the start of the target server is determined, and the heartbeat table is used to record the heartbeat information of the server in the network system;
- An acquisition unit 120 configured to acquire heartbeat information of at least three servers in the heartbeat table, the at least three servers including the target server;
- the sorting unit 130 is configured to sort the at least three servers in chronological order according to the heartbeat information of the at least three servers, to obtain a server sequence;
- a determining unit 140 configured to determine that the target server is the dominant server if the target server is the first in the server sequence
- the determining unit 140 is further configured to determine that the target server is a follower server or a working server if the target server is not the first in the server sequence, and the working server is a backup server of the follower server.
- the sorting unit 130 is specifically used for:
- the first heartbeat time point of at least three servers determines the first heartbeat time point of at least three servers, and the first heartbeat time period is the heartbeat time point written in the heartbeat table for the first time after the server is started; according to the first heartbeat time point of at least three servers At the heartbeat time point, at least three servers are sorted in order from far to near on the time axis to obtain the server sequence.
- the sorting unit determination unit 140 is specifically used to:
- the target server ranks second or third in the server sequence, it is determined that the target server is a follower server; if the target server ranks after the third in the server sequence, then it is determined that the target server is a working server.
- the device further includes: an adding unit 150, configured to add the type identifier of the target server in the heartbeat table after the server type of the target server is determined, and the server types include a leading server, a follower server and a working server.
- an adding unit 150 configured to add the type identifier of the target server in the heartbeat table after the server type of the target server is determined, and the server types include a leading server, a follower server and a working server.
- the device also includes: a checking unit 160, used to check whether the server whose type in the heartbeat table is identified as a follower server is disconnected every time period; After the included N follower servers are disconnected, select N from the working servers to change to follower servers, where N is a positive integer.
- a checking unit 160 used to check whether the server whose type in the heartbeat table is identified as a follower server is disconnected every time period; After the included N follower servers are disconnected, select N from the working servers to change to follower servers, where N is a positive integer.
- the modifying unit 170 is specifically configured to, after determining that the N following servers contained in the heartbeat table are disconnected, select the first to the Nth servers in the server sequence from the working servers that remain connected.
- the server, as a follower service, N is a positive integer.
- the checking unit 160 is also used to check whether the server whose type is identified as the leading server in the heartbeat table is disconnected every time period; the changing unit 170 is also used to determine whether the leading server is disconnected, Then change a follower server to a leader server, and broadcast the changed leader server in the network system.
- the device realizes the server's heartbeat mechanism and database to determine the leading server and follower server in the distributed framework to run distributed applications without third-party components, and solves the problems caused by the use of third-party components in distributed applications in the prior art
- the problem of increased difficulty in operation and maintenance improves the simplicity of distributed applications and reduces the difficulty of maintaining network systems.
- the above-mentioned distributed application device can be realized in the form of a computer program, and the computer program can be run on the computer device as shown in FIG. 5 .
- FIG. 5 is a schematic block diagram of a computer device provided by an embodiment of the present application.
- the computer device 500 is a server, and the server may be an independent server or a server cluster composed of multiple servers.
- the computer device 500 includes a processor 502 connected through a system bus 501 , a memory and a network interface 505 , where the memory may include a storage medium 503 and an internal memory 504 .
- the storage medium 503 can store an operating system 5031 and a computer program 5032 .
- the computer program 5032 When executed, it can cause the processor 502 to execute the distributed application method.
- the processor 502 is used to provide calculation and control capabilities and support the operation of the entire computer device 500 .
- the internal memory 504 provides an environment for the operation of the computer program 5032 in the storage medium 503.
- the processor 502 can be executed to perform the following steps:
- the heartbeat information of the target server is written into the table, and the heartbeat table is used to record the heartbeat information of the servers in the network system;
- the heartbeat information of at least three servers in the heartbeat table is obtained, and the at least three servers include the target server; according to the heartbeat information of the at least three servers, sort the at least three servers in chronological order to obtain a server sequence; if the target server is the first in the server sequence, then determine the target The server is the leading server; if the target server is not the first in the server sequence, it is determined that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
- the network interface 505 is used for network communication, such as providing data transmission and the like.
- the structure shown in FIG. 5 is only a block diagram of a partial structure related to the solution of this application, and does not constitute a limitation on the computer device 500 to which the solution of this application is applied.
- the specific computer device 500 may include more or fewer components than shown, or combine certain components, or have a different arrangement of components.
- the processor 502 is configured to run the computer program 5032 stored in the memory, so as to realize the distributed application method disclosed in the embodiment of the present application.
- the embodiment of the computer device shown in FIG. 5 does not constitute a limitation on the specific composition of the computer device.
- the computer device may include more or less components than those shown in the illustration. Or combine certain components, or different component arrangements.
- the computer device may only include a memory and a processor. In such an embodiment, the structures and functions of the memory and the processor are consistent with those of the embodiment shown in FIG. 4 , and will not be repeated here.
- the processor 502 may be a central processing unit (Central Processing Unit, CPU), and the processor 502 may also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), Application Specific Integrated Circuit (ASIC), off-the-shelf programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
- the general-purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
- a computer readable storage medium may be a non-volatile computer-readable storage medium, or a volatile computer-readable storage medium.
- the computer-readable storage medium stores a computer program, wherein when the computer program is executed by the processor, the following operations are implemented: after determining that the target server is started, write the heartbeat information of the target server to the heartbeat table in the database, and the heartbeat table For recording the heartbeat information of servers in the network system; obtaining the heartbeat information of at least three servers in the heartbeat table, the at least three servers including the target server; according to the heartbeat information of the at least three servers, according to time Order the at least three servers to obtain a server sequence; if the target server is the first in the server sequence, then determine that the target server is the dominant server; if the target server is not the server The first digit of the sequence determines that the target server is a follower server or a working server, and the working server is a backup server of the follower server.
- the disclosed devices, devices and methods can be implemented in other ways.
- the device embodiments described above are only illustrative.
- the division of units is only for logical function division.
- there may be other division methods, and units with the same function may also be combined into one unit.
- several units or components may be combined or integrated into another system, or some features may be omitted, or not implemented.
- the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices or units, and may also be electrical, mechanical or other forms of connection.
- a unit described as a separate component may or may not be physically separated, and a component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment of the present application.
- each functional unit in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit.
- the above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
- an integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a storage medium.
- the technical solution of the present application is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of software products, and the computer software products are stored in a storage medium
- several instructions are included to make a computer device (which may be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods in the various embodiments of the present application.
- the aforementioned storage medium includes: various media that can store program codes such as U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), magnetic disk or optical disk.
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Hardware Redundancy (AREA)
Abstract
涉及云技术中的云部署领域,公开了分布式应用方法、装置、计算机设备及存储介质,方法包括:在确定目标服务器启动之后,向数据库中的心跳表写入目标服务器的心跳信息,心跳表用于记录网络系统中服务器的心跳信息(S101);获取心跳表中至少三个服务器的心跳信息,至少三个服务器包括目标服务器(S102);根据至少三个服务器的心跳信息,按照时间顺序将至少三个服务器排序,得到服务器序列(S103);若目标服务器为服务器序列中的第一位,则确定目标服务器为主导服务器(S104);若目标服务器不为服务器序列的第一位,则确定目标服务器为跟随服务器或者工作服务器,工作服务器为跟随服务器的备份服务器(S105)。提高了分布式应用的简便性,降低了网络系统的维护难度。
Description
本申请要求于2021年5月31日提交中国专利局、申请号为202110600028.9,申请名称为“分布式应用方法、装置、计算机设备、存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
本申请涉及分布式部署领域,尤其涉及一种分布式应用方法、装置、计算机设备及存储介质。
90年代后期,信息产业出现了分布式对象技术,应用程序可以分布在不同的系统平台上,通过分布式技术实现异构平台间对象的相互通信。将企业已有系统集成于分布式系统,可以极大地提高企业应用系统的扩展性。90年代末出现的多层分布式应用为企业进一步简化应用系统的开发指明了方向。分布式任务调度,是指将一个应用或者业务划分出的多个任务交由多个服务器进行处理。分布式任务调度可解决单个服务器资源不足等问题,达到大规模数据计算的目的。
现有分布式框架有很多,例如Zookeeper技术。分布式应用程序协调服务,其对数据进行分片,分配给多个应用服务器去执行处理,实现了并行执行,从而提升了处理速度。现有的分布式框架通过第三方组件,例如Zookeeper,Redis等第三方插件选举出主导(leader)服务器和跟随(follow)服务器,将主导服务器作为分布式系统的分别中心,对跟随服务器进行管理。但是发明人意识到由于第三方组件往往需要管理很多应用服务器,运营难度较高。且使用第三方组件也需要增加额外的维护成本。
发明内容
本申请实施例提供了一种分布式应用方法、装置、计算机设备及存储介质,旨在解决现有技术中分布式应用程序使用第三方组件造成的运营和维护难度增加的问题。
第一方面,本申请实施例提供了一种分布式应用方法,其包括:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服 务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
第二方面,本申请实施例提供了一种分布式应用装置,其包括:写入单元,用于在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取单元,用于获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;排序单元,用于根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;确定单元,用于若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;所述确定单元,还用于若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
第三方面,本申请实施例又提供了一种计算机设备,其包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现以下步骤:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
第四方面,本申请实施例还提供了一种计算机可读存储介质,其中所述计算机可读存储介质存储有计算机程序,所述计算机程序当被处理器执行时使所述处理器执行以下操作:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
本申请实施例提供了一种分布式应用方法、装置、计算机设备及存储介质,通过服务器的心跳机制和数据库,确定分布式框架中的主导服务器和跟随服务器,以运行分布式应用,无需第三方组件,解决现有技术中分布式应用程序使 用第三方组件造成的运营和维护难度增加的问题,提高了分布式应用的简便性,降低了网络系统的维护难度。
为了更清楚地说明本申请实施例技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1为本申请实施例提供的分布式应用方法的应用场景示意图;
图2为本申请实施例提供的一种分布式应用方法的流程示意图;
图3为本申请实施例提供的另一种分布式应用方法的流程示意图;
图4为本申请实施例提供的分布式应用装置的示意性框图;
图5为本申请实施例提供的计算机设备的示意性框图。
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。
应当理解,当在本说明书和所附权利要求书中使用时,术语“包括”和“包含”指示所描述特征、整体、步骤、操作、元素和/或组件的存在,但并不排除一个或多个其它特征、整体、步骤、操作、元素、组件和/或其集合的存在或添加。
还应当理解,在此本申请说明书中所使用的术语仅仅是出于描述特定实施例的目的而并不意在限制本申请。如在本申请说明书和所附权利要求书中所使用的那样,除非上下文清楚地指明其它情况,否则单数形式的“一”、“一个”及“该”意在包括复数形式。
还应当进一步理解,在本申请说明书和所附权利要求书中使用的术语“和/或”是指相关联列出的项中的一个或多个的任何组合以及所有可能组合,并且包括这些组合。
本申请实施例提供了分布式应用方法,为更清楚的描述本申请的方案。下面先介绍一些与分布式相关的知识。
纵观人类计算机的发展历史,每隔十年至十五年,信息产业就会发生周期性的变革,1950年至1970年期间,企业主要采用大型主机-终端的体系结构,企业应用系统则采用单一、集中的方式为用户提供资源共享服务。80年代初期,开放系统与关系型数据库管理系统被企业大量采用,有别于集中式系统,应用程序逻辑分散在主从两端。随着Windows的普及,90年代则是图形化的应用时 代,客户机(client)和服务器(sever)体系结构也被广泛采用。90年代后期,信息产业出现了分布式对象技术,应用程序可以分布在不同的系统平台上,通过分布式技术实现异构平台间对象的相互通信。将企业已有系统集成于分布式系统,可以极大地提高企业应用系统的扩展性。90年代末出现的多层分布式应用为企业进一步简化应用系统的开发指明了方向。
分布式任务调度,是指将一个应用或者业务划分出的多个任务交由多个服务器进行处理。分布式任务调度可解决单个服务器资源不足等问题,达到大规模数据计算的目的。传统的分布式框架有很多,例如,Quartz、Zookeeper等技术都可以实现分布式任务调度。其中,Quartz的集群方式是利用数据库的锁,同一时间只允许有一台服务器能拿到锁执行任务,没有利用集群的优势并行执行,处理的速度比较慢。Zookeeper是分布式应用程序协调服务,其对数据进行分片,分配给多个应用服务器去执行处理,实现了并行执行,从而提升了处理速度。但是由于Zookeeper往往需要管理很多应用服务器,每个任务开始及结束的记录也都需要写入Zookeeper,造成Zookeeper的负担比较重,而且如果要加入新的应用服务器,也需要在Zookeeper上进行操作,进一步加大了其负担。
在分布式系统中,分布在不同主机上的节点需要检测其他节点的状态,如服务器节点需要检测从节点是否失效。为了检测对方节点的有效性,每隔固定时间就发送一个信息给对方,对方回复一个信息,如果长时间没有收到对方的回复,则断开与对方的连接。发包方既可以是服务端,也可以是客户端,这要看具体实现。因为是每隔固定时间发送一次,类似心跳,所以发送的固定信息称为心跳包。心跳包主要应用于长连接的保持与短线链接。
请参阅图1和图2,图1为本申请实施例提供的分布式应用方法的应用场景示意图;图2为本申请实施例提供的分布式应用方法的流程示意图,该分布式应用方法应用于服务器中,该方法通过安装于服务器中的应用软件进行执行。
如图2所示,该方法包括步骤S101~S105。
S101、在确定目标服务器启动之后,向数据库中的心跳表写入目标服务器的心跳信息,心跳表用于记录网络系统中服务器的心跳信息。
分布式应用装置在确定目标服务器启动之后,向数据库中的心跳表写入目标服务器的心跳信息,心跳表用于记录网络系统中服务器的心跳信息。服务器的心跳信息包括多个心跳时间点。
可以理解的是,分布式应用装置会定期向心跳表写入目标服务器的心跳信息。服务器的心跳机制是定时发送一个自定义的结构体,该结构体又称心跳包,以确保连接的有效性的机制。分布式应用装置将每次检测到服务器心跳包的时间点,作为该服务器的心跳时间点。在分布式应用装置在一个时段内首次检测到一个服务器的心跳包时,可以确定该服务器在这段时间内首次启动。
S102、获取心跳表中至少三个服务器的心跳信息,至少三个服务器包括目 标服务器。
分布式应用装置获取心跳表中至少三个服务器的心跳信息,至少三个服务器包括目标服务器。可以理解的是,该至少三个服务器在上述网络系统中。分布式应用装置在网络系统的任一服务器启动之后,会检测服务器的心跳包,并将服务器的心跳信息写入心跳表中。
在一些实施例中,该至少三个服务器是该网络系统中确定启动的三个服务器,在该实施例中,确定启动的三个服务器能确保分布式应用的正常运行。在另一些实施例中,该至少三个服务器是该网络系统中所有的服务器,该实施例能确保该网络系统所有的服务器能共享网络系统的数据和资源。
S103、根据至少三个服务器的心跳信息,按照时间顺序将至少三个服务器排序,得到服务器序列。
分布式应用装置根据至少三个服务器的心跳信息,按照时间顺序将至少三个服务器排序,得到服务器序列。分布式应用装置排序的服务器序列用于选举主导(leader)服务器、跟随(follower)服务器和工作(worker)服务器。
具体的,分布式应用装置在该至少三个服务器的心跳信息中,确定该至少三个服务器的首次心跳时间点。服务器的首次心跳时间点为该服务器首次被分布式应用装置写入心跳表的心跳时间点。分布式应用装置再根据该至少三个服务器的首次心跳时间点,在时间轴上由远及近的顺序,将该至少上颚服务器进行排序,得到服务器序列。举例说明,服务器A的心跳信息中包含心跳时间点:“12点10分12秒”、“12点10分18秒”和“12点10分24秒”,则心跳时间点“12点10分12秒”为服务器A的首次心跳时间点。若服务器A、服务器B和服务器C的首次心跳时间点分别为“12点10分12秒”、“12点11分0秒”和“12点10分9秒”,则按照首次心跳时间点在时间轴上由远及近的顺序,分布式应用装置得到的服务器序列为服务器C、服务器A和服务器B。
S104、若目标服务器为服务器序列中的第一位,则确定目标服务器为主导服务器。
若目标服务器为服务器序列中的第一位,分布式应用装置则确定目标服务器为主导服务器。主导(leader)服务器作为分布式框架中的分配中心,主要的功能为维护该网络系统的分布式缓存,分布式锁以及某些业务需求的全局唯一性属性。若一个服务器不是主导服务器,在该服务器需求获取分布式锁和分布式缓存的情况下,该服务器向主导服务器发送获取请求,并在接收到主导服务器同意获取的返回信息后,该服务器才可使用请求的分布式锁和分布式缓存。该方式用于保证分布式应用的性能和稳定。
可以理解的是,将服务器序列中第一位的服务器作为主导服务器,可以确保网络系统在存在服务器启动的情况下,存在服务器作为主导服务器作为分配中心分配资源,提高了网络系统的稳定性。
S105、若目标服务器不为服务器序列的第一位,则确定目标服务器为跟随服务器或者工作服务器,工作服务器为跟随服务器的备份服务器。
若目标服务器不为服务器序列的第一位,则分布式应用装置确定目标服务器为跟随服务器或者工作服务器,工作服务器为跟随服务器的备份服务器。
需要说明的是,跟随(follower)服务器为主导服务器的备份服务器。在分布式应用装置确定主导服务器断开连接之后,分布式应用装置将一个跟随服务器更改为主导服务器,代替原有的主导服务器进行工作。而工作(worker)服务器为网络系统中跟随服务器的备份服务器,在跟随服务器断开连接之后,代替原有的跟随服务器进行工作。
具体的,若目标服务器在服务器序列中排在第二位或者第三位,则分布式应用装置确定目标服务器为跟随服务器;若目标服务器在服务器序列中排在第三名之后,则分布式应用装置确定目标服务器为工作服务器。跟随服务器的优选设置数量为2,在该实现方式中,分布式应用装置设置的2个跟随服务器,便于在主导服务器断开连接之后,用跟随服务器代替原有的主导服务器进行工作,2个跟随服务器也可保证在任一跟随服务器发生故障时,另一个跟随服务器可正常工作,维护系统的稳定性,同时不用过多设置跟随服务器,降低了复杂性,也减少了维护难度。
在另一些实施例中,分布式应用装置将跟随服务器的数量设置为大于2的整数。该实现方式能进一步维护网络系统的稳定性。
该方法实现了通过服务器的心跳机制和数据库,确定分布式框架中的主导服务器和跟随服务器,以运行分布式应用,无需第三方组件,解决现有技术中分布式应用程序使用第三方组件造成的运营和维护难度增加的问题,提高了分布式应用的简便性,降低了网络系统的维护难度。
图3为本申请实施例提供的分布式应用方法的流程示意图,该分布式应用方法应用于服务器中,该方法通过安装于服务器中的应用软件进行执行。
如图3所示,该方法包括步骤S201~S210。
S201、在确定目标服务器启动之后,向数据库中的心跳表写入目标服务器的心跳信息,心跳表用于记录网络系统中服务器的心跳信息。
S202、获取心跳表中至少三个服务器的心跳信息,至少三个服务器包括目标服务器。
S203、根据至少三个服务器的心跳信息,按照时间顺序将至少三个服务器排序,得到服务器序列。
S204、若目标服务器为服务器序列中的第一位,则确定目标服务器为主导服务器。
S205、若目标服务器不为服务器序列的第一位,则确定目标服务器为跟随服务器或者工作服务器,工作服务器为跟随服务器的备份服务器。
上述步骤S201~S205与图2实施例所示的步骤S101~S105类似,此处不再赘述。
S206、在确定目标服务器的服务器类型之后,在心跳表中增加目标服务器的类型标识,服务器类型包括主导服务器,跟随服务器和工作服务器。
分布式应用装置在确定目标服务器的服务器类型之后,在心跳表中增加目标服务器的类型标识,以确保网路系统中各服务器能在心跳表中查询所有服务器的角色类型,以使各服务器按照划分的服务器类型工作,维护系统的稳定性。
S207、每隔一个时间段,检查心跳表中类型标识为跟随服务器的服务器,是否断开连接。
其中,分布式应用装置每隔一个时间段,检查跟随服务器是否断开连接,可以是分布式应用装置每隔一个固定时间端,检查跟随服务器是否断开连接,例如固定时间段为跟随服务器的2个心跳周期。分布式应用装置也可以每隔一个非固定周期的,检查跟随服务器是否断开连接,此处不作限制,可根据具体情况进行调整。
需要说明的是,分布式应用装置根据检测到的心跳包,能判断服务器时候是否宕机或者断开连接。服务器的心跳周期是固定的,若在服务器的两个心跳周期内,分布式应用装置未检测到服务器的心跳包,则可确定服务器宕机或者断开连接。
S208、在确定心跳表包含的N个跟随服务器断开连接之后,从工作服务器中选择N个更改为跟随服务器,N为正整数。
分布式应用装置在确定心跳表包含的N个跟随服务器断开连接之后,从工作服务器中选择N个更改为跟随服务器,N为正整数。可选的,分布式应用装置在确定心跳表包含的N个跟随服务器断开连接之后,从保持连接的工作服务器中,选择在服务器序列中排在顺位第一至第N的服务器,作为跟随服务,N为正整数。
需要说明的是,在网络系统中服务器启动的先后性,表明了服务器在网络系统中的需求结构,优先将网络系统中启动较快的服务器作为主导服务器,能提高分布式应用的稳定性。
S209、每隔一个时间段,检查心跳表中类型标识为主导服务器的服务器,是否断开连接。
分布式应用装置每隔一个时间段,检查心跳表中类型标识为主导服务器的服务器,是否断开连接。其中,分布式应用装置每隔一个时间段,检查主导服务器是否断开连接,可以是分布式应用装置每隔一个固定时间端,检查主导服务器是否断开连接,例如固定时间段为主导服务器的2个心跳周期。分布式应用装置也可以每隔一个非固定周期的,检查主导服务器是否断开连接,此处不作限制,可根据具体情况进行调整。
S210、若确定主导服务器断开连接,则将一个跟随服务器更改为主导服务器,并在网络系统中广播更改后的主导服务器。
若分布式应用装置确定主导服务器断开连接,则将一个跟随服务器更改为主导服务器,并在网络系统中广播更改后的主导服务器。分布式应用装置在确定主导服务器断开连接之后,将目标服务器更改为主导服务器,代替原有的主导服务器,以维持网络系统的正常工作,提高了分布式应用的稳定性。
在另一些实施例中,若网络系统中存在两个或两个以上的跟随服务器,则分布式应用系统从多个跟随服务器中选择一个更改为主导服务器。可选的,分布式应用装置根据上述服务器序列从多个跟随服务器中选择一个更改为主导服务器。该方式能进一步提高分布式应用的稳定性。
该方法实现了通过服务器的心跳机制和数据库,确定分布式框架中的主导服务器和跟随服务器,以运行分布式应用,无需第三方组件,解决现有技术中分布式应用程序使用第三方组件造成的运营和维护难度增加的问题,提高了分布式应用的简便性,降低了网络系统的维护难度。
本申请实施例还提供一种分布式应用装置,该分布式应用装置用于执行前述分布式应用方法的任一实施例。具体地,请参阅图4,图4是本申请实施例提供的分布式应用装置的示意性框图。该分布式应用装置100可以配置于服务器中。
如图4所示,分布式应用装置100包括:写入单元110、获取单元120、排序单130、确定单元140。
写入单元110,用于在确定目标服务器启动之后,向数据库中的心跳表写入目标服务器的心跳信息,心跳表用于记录网络系统中服务器的心跳信息;
获取单元120,用于获取心跳表中至少三个服务器的心跳信息,至少三个服务器包括目标服务器;
排序单元130,用于根据至少三个服务器的心跳信息,按照时间顺序将至少三个服务器排序,得到服务器序列;
确定单元140,用于若目标服务器为服务器序列中的第一位,则确定目标服务器为主导服务器;
确定单元140,还用于若目标服务器不为服务器序列的第一位,则确定目标服务器为跟随服务器或者工作服务器,工作服务器为跟随服务器的备份服务器。
在一实施例中,排序单元130具体用于:
在至少三个服务器的心跳信息中,确定至少三个服务器的首次心跳时间点,首次心跳时间段为在服务器启动之后第一次写入心跳表中的心跳时间点;根据至少三个服务器的首次心跳时间点,在时间轴上由远及近的顺序,将至少三个服务器进行排序,得到服务器序列。
在一实施例中,排序单元确定单元140具体用于:
若目标服务器在服务器序列中排在第二位或者第三位,则确定目标服务器为跟随服务器;若目标服务器在服务器序列中排在第三名之后,则确定目标服务器为工作服务器。
在一实施例中,该装置还包括:增加单元150,用于在确定目标服务器的服务器类型之后,在心跳表中增加目标服务器的类型标识,服务器类型包括主导服务器,跟随服务器和工作服务器。
在一实施例中,该装置还包括:检查单元160,用于每隔一个时间段,检查心跳表中类型标识为跟随服务器的服务器,是否断开连接;更改单元170,用于在确定心跳表包含的N个跟随服务器断开连接之后,从工作服务器中选择N个更改为跟随服务器,N为正整数。
在一实施例中,更改单元170具体用于,在确定心跳表包含的N个跟随服务器断开连接之后,从保持连接的工作服务器中,选择在服务器序列中排在顺位第一至第N的服务器,作为跟随服务,N为正整数。
在一实施例中,检查单元160,还用于每隔一个时间段,检查心跳表中类型标识为主导服务器的服务器,是否断开连接;更改单元170还用于若确定主导服务器断开连接,则将一个跟随服务器更改为主导服务器,并在网络系统中广播更改后的主导服务器。
该装置实现了通过服务器的心跳机制和数据库,确定分布式框架中的主导服务器和跟随服务器,以运行分布式应用,无需第三方组件,解决现有技术中分布式应用程序使用第三方组件造成的运营和维护难度增加的问题,提高了分布式应用的简便性,降低了网络系统的维护难度。
上述分布式应用装置可以实现为计算机程序的形式,该计算机程序可以在如图5所示的计算机设备上运行。
请参阅图5,图5是本申请实施例提供的计算机设备的示意性框图。该计算机设备500是服务器,服务器可以是独立的服务器,也可以是多个服务器组成的服务器集群。
参阅图5,该计算机设备500包括通过系统总线501连接的处理器502、存储器和网络接口505,其中,存储器可以包括存储介质503和内存储器504。
该存储介质503可存储操作系统5031和计算机程序5032。该计算机程序5032被执行时,可使得处理器502执行分布式应用方法。
该处理器502用于提供计算和控制能力,支撑整个计算机设备500的运行。
该内存储器504为存储介质503中的计算机程序5032的运行提供环境,该计算机程序5032被处理器502执行时,可使得处理器502执行以下步骤:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;根据所述至 少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
该网络接口505用于进行网络通信,如提供数据信息的传输等。本领域技术人员可以理解,图5中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备500的限定,具体的计算机设备500可以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
其中,处理器502用于运行存储在存储器中的计算机程序5032,以实现本申请实施例公开的分布式应用方法。
本领域技术人员可以理解,图5中示出的计算机设备的实施例并不构成对计算机设备具体构成的限定,在其他实施例中,计算机设备可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。例如,在一些实施例中,计算机设备可以仅包括存储器及处理器,在这样的实施例中,存储器及处理器的结构及功能与图4所示实施例一致,在此不再赘述。
应当理解,在本申请实施例中,处理器502可以是中央处理单元(Central Processing Unit,CPU),该处理器502还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。其中,通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。
在本申请的另一实施例中提供计算机可读存储介质。该计算机可读存储介质可以为非易失性的计算机可读存储介质,也可以为易失性的计算机可读存储介质。该计算机可读存储介质存储有计算机程序,其中计算机程序被处理器执行时实现以下操作:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,上述描述的设备、装置和单元的具体工作过程,可以参考前述方法实施例中的对应过 程,在此不再赘述。本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、计算机软件或者二者的结合来实现,为了清楚地说明硬件和软件的可互换性,在上述说明中已经按照功能一般性地描述了各示例的组成及步骤。这些功能究竟以硬件还是软件方式来执行取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
在本申请所提供的几个实施例中,应该理解到,所揭露的设备、装置和方法,可以通过其它的方式实现。例如,以上所描述的装置实施例仅仅是示意性的,例如,单元的划分,仅仅为逻辑功能划分,实际实现时可以有另外的划分方式,也可以将具有相同功能的单元集合成一个单元,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另外,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口、装置或单元的间接耦合或通信连接,也可以是电的,机械的或其它的形式连接。
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本申请实施例方案的目的。
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以是两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分,或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、磁碟或者光盘等各种可以存储程序代码的介质。
以上,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。
Claims (20)
- 一种分布式应用方法,其中,包括:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
- 根据权利要求1所述的方法,其中,所述根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列,包括:在所述至少三个服务器的心跳信息中,确定所述至少三个服务器的首次心跳时间点,所述首次心跳时间段为在服务器启动之后第一次写入所述心跳表中的心跳时间点;根据所述至少三个服务器的首次心跳时间点,在时间轴上由远及近的顺序,将所述至少三个服务器进行排序,得到所述服务器序列。
- 根据权利要求1所述的方法,其中,所述若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,包括:若所述目标服务器在所述服务器序列中排在第二位或者第三位,则确定所述目标服务器为所述跟随服务器;若所述目标服务器在所述服务器序列中排在第三名之后,则确定所述目标服务器为所述工作服务器。
- 根据权利要求1所述的方法,其中,还包括:在确定所述目标服务器的服务器类型之后,在所述心跳表中增加所述目标服务器的类型标识,所述服务器类型包括所述主导服务器,所述跟随服务器和所述工作服务器。
- 根据权利要求4所述的方法,其中,还包括:每隔一个时间段,检查所述心跳表中所述类型标识为所述跟随服务器的服务器,是否断开连接;在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从所述工作服务器中选择N个更改为所述跟随服务器,N为正整数。
- 根据权利要求5所述的方法,其中,所述在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从所述工作服务器中选择N个更改为所述跟随服务器,所述N为正整数,包括:在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从保持连接的所述工作服务器中,选择在所述服务器序列中排在顺位第一至第N的服务器,作为所述跟随服务,N为正整数。
- 根据权利要求4所述的方法,其中,还包括:每隔一个时间段,检查所述心跳表中所述类型标识为所述主导服务器的服务器,是否断开连接;若确定所述主导服务器断开连接,则将一个所述跟随服务器更改为所述主导服务器,并在所述网络系统中广播更改后的所述主导服务器;
- 一种分布式应用装置,其中,包括:写入单元,用于在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取单元,用于获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;排序单元,用于根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;确定单元,用于若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;所述确定单元,还用于若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
- 一种计算机设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,其中,所述处理器执行所述计算机程序时实现以下步骤:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括所述目标服务器;根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务 器。
- 根据权利要求9所述的计算机设备,其中,所述根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列,包括:在所述至少三个服务器的心跳信息中,确定所述至少三个服务器的首次心跳时间点,所述首次心跳时间段为在服务器启动之后第一次写入所述心跳表中的心跳时间点;根据所述至少三个服务器的首次心跳时间点,在时间轴上由远及近的顺序,将所述至少三个服务器进行排序,得到所述服务器序列。
- 根据权利要求9所述的计算机设备,其中,所述若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,包括:若所述目标服务器在所述服务器序列中排在第二位或者第三位,则确定所述目标服务器为所述跟随服务器;若所述目标服务器在所述服务器序列中排在第三名之后,则确定所述目标服务器为所述工作服务器。
- 根据权利要求9所述的计算机设备,其中,还包括:在确定所述目标服务器的服务器类型之后,在所述心跳表中增加所述目标服务器的类型标识,所述服务器类型包括所述主导服务器,所述跟随服务器和所述工作服务器。
- 根据权利要求12所述的计算机设备,其中,还包括:每隔一个时间段,检查所述心跳表中所述类型标识为所述跟随服务器的服务器,是否断开连接;在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从所述工作服务器中选择N个更改为所述跟随服务器,N为正整数。
- 根据权利要求13所述的计算机设备,其中,所述在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从所述工作服务器中选择N个更改为所述跟随服务器,所述N为正整数,包括:在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从保持连接的所述工作服务器中,选择在所述服务器序列中排在顺位第一至第N的服务器,作为所述跟随服务,N为正整数。
- 一种计算机可读存储介质,其中,所述计算机可读存储介质存储有计算机程序,所述计算机程序当被处理器执行时使所述处理器执行以下操作:在确定目标服务器启动之后,向数据库中的心跳表写入所述目标服务器的心跳信息,所述心跳表用于记录网络系统中服务器的心跳信息;获取所述心跳表中至少三个服务器的心跳信息,所述至少三个服务器包括 所述目标服务器;根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列;若所述目标服务器为所述服务器序列中的第一位,则确定所述目标服务器为主导服务器;若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,所述工作服务器为所述跟随服务器的备份服务器。
- 根据权利要求15所述的计算机可读存储介质,其中,所述根据所述至少三个服务器的心跳信息,按照时间顺序将所述至少三个服务器排序,得到服务器序列,包括:在所述至少三个服务器的心跳信息中,确定所述至少三个服务器的首次心跳时间点,所述首次心跳时间段为在服务器启动之后第一次写入所述心跳表中的心跳时间点;根据所述至少三个服务器的首次心跳时间点,在时间轴上由远及近的顺序,将所述至少三个服务器进行排序,得到所述服务器序列。
- 根据权利要求15所述的计算机可读存储介质,其中,所述若所述目标服务器不为所述服务器序列的第一位,则确定所述目标服务器为跟随服务器或者工作服务器,包括:若所述目标服务器在所述服务器序列中排在第二位或者第三位,则确定所述目标服务器为所述跟随服务器;若所述目标服务器在所述服务器序列中排在第三名之后,则确定所述目标服务器为所述工作服务器。
- 根据权利要求15所述的计算机可读存储介质,其中,还包括:在确定所述目标服务器的服务器类型之后,在所述心跳表中增加所述目标服务器的类型标识,所述服务器类型包括所述主导服务器,所述跟随服务器和所述工作服务器。
- 根据权利要求18所述的计算机可读存储介质,其中,还包括:每隔一个时间段,检查所述心跳表中所述类型标识为所述跟随服务器的服务器,是否断开连接;在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从所述工作服务器中选择N个更改为所述跟随服务器,N为正整数。
- 根据权利要求19所述的计算机可读存储介质,其中,所述在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从所述工作服务器中选择N个更改为所述跟随服务器,所述N为正整数,包括:在确定所述心跳表包含的N个所述跟随服务器断开连接之后,从保持连接 的所述工作服务器中,选择在所述服务器序列中排在顺位第一至第N的服务器,作为所述跟随服务,N为正整数。
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110600028.9 | 2021-05-31 | ||
CN202110600028.9A CN113220464A (zh) | 2021-05-31 | 2021-05-31 | 分布式应用方法、装置、计算机设备、存储介质 |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2022252631A1 true WO2022252631A1 (zh) | 2022-12-08 |
Family
ID=77081973
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2022/071838 WO2022252631A1 (zh) | 2021-05-31 | 2022-01-13 | 分布式应用方法、装置、计算机设备、存储介质 |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN113220464A (zh) |
WO (1) | WO2022252631A1 (zh) |
Families Citing this family (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113220464A (zh) * | 2021-05-31 | 2021-08-06 | 平安科技(深圳)有限公司 | 分布式应用方法、装置、计算机设备、存储介质 |
CN118540364A (zh) * | 2023-02-14 | 2024-08-23 | 中兴通讯股份有限公司 | 分布式文件系统的挂接方法、电子设备及存储介质 |
Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103095845A (zh) * | 2013-01-31 | 2013-05-08 | 汉柏科技有限公司 | 一种实现分布式通信的方法和系统 |
CN108667576A (zh) * | 2018-08-06 | 2018-10-16 | 百度在线网络技术(北京)有限公司 | 消息服务器的主备切换方法、装置和消息服务系统 |
CN111538763A (zh) * | 2020-04-24 | 2020-08-14 | 咪咕文化科技有限公司 | 一种确定集群中主节点的方法、电子设备和存储介质 |
CN111651291A (zh) * | 2020-04-23 | 2020-09-11 | 国网河南省电力公司电力科学研究院 | 一种共享存储集群防脑裂的方法、系统、计算机存储介质 |
CN113220464A (zh) * | 2021-05-31 | 2021-08-06 | 平安科技(深圳)有限公司 | 分布式应用方法、装置、计算机设备、存储介质 |
-
2021
- 2021-05-31 CN CN202110600028.9A patent/CN113220464A/zh active Pending
-
2022
- 2022-01-13 WO PCT/CN2022/071838 patent/WO2022252631A1/zh active Application Filing
Patent Citations (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103095845A (zh) * | 2013-01-31 | 2013-05-08 | 汉柏科技有限公司 | 一种实现分布式通信的方法和系统 |
CN108667576A (zh) * | 2018-08-06 | 2018-10-16 | 百度在线网络技术(北京)有限公司 | 消息服务器的主备切换方法、装置和消息服务系统 |
CN111651291A (zh) * | 2020-04-23 | 2020-09-11 | 国网河南省电力公司电力科学研究院 | 一种共享存储集群防脑裂的方法、系统、计算机存储介质 |
CN111538763A (zh) * | 2020-04-24 | 2020-08-14 | 咪咕文化科技有限公司 | 一种确定集群中主节点的方法、电子设备和存储介质 |
CN113220464A (zh) * | 2021-05-31 | 2021-08-06 | 平安科技(深圳)有限公司 | 分布式应用方法、装置、计算机设备、存储介质 |
Also Published As
Publication number | Publication date |
---|---|
CN113220464A (zh) | 2021-08-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US10997211B2 (en) | Systems and methods for database zone sharding and API integration | |
WO2022252631A1 (zh) | 分布式应用方法、装置、计算机设备、存储介质 | |
TWI710897B (zh) | 資料處理方法和流計算系統 | |
AU2014346369B2 (en) | Managed service for acquisition, storage and consumption of large-scale data streams | |
US10382380B1 (en) | Workload management service for first-in first-out queues for network-accessible queuing and messaging services | |
US11429566B2 (en) | Approach for a controllable trade-off between cost and availability of indexed data in a cloud log aggregation solution such as splunk or sumo | |
US9244958B1 (en) | Detecting and reconciling system resource metadata anomolies in a distributed storage system | |
WO2021129477A1 (zh) | 一种数据同步的方法及相关设备 | |
US9792231B1 (en) | Computer system for managing I/O metric information by identifying one or more outliers and comparing set of aggregated I/O metrics | |
US20200044881A1 (en) | Managing channels in an open data ecosystem | |
US20180248825A1 (en) | Selective distribution of messages in a scalable, real-time messaging system | |
US9438665B1 (en) | Scheduling and tracking control plane operations for distributed storage systems | |
US10860604B1 (en) | Scalable tracking for database udpates according to a secondary index | |
US10275400B1 (en) | Systems and methods for forming a fault-tolerant federated distributed database | |
US10158709B1 (en) | Identifying data store requests for asynchronous processing | |
US10712964B2 (en) | Pre-forking replicas for efficient scaling of a distributed data storage system | |
US12032550B2 (en) | Multi-tenant partitioning in a time-series database | |
US11250019B1 (en) | Eventually consistent replication in a time-series database | |
US20220171792A1 (en) | Ingestion partition auto-scaling in a time-series database | |
US10135703B1 (en) | Generating creation performance metrics for a secondary index of a table | |
US10747739B1 (en) | Implicit checkpoint for generating a secondary index of a table | |
US10237148B2 (en) | Providing a data set for tracking and diagnosing datacenter issues | |
US9893972B1 (en) | Managing I/O requests | |
US10949322B2 (en) | Collecting performance metrics of a device | |
US11093493B1 (en) | Dynamically switching between query and scan for optimizing table reads |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
121 | Ep: the epo has been informed by wipo that ep was designated in this application |
Ref document number: 22814684 Country of ref document: EP Kind code of ref document: A1 |
|
NENP | Non-entry into the national phase |
Ref country code: DE |
|
122 | Ep: pct application non-entry in european phase |
Ref document number: 22814684 Country of ref document: EP Kind code of ref document: A1 |