CN113220464A - Distributed application method and device, computer equipment and storage medium - Google Patents

Distributed application method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN113220464A
CN113220464A CN202110600028.9A CN202110600028A CN113220464A CN 113220464 A CN113220464 A CN 113220464A CN 202110600028 A CN202110600028 A CN 202110600028A CN 113220464 A CN113220464 A CN 113220464A
Authority
CN
China
Prior art keywords
server
servers
heartbeat
sequence
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110600028.9A
Other languages
Chinese (zh)
Inventor
包云飞
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202110600028.9A priority Critical patent/CN113220464A/en
Publication of CN113220464A publication Critical patent/CN113220464A/en
Priority to PCT/CN2022/071838 priority patent/WO2022252631A1/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements 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/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4812Task transfer initiation or dispatching by interrupt, e.g. masked

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

The application relates to the field of cloud deployment, and discloses a distributed application method, a distributed application device, computer equipment and a storage medium, wherein the method comprises the following steps: after the target server is determined to be started, writing heartbeat information of the target server into a heartbeat table in a database, wherein the heartbeat table is used for recording the heartbeat information of a server in a network system; acquiring heartbeat information of at least three servers in a heartbeat table, wherein the at least three servers comprise a target server; sequencing at least three servers according to the heartbeat information of at least three servers and the time sequence to obtain a server sequence; if the target server is the first in the server sequence, determining the target server as a leading server; and if the target server is not the first position of the server sequence, determining that the target server is a following server or a working server, and the working server is a backup server of the following server. The simplicity of distributed application is improved, and the maintenance difficulty of a network system is reduced.

Description

