Cluster remote procedure calling (PRC) method and system
Technical field
The invention belongs to trunking communicating technology field more particularly to a kind of cluster remote procedure calling (PRC) method and systems.
Background technology
With the fast development of the Internet, applications, background server cluster also becomes increasing, often a business tune
(collaboration between multiple servers is commonly referred to as RPC) is completed with needing to be cooperateed with by multiple servers in background server cluster, because
Release of service and inquiry between this server also become extremely important.RPC(Remote Procedure Call
Protocol) --- remote procedure call protocol, it is that one kind asks service by network from remote computer program, without
It should be understood that the agreement of underlying network technology.RPC agreements assume the presence of some transport protocols, such as TCP or UDP, for the journey that communicates
Information data is carried between sequence.In OSI network communication models, RPC spans transport layer and application layer.RPC causes development kit
The application program including network distribution type multiprogram is included to be more prone to.RPC uses Client/Server pattern.Requestor is just
It is a client computer, and service providing program is exactly a server.First, client calls process, which sends one, process ginseng
Then several recalls informations waits response message to service processes.In server end, process keeps sleep state to believe until calling
Until the arrival of breath.When a recalls information reaches, server obtains process parameter, and result of calculation sends reply message, then
Next recalls information is waited, finally, client call process receives reply message, obtains proceeding results, then calls and performs
Continue.
Current main cluster RPC communication technology has two major classes, and one kind is static configuration mode, i.e. each in cluster
The service scenario that Servers-all provides in cluster is configured in server, this mode realizes fairly simple, but presence service
Device failure or increase after new demand servicing device can not real-time informing to other servers, therefore be relatively suitble to service scale is fixed to answer
With can not be adapted to for the fast-changing situation of cluster scale.
In addition a kind of is dynamic registration mode, i.e., 1 server is chosen in cluster as registrar, all in cluster
Server registers oneself service type of offer and RPC call address information to this registrar, when there is server needs
, it is necessary to inquire about the RPC call address information of the offer service to registrar when accessing some service, RPC tune is then completed
With, this mode there are the problem of be that there are Single Point of Faliures, i.e., after registrar failure, entire cluster RPC for registrar
It will be unable to use.
The content of the invention
The present invention goal of the invention be:In order to solve in above-mentioned cluster in the prior art, there are Single Point of Faliures for registrar
And the problem of causing entire cluster RPC that can not use, the present invention propose a kind of cluster remote procedure calling (PRC) method and system.
The technical scheme is that:A kind of cluster remote procedure calling (PRC) method, comprises the following steps:
A, start all registration services in cluster, registration service is added in into registration service multicast group, and monitoring group is reported
Text;
B, the registration request message from server-side is sent to registration service multicast group according to predetermined period, registration service is received
Message information is preserved after to registration request message;
C, the service name query accessed according to client needs corresponds to the registration service in cluster server, utilizes registration
The message information preserved in service inquires about call address information corresponding with service name and returns to client;
D, client according to the corresponding server-side of call address message reference returned in step C, complete to access by server-side
Handling result is returned into client after request.
Further, the cluster includes N number of cluster server, N >=1.
Further, the registration service, client and server-side are run simultaneously in the cluster server.
Further, it is stored with latest services information bank in the cluster server.
Further, the registration request message includes service name and call address information.
Further, the step B is further comprising the steps of:
Setting and judges that registration service is received after registration request message under distance more than the detection duration of predetermined period duration
Whether the duration for once receiving registration request message is more than detection duration;
Distance receives the duration of registration request message more than detection next time after if registration service receives registration request message
Duration then deletes the correspondence message information preserved in registration service;
If registration service receives distance after registration request message the duration of registration request message is received next time be less than or wait
In detection duration, then corresponding message information is stored in registration service.
In order to solve problem above, the invention also provides a kind of cluster RPC system, including registration module,
Access modules and service module;
The registration service is added in registration service group by the registration module for starting all registration services in cluster
It broadcasts group and monitors multicast message;The registration module preserves message information after receiving registration request message;When access modules are inquired about
During registration service, the registration module is inquired about call address information corresponding with service name according to the message information of preservation and is returned
Back to access modules;
The access modules are arranged on client, for the service name query registration service according to client, and according to note
The call address message reference corresponding server that volume module returns;
The service module is arranged on server-side, for sending registration request report to registration service multicast group according to predetermined period
Text;When access modules access server, service module completes access request and handling result is returned to access modules.
Further, each cluster server in the cluster includes registration module, access modules and service module.
Further, the registration request message includes service name and call address information.
Further, detection module is further included,
The detection module for judge registration module receive registration request message after distance receive registration request next time
Whether the duration of message is more than default detection duration, a length of multiple predetermined period durations during the detection, if registration module receives
The duration that distance receives registration request message next time after registration request message is then deleted in registration module and protected more than detection duration
The correspondence message information deposited, if registration module receives the duration that distance after registration request message receives registration request message next time
Less than or equal to detection duration, then corresponding message information is stored in registration module.
The beneficial effects of the invention are as follows:The present invention is by being multiple cluster servers by assemblage classification, and in each cluster
The registration service, client and server-side are run in server simultaneously, realizes cluster remote procedure call;The present invention by
Newest RPC service information bank is stored in each cluster server, realizes looking into for when any number of node failure in cluster RPC
It askes unaffected with access;The present invention to registration service multicast group according to predetermined period in server-side also by sending registration request
Message realizes that the new cluster server for adding in cluster can learn into cluster all RPC clothes within a certain period of time without configuration
Business information;The present invention also by setting detection duration come the expired RPC log-on messages of periodic cleaning, makes RPC information keep newest
State avoids occurring continuing RPC access faults when cluster server breaks down or removes.
Description of the drawings
Fig. 1 is the cluster remote procedure calling (PRC) method flow diagram of the present invention.
Fig. 2 is cluster schematic diagram in cluster remote procedure calling (PRC) method of the invention.
Fig. 3 is the cluster RPC system schematic diagram of the present invention.
Specific embodiment
In order to make the purpose , technical scheme and advantage of the present invention be clearer, with reference to the accompanying drawings and embodiments, it is right
The present invention is further elaborated.
As shown in Figure 1, for the cluster remote procedure calling (PRC) method flow diagram of the present invention, following steps are specifically included:
A, start all registration services in cluster, registration service is added in into registration service multicast group, and monitoring group is reported
Text.
As shown in Fig. 2, it is cluster schematic diagram in the cluster remote procedure calling (PRC) method of the present invention.The cluster of the present invention includes
N number of cluster server, N >=1 here;Newest RPC service information bank is stored in each cluster server, realizes and works as
The inquiry of RPC is unaffected with accessing during any number of node failure in cluster;Note is run in each cluster server simultaneously
Volume service, client and server-side.The registration service of the present invention is the manager of cluster RPC service information, is serviced for receiving
The registration request message at end simultaneously preserves message information, while receives the inquiry request of client, believes when inquiring corresponding with service end
Information is returned into client after breath.The present invention starts the registration service in each cluster server in cluster, all registration clothes
After business starts, the multicast network for including all registration services is set up, registration service is added in into registration service multicast group, and monitoring group
Report text.
A multicast address is configured in the embodiment of the present invention first and multicast port is used as registration service, such as
224.0.1.1:8000.Then the registration service in each cluster server in cluster is started, all registration services will after starting
Registration service adds in registration service multicast group, and monitors multicast message.
B, the registration request message from server-side is sent to registration service multicast group according to predetermined period, registration service is received
Message information is preserved after to registration request message.
The present invention sets a cycle in server-side, and registration request is sent to registration service multicast group according to the cycle of setting
Message, all RPC can be learnt into cluster within a certain period of time without configuration by realizing the new cluster server for adding in cluster
Information on services.Here registration request message includes service name and call address information.Registration request is received in registration service
After message, registration service preserves registration request message information.
Sending cycle is set in the embodiment of the present invention as 10 seconds, i.e., server-side sent registration every 10 seconds to corresponding multicast group
Service message.Registration service message is specially retrieval service, and including service name and call address information, service name is
SearchServer, service access address are http://192.168.1.1/SearchServer.do.All notes in cluster
After volume service receives registration request message, relevant information is saved in memory or in local data base.
The step B of the present invention is further comprising the steps of:
Setting and judges that registration service is received after registration request message under distance more than the detection duration of predetermined period duration
Whether the duration for once receiving registration request message is more than detection duration;
Distance receives the duration of registration request message more than detection next time after if registration service receives registration request message
Duration then deletes the correspondence message information preserved in registration service;
If registration service receives distance after registration request message the duration of registration request message is received next time be less than or wait
In detection duration, then corresponding message information is stored in registration service.
Since cluster server is likely to occur failure, registration service needs periodic detection to update.The present invention is by setting
Regular inspection surveys duration and judges that registration service receives distance after registration request message and receives the duration of registration request message next time
It is no to carry out the expired RPC log-on messages of periodic cleaning beyond duration is detected, RPC information is made to keep last state, avoids taking when cluster
It is engaged in occurring continuing RPC access faults when device failure or removal.
3 times, i.e., 30 seconds of a length of predetermined period when detection is set in the embodiment of the present invention.Work as retrieval service
When cluster server where SearchServer breaks down, registration service did not receive retrieval service in 30 seconds
The log-on message before retrieval service SearchServer is deleted in the registration service message of SearchServer, then registration service.
If query and search services SearchServer to next client again, the calling of retrieval service SearchServer will not be inquired
Address information.
C, the service name query accessed according to client needs corresponds to the registration service in cluster server, utilizes registration
The message information preserved in service inquires about call address information corresponding with service name and returns to client.
When some client needs to access registration service in cluster, the registration clothes into cluster server where client
Inquiry request is initiated in business, and inquiry request here includes service name;Registration service according to the message information of preservation inquiry with
The corresponding call address information of service name, and the call address information that inquiry is obtained returns to client.
Some client needs to access retrieval service in the cluster of the embodiment of the present invention, then is taken to the cluster where client
Inquiry request is initiated in the registration service being engaged in device, and inquiry request here includes service name SearchServer;Registration clothes
It is http that business inquires about call address information corresponding with SearchServer according to the message information of preservation://192.168.1.1/
SearchServer.do, and return to client.
D, client according to the corresponding server-side of call address message reference returned in step C, complete to access by server-side
Handling result is returned into client after request.
Client is initiated to access and asked according to the call address information returned in step C to corresponding server-side in the present invention
It asks, handling result is returned into client after server-side completion access request, completes cluster remote procedure call.
As shown in figure 3, the cluster RPC system schematic diagram for the present invention.The invention also provides a kind of clusters
RPC system, including registration module, access modules and service module;
The registration service is added in registration service group by the registration module for starting all registration services in cluster
It broadcasts group and monitors multicast message;The registration module preserves message information after receiving registration request message;When access modules are inquired about
During registration service, the registration module is inquired about call address information corresponding with service name according to the message information of preservation and is returned
Back to access modules;
The access modules are arranged on client, for the service name query registration service according to client, and according to note
The call address message reference corresponding server that volume module returns;
The service module is arranged on server-side, for sending registration request report to registration service multicast group according to predetermined period
Text;When access modules access server, service module completes access request and handling result is returned to access modules.
Cluster includes multiple cluster servers in the cluster RPC system of the present invention, is wrapped in each server
Include registration module, access modules and access modules.
The cluster RPC system of the present invention further includes detection module, and detection module is used to judge that registration module is received
Whether distance receives the duration of registration request message more than default detection duration, inspection here next time after to registration request message
A length of multiple predetermined period durations during survey, if distance receives registration request report after registration module receives registration request message next time
The duration of text is more than detection duration, then deletes the correspondence message information preserved in registration module, if registration service receives registration and asks
The duration that distance after message receives registration request message next time is asked to be less than or equal to detection duration, then by corresponding message information
It is stored in registration service.
The cluster RPC system of the present invention starts each cluster server of cluster first with registration module
Registration service is added in registration service multicast group and monitors multicast message by interior registration service;Service module is recycled according to pre-
If the cycle sends registration request message to registration service multicast group, registration request message here includes service name and calls ground
Location information;Using detection module judge registration module receive registration request message after distance receive registration request message next time
Whether duration is more than default detection duration, if distance receives registration request report after registration module receives registration request message next time
The duration of text is more than detection duration, then deletes the correspondence message information preserved in registration module, if registration module receives registration and asks
The duration that distance after message receives registration request message next time is asked to be less than or equal to detection duration, then by corresponding message information
It is stored in registration module;Registration module preserves message information into memory or local data base after receiving registration request message;
When the client in cluster in some cluster server needs to access registration service, using access modules according to the clothes of client
Business name query registration service, registration module inquire about call address information corresponding with service name according to the message information of preservation
And return to access modules;The call address message reference corresponding server that access modules are returned further according to registration module, service
Module completes access request and handling result is returned to access modules, completes cluster remote procedure call.
Those of ordinary skill in the art will understand that the embodiments described herein, which is to help reader, understands this hair
Bright principle, it should be understood that protection scope of the present invention is not limited to such special statement and embodiment.This field
Those of ordinary skill these disclosed technical inspirations can make according to the present invention and various not depart from the other each of essence of the invention
The specific deformation of kind and combination, these deform and combine still within the scope of the present invention.