Summary of the invention
Goal of the invention of the invention is to be distributed in certain scale master under existing business demand in the prior art to overcome
Multiple application programs on machine can not carry out the deficiency of high performance communication, and providing one kind can be in larger multiple host
On, the distributed communication system on static cluster being in communication with each other in multiple application processes using Service name and side
Method.
To achieve the goals above, the invention adopts the following technical scheme:
A kind of distributed communication system applied on static cluster is including N platform host, m application service process
On static cluster, the distributed communication system for serving the static state cluster includes angel's service processes on every host,
Very fast repository and m angel's client library;Each application service process adjusts corresponding angel's client library, angel's service
Process and each application service process are connect with very fast repository, and angel's service processes connect with each application service process respectively
It connects, N >=1, m >=2;
Application service process information table and angel's service processes information table are equipped in very fast repository;
Application service process information table is made of 4 fields, and 4 fields are respectively application service process Service name, application
Service processes number, the corresponding angel's service processes number of application service process and application service process presence;Wherein, it answers
It is the major key of application service process information table with service processes Service name;Application service process presence field is dynamic word
Section, application service process are updated according to the connection status between application service process and angel's service processes, other fields
It is static fields;
Angel's service processes information table is made of 5 fields, and 5 fields are respectively angel's service processes address information, day
Service processes are numbered, the attached application service process Base Serial Number of angel's service processes, the attached application service of angel's service processes
Process number and angel's service processes presence;Angel's service processes address information is the master of angel's service processes information table
Key, angel's service processes are dynamic field, and angel's service processes presence is according to local angel's service processes and other angels
Connection status between service processes is updated, while what is updated includes that the attached application service process of angel's service processes exists
Linear state.
What the present invention solved that multiple application programs for being distributed on certain scale host carry out that high-performance is in communication with each other asks
Topic, provide it is a kind of on larger multiple host, it is multiple to there is program to can be used during Service name is in communication with each other
Between part system.The present invention uses simply, to user friendly.
When an application service process needs are communicated with multiple application service process, if using client
End, server-side model, application service process needs to manage multiple connections, complicated for operation, and the application being in communication with each other with needs
Service processes quantity increases, and develops complexity rapid increase;If this application clothes for needing to be in communication with each other in entire cluster
Number of processes of being engaged in is especially more, will consume more system resource.
Relative to client, server-side traffic model, the present invention can be communicated according to Service name.
Existing open source message technology only supports the cluster of three hosts or more substantially;Message queue technology of increasing income is in cluster
Middle N/2+1 platform machine just not can be carried out communication when there is network failure or hostdown;Message queue technology of increasing income is in cluster
When scale is increasing, decline is presented in communication efficiency;Message queue technology of increasing income is when cluster divides, in minority
Host cannot use message queue;The problem of open source message queue is faced in accordance with open source protocol, needs in face of dynamic cluster skill
Art, implementation complexity height, low efficiency,
Relative to open source message queue technology, the present invention is adapted to one, two cluster for arriving multiple host, in cluster
When scale becomes larger, communication efficiency keeps stablizing;It can still be communicated between a small number of hosts;The present invention faces static set group rings
Border is realized simply, high-efficient.
A method of applied to the distributed communication system on static cluster, the insertion process including relation table: relationship
Table is application service process information table or angel's service processes information table;
Step 1: major key content is taken out from the row content for want inserting line;
Step 2: Hash calculation being carried out to major key, obtains cryptographic Hash;
Step 3: being found in Hash area and be transferred to step if the node is not used with the position of cryptographic Hash corresponding node
Rapid 4, if the node is used, it is transferred to step 6;
Step 4: nodal information being written in node, nodal information includes major key, line number and the offset of next node;Wherein,
Line number is to be inserted into line number in the gauge outfit of relation table, and gauge outfit includes number of lines;
Step 5: the write-in of row content being inserted into the row of line number, line number is inserted into and adds 1;
Step 6: according to next node offset information in nodal information, next node is successively found, until next
Node offset is -1, is changed to the offset of zipper domain enabled node for -1, on the position of zipper domain available offsets, write-in node letter
Breath, by zipper domain available offsets number plus 1;
Step 7: the write-in of row content being inserted into the row of line number, line number is inserted into and adds 1;
Wherein, Hash calculation includes the following steps:
Step 1: Hash being carried out to major key using common hash algorithm, obtains an integer;
Step 2: by integer to number of lines remainder, obtaining a cryptographic Hash.
Preferably, further including the process of inquiry:
Step 1: Hash calculation being carried out to inquiry major key, obtains cryptographic Hash;
Step 2: finding the position with cryptographic Hash corresponding node, the major key content and inquiry major key of comparison node in Hash area
Whether content is identical, and the row number information recorded in node is taken when identical;When not identical, the offset of next node is taken;
Step 3: according to the offset of next node, successively whether the major key of comparison node and inquiry major key are identical, until
Identical node is found, the row number information recorded in the node is taken;
Step 4: if not finding row number information, inquiry failure;
Wherein, Hash calculation includes the following steps:
Step 1: Hash being carried out to major key using common hash algorithm, obtains an integer;
Step 2: by integer to number of lines remainder, obtaining a cryptographic Hash.
Preferably, further including the synchronous triggering step of presence:
Step 1: taking present system time, present system time is subtracted to last system time, obtains the time difference;
If time difference > 1 second, being transferred to step 2;
If time difference≤1 second, sleep 100 milliseconds, circulation executes step 1;
Whether step 2: whether detecting event trigger flag is 1, or to synchronizing cycle;If so, being transferred to step 3;
Otherwise, step 2 is continued to execute;
Step 3: event trigger flag being revised as 0, executes presence synchronizing process;
Step 4: by last system time be assigned a value of obtain present system time, will be assigned a value of cycle time be currently
The system time adds periodic quantity, continues to execute step 1.
Preferably, further including presence synchronizing process:
Step 1: angel's service processes read from very fast repository the application service process for being attached to oneself in threadiness
State;
Step 2: angel's service processes compress the presence for being attached to the application service process of oneself, constitute one
A presence updates packet;
Step 3: sending the online of oneself attached application service process to angel's service processes of other All hosts
State updates packet;
Step 4: receiving presence and update the angel's service processes wrapped, decompression presence updates packet, and modification is originally
The very fast repository on ground.
Preferably, further including application service process login process:
Step 1: on host i, application service process j is logged on angel's service processes i, and application service process j is called
The login interface of angel's client library is passed to the Service name jX of oneself;I=1,2 ..., N;J=1,2 ..., m;
Step 2: angel's service processes i is connected to application service process j logging request, and it is local to inquire inquiry according to Service name j
Very fast repository;
If found inside very fast repository, there are the configurations of the service, return to the number and login of application service process j
Successful information, the logging state for modifying application service process j in very fast repository are to have logged on, and are transferred to step 3;
If do not found inside very fast repository, there are the configurations of the service, return to the information of -1 and login failure;
Step 3: the logging state of application service process j is broadcast to angel's service processes 2 by angel's service processes i
To N;
Angel's service processes 2 receive the logging state of application service process j to angel's service processes N, are transferred to step respectively
Rapid 4;
Step 4: angel's service processes 2 to angel's service processes N the logging state of application service process j are written local
Very fast repository.
Preferably, further including communication process between application service process:
Application service process j sends a message to application service process k;K=1,2 ..., m;k≠j;
Step 1: application service process j is by local very fast repository, according to the Service name of application service process k, inquiry
The number and presence of application service process k;If inquiring the online of the number of application service process and application service process
State be it is online, be transferred to step 2;Conversely, returning to failure information, sign off;
Step 2: application service process j constructs message package, sends the message package to angel's service processes i;
Step 3: angel's service processes i receives the message package, according to the message package packet header content, inquires very fast repository,
The target angel process N that forward is found, and inquires the presence of target angel's process N;
Step 4: message package is sent to angel's service processes N by angel's service processes i;
Step 5: angel's service processes N receives the message package, according to the message package packet header content, inquires very fast repository,
Find application service process k;
Step 6: message package is sent to application service process k by angel's service processes N.
Therefore, the invention has the following beneficial effects: one, two cluster for arriving multiple host is adapted to, in cluster
When scale becomes larger, communication efficiency keeps stablizing;When static cluster breaks down, even if fault coverage relates to most of master
Machine can still communicate between the hosts that are not involved of minority;The present invention faces static cluster environment, realizes simply, high-efficient.
Specific embodiment
The present invention will be further described with reference to the accompanying drawings and detailed description.
Embodiment as shown in Figure 1 is a kind of distributed communication system applied on static cluster, is including N platform host
On the static cluster of 2,20 application service process 23, the distributed communication system for serving the static state cluster includes being set to every
Angel's service processes 21 on host, very fast repository 22 and 20 angel client library 24;20 application service process difference
20 angel's client libraries are called, angel's service processes and each application service process call very fast repository, angel's service
Process is connect with each application service process respectively;
As shown in Fig. 2, being equipped with application service process information table and angel's service processes information table in very fast repository;
Application service process information table is made of 4 fields, and 4 fields are respectively application service process Service name, application
Service processes number, the corresponding angel's service processes number of application service process and application service process presence;Wherein, it answers
It is the major key of application service process information table with service processes Service name;Application service process presence field is dynamic word
Section can be updated according to the connection status between application service process and angel's service processes;
Other fields are static fields;Static fields are when a static cluster determines just it has been determined that will not
In runtime dynamic change.Application service process Service name can carry out quick search according to Service name.Application service process
Number uses continuous number serial number, corresponds to line number of the application service process in application service process information table, and will be same
Application service process serial number on one host.Only application service process presence be according to the actual situation dynamic more
New field.
Angel's service processes information table is made of 5 fields, and 5 fields are respectively angel's service processes address information, day
Service processes are numbered, the attached application service process Base Serial Number of angel's service processes, the attached application service of angel's service processes
Process number and angel's service processes presence;Angel's service processes address information is the master of angel's service processes information table
Key, can be according to address quick search.Angel's service processes number uses continuous number serial number, corresponding angel's service processes
The line number of information table.Angel's service processes address information is major key,
The attached application service process of angel's service processes be with angel's service processes on same host, use angel
Client library is connected directly between the application service process on angel's service processes.Angel's service processes are dynamic field, angel's clothes
Business process presence is updated according to the connection status between local angel's service processes and other angel's service processes
, while what is updated includes the attached application service process presence of angel's service processes.
Presence field in two tables is dynamic change, but is changed infrequently, and a table of bytes is used in table
To show presence, while indicating online using 0, other any values indicate offline, so variation field is not necessarily to lock, entire pole
Fast repository change can be used to be designed without lock.Very fast repository is realized using shared drive, and use is designed without lock, according to
These characteristics, very fast repository can provide the access speed of memory hierarchy.
As shown in figs. 3 and 5, further include the insertion process of relation table:
Step 1: major key content is taken out from the row content for want inserting line;
Step 2: Hash calculation being carried out to major key, obtains cryptographic Hash;
Step 3: being found in Hash area and be transferred to step if the node is not used with the position of cryptographic Hash corresponding node
Rapid 4, if the node is used, it is transferred to step 6;
Step 4: nodal information being written in node, nodal information includes major key, line number and the offset of next node;Wherein,
Line number is to be inserted into line number in the gauge outfit of relation table, and gauge outfit includes number of lines;
Step 5: the write-in of row content being inserted into the row of line number, line number is inserted into and adds 1;
Step 6: according to next node offset information in nodal information, next node is successively found, until next
Node offset is -1, is changed to the offset of zipper domain enabled node for -1, on the position of zipper domain available offsets, write-in node letter
Breath, by zipper domain available offsets number plus 1;
Step 7: the write-in of row content being inserted into the row of line number, line number is inserted into and adds 1;
Wherein, Hash calculation includes the following steps:
Step 1: Hash being carried out to major key using common hash algorithm, obtains an integer;
Step 2: by integer to number of lines remainder, obtaining a cryptographic Hash.
As shown in Figure 4, Figure 5, further include the process of inquiry:
Step 1: Hash calculation being carried out to inquiry major key, obtains cryptographic Hash;
Step 2: finding the position with cryptographic Hash corresponding node, the major key content and inquiry major key of comparison node in Hash area
Whether content is identical, and the row number information recorded in node is taken when identical;When not identical, the offset of next node is taken;
Step 3: according to the offset of next node, successively whether the major key of comparison node and inquiry major key are identical, until
Identical node is found, the row number information recorded in the node is taken;
Step 4: if not finding row number information, inquiry failure;
Wherein, Hash calculation includes the following steps:
Step 1: Hash being carried out to major key using common hash algorithm, obtains an integer;
Step 2: by integer to number of lines remainder, obtaining a cryptographic Hash.
As shown in fig. 6, the angel's service processes being distributed on each machine in the cluster are all connected on other All hosts
Angel's service processes, constitute the network structure of radiation shapes all reciprocity on an each host.1st angel's service processes
While connecting the 2nd angel's service processes to N angel's service processes, the 2nd angel's service processes are received to N angel service
The connection of process.
The linking number of each angel's service processes management is 2* (N-1) on reciprocity radial network;Any two masters
Machine is all directly connected to using angel's service processes;Any two are distributed in the communication between the application service process on different hosts
It is all to be forwarded communication using angel's service processes between two hosts.In the network structure of reciprocity radial network, do not have
There is any one angel's service processes node that can become performance bottleneck, also none angel's service processes can become main section
Point, and influence the communication between incoherent application service process.Due to the speed with network communication communicated between local process
Compared to being very quick, so local angel's service processes will not become the bottleneck of application service process communication, because more
First reach bottleneck is network communication speed.If reach the speed bottle-neck of network communication, even if using client, server-side
Conventional communication mode can not improve speed.
The synchronous triggering mode of presence is divided into two kinds:
It is synchronous that period triggers presence;
It is synchronous that event triggers presence.The period presence of triggering is synchronous, is the appearance to prevent abnormal conditions, and one
Kind can be from selfreparing strategy under any error situation.Regardless of occur it is any it is not expected that exception, as long as by a week
Phase, system can be restored from mistake, and returning to normally can operating status.It being executed once every a cycle, the period is configurable,
Most short cycle one second.The presence of event triggering is synchronous, is to call login interface, calling to publish and connect in application service process
Mouth, exception exit in the case of three kinds, and modification is 1 (note that not being that the direct presence that triggers synchronizes) in event trigger flag.Two
Kind triggering mode is combined together, and obtains the synchronous triggering step of following presences.
As shown in fig. 7, further including the synchronous triggering step of presence:
Step 1: taking present system time, present system time is subtracted to last system time, obtains the time difference;
If time difference > 1 second, being transferred to step 2;
If time difference≤1 second, sleep 100 milliseconds, circulation executes step 1;
Whether step 2: whether detecting event trigger flag is 1, or to synchronizing cycle;If so, being transferred to step 3;
Otherwise, step 2 is continued to execute;
Step 3: event trigger flag being revised as 0, executes presence synchronizing process;
Step 4: by last system time be assigned a value of obtain present system time, will be assigned a value of cycle time be currently
The system time adds periodic quantity, continues to execute step 1.
It is handled as can be seen that event triggered fashion is merged into period triggering mode, event triggering occurs
When, only modify event trigger flag.The advantage of doing so is that calling the events such as login interface application service process occurs
When, after most 1 seconds, the presence of application service process will be synchronized, and maintain the sensitivity of system.And it avoids
If certain application service process be abnormal or other situations caused by frequently log in, publish calling, lead to presence
Synchronization is too frequent, to impact whole system.Because trigger event frequently occurs anyway, presence synchronizing process is most
Triggering mostly per second is primary.
Further include presence synchronizing process:
Step 1: angel's service processes read from very fast repository the application service process for being attached to oneself in threadiness
State;
Step 2: angel's service processes compress the presence for being attached to the application service process of oneself, constitute one
A presence updates packet;
Step 3: sending the online of oneself attached application service process to angel's service processes of other All hosts
State updates packet;
Step 4: receiving presence and update the angel's service processes wrapped, decompression presence updates packet, and modification is originally
The very fast repository on ground.
The method of compression is as follows: because being attached to multiple applications of same angel's service processes the characteristics of static cluster
Service processes are that continuously, a character array, which can be used, indicates presence, and character array is every in sequence in number
Each of one byte corresponds to the presence of an application service process.Due to having had angel's service in very fast repository
The Base Serial Number and number of the corresponding application service process of process both can be into so do not need to transmit additional other information
Row decompression.Such as 1 attached 5 application service process of angel's service processes, a byte have 8 bits, use a word
Section can indicate the presence of 5 application service process.Using above-mentioned compression method, few byte, table can be used
Show more information.
Using the synchronous method of application service process presence of the invention, in 1000 hosts, every host
On the static cluster of upper 80 application service process, use 10 seconds for a cycle.During system stable operation, each master
Synchronizing consumed network bandwidth on machine for holding application service process presence is 1000 byte per second (calculation methods
(80/8*1000)/10), the system-computed for being 100,000,000 according to bandwidth, the resource of loss only has insufficient a ten thousandth.Even if being
For system thoroughly during upheaval, consumed maximum bandwidth also only has 10000 byte per seconds, also divides less than thousand according to 100,000,000 system-computeds
One of, moreover such case hardly occurs.So using this synchronous method, it is very small for the loss of resource, it is synchronous
Velocity-stabilization, and have self-reparing capability, can restore from mistake.
Further include application service process login process:
Step 1: on host i, application service process j is logged on angel's service processes i, and application service process j is called
The login interface of angel's client library is passed to the Service name jX of oneself;I=1,2 ..., N;J=1,2 ..., m;
Step 2: angel's service processes i is connected to application service process j logging request, and it is local to inquire inquiry according to Service name j
Very fast repository;
If found inside very fast repository, there are the configurations of the service, return to the number and login of application service process j
Successful information, the logging state for modifying application service process j in very fast repository are to have logged on, and are transferred to step 3;
If do not found inside very fast repository, there are the configurations of the service, return to the information of -1 and login failure;
Step 3: the logging state of application service process j is broadcast to angel's service processes 2 by angel's service processes i
To N;
Angel's service processes 2 receive the logging state of application service process j to angel's service processes N, are transferred to step respectively
Rapid 4;
Step 4: angel's service processes 2 to angel's service processes N the logging state of application service process j are written local
Very fast repository.
Further include communication process between application service process:
Application service process j sends a message to application service process k;K=1,2 ..., m;k≠j;
Step 1: application service process j is by local very fast repository, according to the Service name of application service process k, inquiry
The number and presence of application service process k;If inquiring the online of the number of application service process and application service process
State be it is online, be transferred to step 2;Conversely, returning to failure information, sign off;
Step 2: application service process j constructs message package, sends the message package to angel's service processes i;
Step 3: angel's service processes i receives the message package, according to the message package packet header content, inquires very fast repository,
The target angel process N that forward is found, and inquires the presence of target angel's process N;
Step 4: message package is sent to angel's service processes N by angel's service processes i;
Step 5: angel's service processes N receives the message package, according to the message package packet header content, inquires very fast repository,
Find application service process k;
Step 6: message package is sent to application service process k by angel's service processes N.
As shown in figure 8, causing to divide into group, 2 and 3 two parts being split into, in such case because of network failure
Under, this communication middleware still can be used.
When there is division as shown in Figure 8, if using open source message queue technology, below half number of host
Be 2, it is impossible to communicated, above number of host be 3, can communicate.If there is a host event again in top half
Barrier, top half can not be communicated.
If upper left application service process is X, the application service process in upper right side is Y, the application service of lower left into
Journey is F, and the application service process of lower right is G;
This problem is not present in the present invention, can communicate, answers between application service process X and application service process Y
It also can communicate with service processes F and application service process G.Application service process X not can be carried out with application service process F
The reason of communication is that do not have connectivity physically because of network or hardware fault, and unrelated with communication middleware, communication is intermediate
Part provides the reliability of maximum possible.This example is to enumerate the reliability of this communication middleware under one of fault condition,
Other similar situation will not enumerate with failure.
As shown in figure 9, angel's client library provides service login, publishes, message transmission, message sink is adjusted back four and is connect
Mouthful, and only there are four interfaces, provide simple usage mode to application service process.
It should be understood that this embodiment is only used to illustrate the invention but not to limit the scope of the invention.In addition, it should also be understood that,
After having read the content of the invention lectured, those skilled in the art can make various modifications or changes to the present invention, these etc.
Valence form is also fallen within the scope of the appended claims of the present application.