Distributed application method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of distributed deployment, and in particular, to a distributed application method, apparatus, computer device, and storage medium.
Background
In the later 90 s, distributed object technology appeared in the information industry, and application programs can be distributed on different system platforms, so that the mutual communication of objects among heterogeneous platforms is realized through the distributed technology. The existing system of the enterprise is integrated in the distributed system, so that the expansibility of the enterprise application system can be greatly improved. The advent of multi-tiered distributed applications in the late 90 s has indicated a direction for enterprises to further simplify the development of application systems. Distributed task scheduling refers to processing multiple tasks divided from one application or service by multiple servers. The distributed task scheduling can solve the problems of insufficient resources of a single server and the like, and achieves the purpose of large-scale data calculation.
There are many existing distributed frameworks, such as Zookeeper technology. The distributed application program coordination service is used for fragmenting data and distributing the fragmented data to a plurality of application servers to execute processing, so that parallel execution is realized, and the processing speed is increased. In the existing distributed framework, a leading (leader) server and a following (follow) server are elected by a third-party component, such as a Zookeeper, Redis and other third-party plug-in components, and the leading server is used as a separate center of a distributed system to manage the following servers. However, since the third-party component often needs to manage many application servers, the operation difficulty is high. And the use of third party components also requires additional maintenance costs.
Disclosure of Invention
The embodiment of the application provides a distributed application method, a distributed application device, computer equipment and a storage medium, and aims to solve the problem that operation and maintenance difficulty is increased due to the fact that a third-party component is used by a distributed application program in the prior art.
In a first aspect, an embodiment of the present application provides a distributed application method, which includes: after the target server is determined to be started, writing heartbeat information of the target server into a heartbeat table in a database, wherein the heartbeat table is used for recording the heartbeat information of a server in a network system; acquiring heartbeat information of at least three servers in the heartbeat table, wherein the at least three servers comprise the target server; sequencing the at least three servers according to the heartbeat information of the at least three servers and the time sequence to obtain a server sequence; if the target server is the first in the server sequence, determining that the target server is a leading server; and if the target server is not the first position of the server sequence, determining that the target server is a following server or a working server, wherein the working server is a backup server of the following server.
In an optional implementation manner, the sorting the at least three servers according to the heartbeat information of the at least three servers in a time order to obtain a server sequence includes: determining first heartbeat time points of the at least three servers in heartbeat information of the at least three servers, wherein the first heartbeat time period is a heartbeat time point written into the heartbeat table for the first time after the servers are started; and sequencing the at least three servers from far to near on a time axis according to the first heartbeat time points of the at least three servers to obtain the server sequence.
In an optional implementation manner, the determining that the target server is a following server or a working server if the target server is not the first bit of the server sequence includes: if the target server is ranked at the second place or the third place in the server sequence, determining that the target server is the following server; and if the target server is ranked behind a third name in the server sequence, determining that the target server is the working server.
In an optional implementation manner, the method further includes: after determining the server type of the target server, adding a type identifier of the target server in the heartbeat table, wherein the server type comprises the leading server, the following server and the working server.
In an optional implementation manner, the method further includes: checking whether the server with the type identifier as the following server in the heartbeat table is disconnected every other time period; after N follow-up servers contained in the heartbeat table are determined to be disconnected, N follow-up servers are selected from the working servers to be changed into the follow-up servers, wherein N is a positive integer.
In an optional implementation manner, after determining that N follower servers included in the heartbeat table are disconnected, selecting N follower servers from the work servers to change to the follower servers, where N is a positive integer, includes: after N following servers contained in the heartbeat table are determined to be disconnected, selecting servers ranked from the first to the Nth in the order in the server sequence from the working servers which are kept connected as the following servers, wherein N is a positive integer.
In an optional implementation manner, the method further includes: checking whether the master server is disconnected every other time period; and if the master server is determined to be disconnected, changing one following server into the master server, and broadcasting the changed master server in the network system.
In a second aspect, an embodiment of the present application provides a distributed application apparatus, which includes: the device comprises a writing unit, a judging unit and a processing unit, wherein the writing unit is used for writing heartbeat information of a target server into a heartbeat table in a database after the target server is determined to be started, and the heartbeat table is used for recording the heartbeat information of a server in a network system; an obtaining unit, configured to obtain heartbeat information of at least three servers in the heartbeat table, where the at least three servers include the target server; the sequencing unit is used for sequencing the at least three servers according to the heartbeat information of the at least three servers and the time sequence to obtain a server sequence; a determining unit, configured to determine that the target server is a master server if the target server is a first place in the server sequence; the determining unit is further configured to determine that the target server is a following server or a working server if the target server is not the first position of the server sequence, and the working server is a backup server of the following server.
In an optional implementation manner, the sorting unit is specifically configured to: determining first heartbeat time points of the at least three servers in heartbeat information of the at least three servers, wherein the first heartbeat time period is a heartbeat time point written into the heartbeat table for the first time after the servers are started; and sequencing the at least three servers from far to near on a time axis according to the first heartbeat time points of the at least three servers to obtain the server sequence.
In an optional implementation manner, the sorting unit determining unit is specifically configured to: if the target server is ranked at the second place or the third place in the server sequence, determining that the target server is the following server; and if the target server is ranked behind a third name in the server sequence, determining that the target server is the working server.
In an optional implementation, the apparatus further includes: and the adding unit is used for adding the type identifier of the target server in the heartbeat table after determining the server type of the target server, wherein the server type comprises the leading server, the following server and the working server.
In an optional implementation, the apparatus further includes: a checking unit, configured to check, every other time period, whether the server with the type identifier as the following server in the heartbeat table is disconnected; and the changing unit is used for selecting N following servers from the working servers to be changed into the following servers after the disconnection of the N following servers contained in the heartbeat table is determined, wherein N is a positive integer.
In an optional implementation manner, the changing unit is specifically configured to, after determining that N following servers included in the heartbeat table are disconnected, select, from the working servers that remain connected, a server that is ranked first to nth in the order in the server sequence as the following service, where N is a positive integer.
In an optional implementation manner, the checking unit is further configured to check, every other time period, whether the server of which the type identifier is the master server in the heartbeat table is disconnected; and the changing unit is further used for changing one following server into the leading server and broadcasting the changed leading server in the network system if the leading server is determined to be disconnected.
In a third aspect, an 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 executable on the processor, and the processor implements the distributed application method described in the first aspect when executing the computer program.
In a fourth aspect, this application further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, causes the processor to execute the distributed application method according to the first aspect.
The embodiment of the application provides a distributed application method and device, computer equipment and a storage medium, wherein a leading server and a following server in a distributed framework are determined through a heartbeat mechanism and a database of the server so as to run the distributed application, a third-party component is not needed, the problem that operation and maintenance difficulty are increased due to the fact that a distributed application program uses the third-party component in the prior art is solved, simplicity of the distributed application is improved, and maintenance difficulty of a network system is reduced.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic view of an application scenario of a distributed application method according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a distributed application method according to an embodiment of the present application;
fig. 3 is a schematic flowchart of another distributed application method provided in an embodiment of the present application;
fig. 4 is a schematic block diagram of a distributed application apparatus provided in an embodiment of the present application;
fig. 5 is a schematic block diagram of a computer device provided in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the present application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in the specification of the present application and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
It should be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
The embodiment of the invention provides a distributed application method, and the scheme of the invention is more clearly described. Some knowledge related to the distribution is first introduced below.
Throughout the development history of human computers, the information industry will change periodically every ten years to fifteen years, and during the period from 1950 to 1970, enterprises mainly adopt a large host-terminal architecture, and enterprise application systems adopt a single and centralized mode to provide resource sharing services for users. In the early 80 s, the open system and the relational database management system were adopted by enterprises in large quantities, which is different from the centralized system, and the application program logic is dispersed at the master and the slave. With the popularization of Windows, the 90 s are graphical application times, and the client (client) and server (server) architectures are widely adopted. In the later 90 s, distributed object technology appeared in the information industry, and application programs can be distributed on different system platforms, so that the mutual communication of objects among heterogeneous platforms is realized through the distributed technology. The existing system of the enterprise is integrated in the distributed system, so that the expansibility of the enterprise application system can be greatly improved. The advent of multi-tiered distributed applications in the late 90 s has indicated a direction for enterprises to further simplify the development of application systems.
Distributed task scheduling refers to processing multiple tasks divided from one application or service by multiple servers. The distributed task scheduling can solve the problems of insufficient resources of a single server and the like, and achieves the purpose of large-scale data calculation. There are many conventional distributed frameworks, for example, Quartz, Zookeeper, etc. can implement distributed task scheduling. The Quartz cluster mode is to use the lock of a database, only one server is allowed to take the lock to execute tasks at the same time, the advantages of the cluster are not used, parallel execution is achieved, and the processing speed is low. Zookeeper is a distributed application program coordination service, which fragments data and distributes the data to a plurality of application servers to execute processing, thereby realizing parallel execution and improving the processing speed. However, since the Zookeeper usually needs to manage many application servers, the record of the start and the end of each task also needs to be written into the Zookeeper, which causes a heavy burden on the Zookeeper, and if a new application server needs to be added, the operation needs to be performed on the Zookeeper, which further increases the burden.
In a distributed system, nodes distributed on different hosts need to detect the state of other nodes, for example, a server node needs to detect whether a slave node fails. In order to detect the validity of the node of the other side, a message is sent to the other side at fixed time intervals, the other side replies a message, and if the reply of the other side is not received for a long time, the connection with the other side is disconnected. The contracting party can be a server side or a client side, and the specific implementation is needed. Since the fixed information is transmitted at fixed time intervals, similar to a heartbeat, the transmitted fixed information is called a heartbeat packet. The heartbeat packet is mainly applied to the keeping of long connection and short line linkage.
Referring to fig. 1 and fig. 2, fig. 1 is a schematic view of an application scenario of a distributed application method according to an embodiment of the present application; fig. 2 is a schematic flowchart of a distributed application method provided in an embodiment of the present application, where the distributed application method is applied to a server, and the method is executed by application software installed in the server.
As shown in fig. 2, the method includes steps S101 to S105.
S101, after the target server is determined to be started, writing heartbeat information of the target server into a heartbeat table in a database, wherein the heartbeat table is used for recording the heartbeat information of the server in the network system.
After determining that the target server is started, the distributed application device writes heartbeat information of the target server into a heartbeat table in the database, wherein the heartbeat table is used for recording heartbeat information of a server in the network system. The heartbeat information of the server includes a plurality of heartbeat time points.
It is understood that 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 for regularly sending a self-defined structure, which is also called a heartbeat packet, so as to ensure the validity of the connection. The distributed application device takes the time point of each detection of the server heartbeat packet as the heartbeat time point of the server. When a distributed application device first detects a heartbeat packet of a server within a period of time, it may be determined that the server first starts within the period of time.
S102, acquiring heartbeat information of at least three servers in a heartbeat table, wherein the at least three servers comprise a target server.
The distributed application device acquires heartbeat information of at least three servers in the heartbeat table, wherein the at least three servers comprise a target server. It is to be understood that the at least three servers are in the network system described above. After any server of the network system is started, the distributed application device detects the heartbeat packet of the server and writes the heartbeat information of the server into the heartbeat table.
In some embodiments, the at least three servers are the determined three servers to be started in the network system, and in this embodiment, the determined three servers to be started can ensure the normal operation of the distributed application. In other embodiments, where the at least three servers are all servers in the network system, the embodiment ensures that all servers in the network system share data and resources of the network system.
S103, sequencing the at least three servers according to the time sequence according to the heartbeat information of the at least three servers to obtain a server sequence.
The distributed application device sorts the at least three servers according to the heartbeat information of the at least three servers and the time sequence to obtain a server sequence. The server sequence ordered by the distributed application device is used for electing a leader (leader) server, a follower (follower) server and a worker (worker) server.
Specifically, the distributed application apparatus determines a first heartbeat time point of the at least three servers in the heartbeat information of the at least three servers. The first heartbeat time point of the server is the heartbeat time point of the server which is written into the heartbeat table by the distributed application device for the first time. And the distributed application device sorts the at least palate server in a sequence from far to near on a time axis according to the first heartbeat time points of the at least three servers to obtain a server sequence. For example, the heartbeat information of the server a includes heartbeat time points: "12 o 'clock 10 min 12 sec", "12 o' clock 10 min 18 sec", and "12 o 'clock 10 min 24 sec", the heartbeat time point "12 o' clock 10 min 12 sec" is the first heartbeat time point of server a. If the first heartbeat time points of the server a, the server B and the server C are respectively "12 o ' clock 10 min 12 sec", "12 o ' clock 11 min 0 sec" and "12 o ' clock 10 min 9 sec", the server sequences obtained by the distributed application apparatus are the server C, the server a and the server B according to the sequence of the first heartbeat time points from far to near on the time axis.
And S104, if the target server is the first position in the server sequence, determining that the target server is the leading server.
And if the target server is the first in the server sequence, the distributed application device determines that the target server is the leading server. The leading (leader) server serves as a distribution center in the distributed framework, and the main function is to maintain the distributed caches, distributed locks and global uniqueness attributes of certain service requirements of the network system. If a server is not the leading server, the server sends an acquisition request to the leading server under the condition that the server needs to acquire the distributed lock and the distributed cache, and the server can use the requested distributed lock and the distributed cache after receiving the return information which is approved by the leading server to acquire. This approach is used to ensure performance and stability of distributed applications.
It can be understood that, taking the first server in the server sequence as the leading server can ensure that the presence server serves as the leading server to allocate resources as an allocation center under the condition that the presence server of the network system is started, thereby improving the stability of the network system.
And S105, if the target server is not the first position of the server sequence, determining that the target server is a following server or a working server, and determining that the working server is a backup server of the following server.
And if the target server is not the first position of the server sequence, the distributed application device determines that the target server is a following server or a working server, and the working server is a backup server of the following server.
Note that the following (follower) server is a backup server of the leading server. After the distributed application device determines that the leading server is disconnected, the distributed application device changes a following server into the leading server to replace the original leading server to work. And the work (worker) server is a backup server of the following server in the network system, and replaces the original following server to work after the following server is disconnected.
Specifically, if the target server is ranked at the second place or the third place in the server sequence, the distributed application apparatus determines that the target server is a following server; if the target server is ranked after the third name in the server sequence, the distributed application device determines that the target server is a working server. The preferred quantity that sets up of following the server is 2, and in this implementation, the server is followed to 2 that distributed application device set up, is convenient for after leading server disconnection, replaces original leading server with following the server and carries out work, and 2 follow the server and also can guarantee when arbitrary following server breaks down, and another follows server and can normally work, maintains the stability of system, need not set up too much simultaneously and follows the server, has reduced the complexity, has also reduced and has maintained the degree of difficulty.
In other embodiments, the distributed application sets the number of following servers to an integer greater than 2. The implementation mode can further maintain the stability of the network system.
The method realizes that the leading server and the following server in the distributed framework are determined through the heartbeat mechanism and the database of the server so as to run the distributed application, a third-party component is not needed, the problem that operation and maintenance difficulty is increased due to the fact that the distributed application program uses the third-party component in the prior art is solved, simplicity of the distributed application is improved, and maintenance difficulty of a network system is reduced.
Fig. 3 is a schematic flowchart of a distributed application method provided in an embodiment of the present application, where the distributed application method is applied to a server, and the method is executed by application software installed in the server.
As shown in fig. 3, the method includes steps S201 to S210.
S201, after the target server is determined to be started, writing heartbeat information of the target server into a heartbeat table in a database, wherein the heartbeat table is used for recording the heartbeat information of the server in the network system.
S202, acquiring heartbeat information of at least three servers in the heartbeat table, wherein the at least three servers comprise a target server.
S203, sequencing the at least three servers according to the time sequence according to the heartbeat information of the at least three servers to obtain a server sequence.
And S204, if the target server is the first position in the server sequence, determining that the target server is the leading server.
And S205, if the target server is not the first position of the server sequence, determining that the target server is a following server or a working server, and determining that the working server is a backup server of the following server.
The steps S201 to S205 are similar to the steps S101 to S105 shown in the embodiment of fig. 2, and are not described again here.
S206, after the server type of the target server is determined, the type identification of the target server is added in the heartbeat table, and the server type comprises a leading server, a following server and a working server.
After determining the server type of the target server, the distributed application device adds the type identifier of the target server in the heartbeat table to ensure that each server in the network system can inquire the role types of all servers in the heartbeat table, so that each server works according to the divided server types and the stability of the system is maintained.
And S207, checking whether the server with the type identification as the following server in the heartbeat table is disconnected every other time period.
The distributed application apparatus checks whether the following server is disconnected every other time period, which may be that the distributed application apparatus checks whether the following server is disconnected every other fixed time period, for example, the fixed time period is 2 heartbeat cycles of the following server. The distributed application apparatus may also check whether the following server is disconnected every other non-fixed period, which is not limited herein and may be adjusted according to specific situations.
It should be noted that the distributed application apparatus can determine whether the server is down or disconnected according to the detected heartbeat packet. The heartbeat period of the server is fixed, and if the distributed application device does not detect the heartbeat packet of the server in two heartbeat periods of the server, the server can be determined to be down or disconnected.
S208, after the fact that the N following servers contained in the heartbeat table are disconnected is determined, N following servers are selected from the working servers and changed into the following servers, and N is a positive integer.
And after the distributed application device determines that the N following servers contained in the heartbeat table are disconnected, selecting N following servers from the working servers to be changed into the following servers, wherein N is a positive integer. Optionally, after determining that N following servers included in the heartbeat table are disconnected, the distributed application apparatus selects, from the working servers that maintain the connection, a server ranked in the order from the first to the nth in the server sequence as a following service, where N is a positive integer.
It should be noted that the starting sequence of the servers in the network system indicates the structure of the server requirements in the network system, and the server which is started faster in the network system is preferentially used as the leading server, so that the stability of the distributed application can be improved.
S209, every other time period, checking whether the server with the type identification as the leading server in the heartbeat table is disconnected.
And the distributed application device checks whether the server with the type identification as the leading server in the heartbeat table is disconnected every other time period. The distributed application apparatus checks whether the master server is disconnected every other time period, which may be that the distributed application apparatus checks whether the master server is disconnected every other fixed time period, for example, the fixed time period is 2 heartbeat cycles of the master server. The distributed application apparatus may also check whether the master server is disconnected every other non-fixed period, which is not limited herein and may be adjusted according to specific situations.
S210, if the master server is determined to be disconnected, changing one following server into the master server, and broadcasting the changed master server in the network system.
And if the distributed application device determines that the leading server is disconnected, changing one following server into the leading server, and broadcasting the changed leading server in the network system. After the distributed application device determines that the leading server is disconnected, the target server is changed into the leading server to replace the original leading server, so that the normal work of a network system is maintained, and the stability of distributed application is improved.
In other embodiments, if two or more follower servers are present in the network system, the distributed application system selects one of the plurality of follower servers to change to the leading server. Optionally, the distributed application apparatus selects one of the following servers to change into the leading server according to the server sequence. This approach can further improve the stability of distributed applications.
The method realizes that the leading server and the following server in the distributed framework are determined through the heartbeat mechanism and the database of the server so as to run the distributed application, a third-party component is not needed, the problem that operation and maintenance difficulty is increased due to the fact that the distributed application program uses the third-party component in the prior art is solved, simplicity of the distributed application is improved, and maintenance difficulty of a network system is reduced.
Embodiments of the present application further provide a distributed application apparatus, where the distributed application apparatus is configured to execute any embodiment of the foregoing distributed application method. Specifically, referring to fig. 4, fig. 4 is a schematic block diagram of a distributed application apparatus according to an embodiment of the present application. The distributed application apparatus 100 may be configured in a server.
As shown in fig. 4, the distributed application apparatus 100 includes: a writing unit 110, an obtaining unit 120, a sorting unit 130, and a determining unit 140.
A writing unit 110, configured to write heartbeat information of a target server into a heartbeat table in a database after it is determined that the target server is started, where the heartbeat table is used to record heartbeat information of a server in a network system;
an obtaining unit 120, configured to obtain heartbeat information of at least three servers in a heartbeat table, where the at least three servers include a target server;
the sorting unit 130 is configured to sort the at least three servers according to the heartbeat information of the at least three servers and according to a time sequence to obtain a server sequence;
a determining unit 140, configured to determine that the target server is the leading 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 following 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 following server.
In an embodiment, the sorting unit 130 is specifically configured to:
determining first heartbeat time points of at least three servers in heartbeat information of at least three servers, wherein the first heartbeat time period is a heartbeat time point written into a heartbeat table for the first time after the servers are started; and sequencing the at least three servers from far to near on a time axis according to the first heartbeat time points of the at least three servers to obtain a server sequence.
In an embodiment, the sorting unit determining unit 140 is specifically configured to:
if the target server is ranked at the second place or the third place in the server sequence, determining the target server as a following server; and if the target server is ranked behind the third name in the server sequence, determining the target server as the working server.
In one embodiment, the apparatus further comprises: and the adding unit 150 is used for adding the type identification of the target server in the heartbeat table after determining the server type of the target server, wherein the server type comprises a leading server, a following server and a working server.
In one embodiment, the apparatus further comprises: a checking unit 160, configured to check, every other time period, whether the server with the type identifier of the server in the heartbeat table is disconnected; a changing unit 170, configured to select N following servers included in the heartbeat table to be changed into following servers after determining that the N following servers are disconnected, where N is a positive integer.
In an embodiment, the changing unit 170 is specifically configured to, after determining that N following servers included in the heartbeat table are disconnected, select, from the working servers that maintain the connection, a server that is ranked first to nth in the server sequence as a following service, where N is a positive integer.
In an embodiment, the checking unit 160 is further configured to check, every other time period, whether the server with the type identified as the master server in the heartbeat table is disconnected; the changing unit 170 is further configured to change a following server to the leading server if it is determined that the leading server is disconnected, and broadcast the changed leading server in the network system.
The device realizes that the leading server and the following server in the distributed framework are determined through the heartbeat mechanism and the database of the server so as to run the distributed application, a third-party component is not needed, the problem that operation and maintenance difficulty are increased due to the fact that the distributed application program uses the third-party component in the prior art is solved, simplicity of the distributed application is improved, and maintenance difficulty of a network system is reduced.
The above described distributed application apparatus may be implemented in the form of a computer program which may be run on a computer device as shown in fig. 5.
Referring to fig. 5, fig. 5 is a schematic block diagram of a computer device according to 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 a plurality of servers.
Referring to fig. 5, the computer device 500 includes a processor 502, memory, and a network interface 505 connected by a system bus 501, where the memory may include a storage medium 503 and an internal memory 504.
The storage medium 503 may store an operating system 5031 and a computer program 5032. The computer program 5032, when executed, may cause the processor 502 to perform a distributed application method.
The processor 502 is used to provide computing and control capabilities that support the operation of the overall computer device 500.
The internal memory 504 provides an environment for the execution of the computer program 5032 in the storage medium 503, and when the computer program 5032 is executed by the processor 502, the processor 502 can be caused to execute the distributed application method.
The network interface 505 is used for network communication, such as providing transmission of data information. Those skilled in the art will appreciate that the configuration shown in fig. 5 is a block diagram of only a portion of the configuration associated with the present application and does not constitute a limitation of the computer device 500 to which the present application may be applied, and that a particular computer device 500 may include more or less components than those shown, or may 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 to implement the distributed application method disclosed in the embodiment of the present application.
Those skilled in the art will appreciate that the embodiment of a computer device illustrated in fig. 5 does not constitute a limitation on the specific construction of the computer device, and that in other embodiments a computer device may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. For example, in some embodiments, the computer device may only include a memory and a processor, and in such embodiments, the structures and functions of the memory and the processor are consistent with those of the embodiment shown in fig. 4, and are not described herein again.
It should be understood that in the embodiment of the present Application, the Processor 502 may be a Central Processing Unit (CPU), and the Processor 502 may also be other general purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In another embodiment of the present application, a computer-readable storage medium is provided. The computer-readable storage medium may be a nonvolatile computer-readable storage medium or a volatile computer-readable storage medium. The computer readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the distributed application method disclosed in the embodiments of the present application.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, devices and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. Those of ordinary skill in the art will appreciate that the elements and algorithm steps of the examples described in connection with the embodiments disclosed herein may be embodied in electronic hardware, computer software, or combinations of both, and that the components and steps of the examples have been described in a functional general in the foregoing description for the purpose of illustrating clearly the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus, device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only a logical division, and there may be other divisions when the actual implementation is performed, or units having the same function may be grouped into one unit, for example, a plurality of units or components may be combined or may be integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may also be an electric, mechanical or other form of connection.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiments of the present application.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a storage medium. Based on such understanding, the technical solution of the present application may be substantially or partially contributed by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method of the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-only memory (ROM), a magnetic disk, or an optical disk.
While the invention has been described with reference to specific embodiments, the scope of the invention is not limited thereto, and those skilled in the art can easily conceive various equivalent modifications or substitutions within the technical scope of the invention, and these modifications or substitutions are intended to be included in the scope of the invention. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A distributed application method, comprising:
after the target server is determined to be started, writing heartbeat information of the target server into a heartbeat table in a database, wherein the heartbeat table is used for recording the heartbeat information of a server in a network system;
acquiring heartbeat information of at least three servers in the heartbeat table, wherein the at least three servers comprise the target server;
sequencing the at least three servers according to the heartbeat information of the at least three servers and the time sequence to obtain a server sequence;
if the target server is the first in the server sequence, determining that the target server is a leading server;
and if the target server is not the first position of the server sequence, determining that the target server is a following server or a working server, wherein the working server is a backup server of the following server.
2. The method according to claim 1, wherein the sorting the at least three servers in time order according to the heartbeat information of the at least three servers to obtain a server sequence comprises:
determining first heartbeat time points of the at least three servers in heartbeat information of the at least three servers, wherein the first heartbeat time period is a heartbeat time point written into the heartbeat table for the first time after the servers are started;
and sequencing the at least three servers from far to near on a time axis according to the first heartbeat time points of the at least three servers to obtain the server sequence.
3. The method of claim 1, wherein determining that the target server is a following server or a working server if the target server is not the first in the sequence of servers comprises:
if the target server is ranked at the second place or the third place in the server sequence, determining that the target server is the following server;
and if the target server is ranked behind a third name in the server sequence, determining that the target server is the working server.
4. The method according to any one of claims 1-3, further comprising:
after determining the server type of the target server, adding a type identifier of the target server in the heartbeat table, wherein the server type comprises the leading server, the following server and the working server.
5. The method of claim 4, further comprising:
checking whether the server with the type identifier as the following server in the heartbeat table is disconnected every other time period;
after N follow-up servers contained in the heartbeat table are determined to be disconnected, N follow-up servers are selected from the working servers and changed into the follow-up servers, wherein N is a positive integer.
6. The method of claim 5, wherein the selecting N changes from the working servers to the follower servers after determining that N follower servers included in the heartbeat table are disconnected, wherein N is a positive integer, comprises:
after N following servers contained in the heartbeat table are determined to be disconnected, selecting servers ranked from the first to the Nth in the order in the server sequence from the working servers which are kept connected as the following servers, wherein N is a positive integer.
7. The method of claim 4, further comprising:
checking whether the server with the type identification as the master server in the heartbeat table is disconnected every other time period;
and if the master server is determined to be disconnected, changing one following server into the master server, and broadcasting the changed master server in the network system.
8. A distributed application apparatus, comprising:
the device comprises a writing unit, a judging unit and a processing unit, wherein the writing unit is used for writing heartbeat information of a target server into a heartbeat table in a database after the target server is determined to be started, and the heartbeat table is used for recording the heartbeat information of a server in a network system;
an obtaining unit, configured to obtain heartbeat information of at least three servers in the heartbeat table, where the at least three servers include the target server;
the sequencing unit is used for sequencing the at least three servers according to the heartbeat information of the at least three servers and the time sequence to obtain a server sequence;
a determining unit, configured to determine that the target server is a master server if the target server is a first place in the server sequence;
the determining unit is further configured to determine that the target server is a following server or a working server if the target server is not the first position of the server sequence, and the working server is a backup server of the following server.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the distributed application method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which, when executed by a processor, causes the processor to carry out the distributed application method according to any one of claims 1 to 7.
CN202110600028.9A 2021-05-31 2021-05-31 Distributed application method and device, computer equipment and storage medium Pending CN113220464A (en)

Priority Applications (2)

Application Number Priority Date Filing Date Title
CN202110600028.9A CN113220464A (en) 2021-05-31 2021-05-31 Distributed application method and device, computer equipment and storage medium
PCT/CN2022/071838 WO2022252631A1 (en) 2021-05-31 2022-01-13 Method and apparatus for distributed application, and computer device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110600028.9A CN113220464A (en) 2021-05-31 2021-05-31 Distributed application method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113220464A true CN113220464A (en) 2021-08-06

Family

ID=77081973

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110600028.9A Pending CN113220464A (en) 2021-05-31 2021-05-31 Distributed application method and device, computer equipment and storage medium

Country Status (2)

Country Link
CN (1) CN113220464A (en)
WO (1) WO2022252631A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022252631A1 (en) * 2021-05-31 2022-12-08 平安科技(深圳)有限公司 Method and apparatus for distributed application, and computer device and storage medium

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103095845B (en) * 2013-01-31 2016-08-03 汉柏科技有限公司 A kind of method and system realizing distributed communication
CN108667576A (en) * 2018-08-06 2018-10-16 百度在线网络技术(北京)有限公司 Main/standby switching method, device and the message service system of message server
CN111651291B (en) * 2020-04-23 2023-02-03 国网河南省电力公司电力科学研究院 Method, system and computer storage medium for preventing split brain of shared storage cluster
CN111538763B (en) * 2020-04-24 2023-08-15 咪咕文化科技有限公司 Method for determining master node in cluster, electronic equipment and storage medium
CN113220464A (en) * 2021-05-31 2021-08-06 平安科技(深圳)有限公司 Distributed application method and device, computer equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022252631A1 (en) * 2021-05-31 2022-12-08 平安科技(深圳)有限公司 Method and apparatus for distributed application, and computer device and storage medium

Also Published As

Publication number Publication date
WO2022252631A1 (en) 2022-12-08

Similar Documents

Publication Publication Date Title
US20190215313A1 (en) Implementing Secure Communication In A Distributed Computing System
US9794135B2 (en) Managed service for acquisition, storage and consumption of large-scale data streams
US7685227B2 (en) Message forwarding backup manager in a distributed server system
US10228737B2 (en) Affinity-aware parallel zeroing of memory for initialization of large pages in non-uniform memory access (NUMA) servers
US20160275123A1 (en) Pipeline execution of multiple map-reduce jobs
CN113364877B (en) Data processing method, device, electronic equipment and medium
CN112256433B (en) Partition migration method and device based on Kafka cluster
US20160234129A1 (en) Communication system, queue management server, and communication method
CN111385370B (en) ID allocation method, device, storage medium and ID allocation system
US20180248940A1 (en) Distributed data management
WO2021082465A1 (en) Method for ensuring data consistency and related device
CN115525417A (en) Data communication method, communication system, and computer-readable storage medium
CN111163186B (en) ID generation method, device, equipment and storage medium
CN113220464A (en) Distributed application method and device, computer equipment and storage medium
CN106708865B (en) Method and device for accessing window data in stream processing system
CN113726546A (en) Configuration method, device, system, computing equipment and storage medium
CN111400241B (en) Data reconstruction method and device
CN111736975A (en) Request control method and device, computer equipment and computer readable storage medium
CN112631994A (en) Data migration method and system
WO2023142824A1 (en) Gpu resource utilization monitoring method and apparatus, computer device, and medium
US9477471B1 (en) Maintaining lock-free, high frequency, high performance counters in software
US10678453B2 (en) Method and device for checking false sharing in data block deletion using a mapping pointer and weight bits
US10949322B2 (en) Collecting performance metrics of a device
CN113051244A (en) Data access method and device, and data acquisition method and device
CN112948106A (en) Task allocation method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40055411

Country of ref document: HK