Background technology
Along with the fast development of internet, applications, background server cluster also becomes increasing, often calling service needs work in coordination with (between multiple server collaborative be commonly referred to as RPC) by server multiple in background server cluster, the release of service therefore between server and inquire about and also become extremely important.RPC (Remote Procedure Call Protocol)---remote procedure call protocol, it be a kind of by network from request service remote computer program, and do not need the agreement understanding underlying network technology.RPC agreement supposes the existence of some host-host protocol, as TCP or UDP, is carry information data between signal procedure.In OSI network communication models, RPC spans transport layer and application layer.RPC makes kit includes network distributed multi-program be more prone in interior application program.RPC adopts Client/Server pattern.Requestor is exactly a client computer, and service providing program is exactly a server.First, client calls process sends one has the recalls information of process parameter to service processes, then wait acknowledge information.At server end, process keeps sleep state until the arrival of recalls information.When a recalls information arrives, server obtains process parameter, result of calculation, sends reply message, then waits for next recalls information, and finally, client call process receives reply message, obtains proceeding results, then calls execution and proceed.
The cluster RPC communication technology main at present has two large classes, one class is static configuration mode, namely the service scenario that in allocation cluster, Servers-all provides in each station server of cluster, this mode realizes fairly simple, but presence server fault or after increasing new server cannot real-time informing to other servers, therefore be relatively applicable to the fixing application of service scale, cannot adapt to for the fast-changing situation of cluster scale.
An other class is dynamic registration mode, namely choosing 1 server in cluster is registrar, servers all in cluster registers the COS and RPC call address information that oneself provide to this registrar, when needing when there being server to access certain service, need the RPC call address information that this service is provided to registrar inquiry, then complete RPC to call, this mode Problems existing is that registrar exists Single Point of Faliure, namely, after registrar fault, whole cluster RPC cannot use.
Summary of the invention
Goal of the invention of the present invention is: there is Single Point of Faliure to solve in above-mentioned prior art registrar in cluster and cause the problem that whole cluster RPC cannot use, the present invention proposes a kind of cluster remote procedure calling (PRC) method and system.
Technical scheme of the present invention is: a kind of cluster remote procedure calling (PRC) method, comprises the following steps:
A, all registration services started in cluster, add registration service multicast group, and monitor multicast message by registration service;
B, send registration request message from service end according to predetermined period to registration service multicast group, registration service preserves message information after receiving registration request message;
C, the registration service needed according to client in the service name query correspondence cluster server of access, utilize the message information preserved in registration service inquire about the call address information corresponding with service name and return to client;
The service end that D, client are corresponding according to the call address message reference returned in step C, result is returned to client after completing access request by service end.
Further, described cluster comprises N number of cluster server, N >=1.
Further, run described registration service, client and service end in described cluster server simultaneously.
Further, latest services information bank is stored in described cluster server.
Further, described registration request message comprises service name and call address information.
Further, described step B is further comprising the steps of:
Setting is greater than the detection duration of predetermined period duration, and judge registration service receive registration request message after the distance duration that next time receives registration request message whether be greater than detection duration;
If the duration that after registration service receives registration request message, distance receives registration request message is greater than detection duration next time, then delete the corresponding message information preserved in registration service;
If the duration that after registration service receives registration request message, distance receives registration request message is less than or equal to detection duration next time, then the message information of correspondence is kept in registration service.
In order to overcome the above problems, the invention allows for a kind of cluster RPC system, comprising Registering modules, access modules and service module;
Described registration service for starting all registration services in cluster, and is added registration service multicast group and monitors multicast message by described Registering modules; Described Registering modules preserves message information after receiving registration request message; When access modules inquiry registration service, described Registering modules is inquired about the call address information corresponding with service name according to the message information preserved and is returned to access modules;
Described access modules is located at client, for the service name query registration service according to client, and according to the call address message reference corresponding server that Registering modules returns;
Described service module is located at service end, for sending registration request message according to predetermined period to registration service multicast group; When access modules access services device, service module completes access request and result is returned to access modules.
Further, each cluster server in described cluster comprises Registering modules, access modules and service module.
Further, described registration request message comprises service name and call address information.
Further, also comprise detection module,
Whether described detection module is greater than to preset for the duration that distance after judging Registering modules and receiving registration request message receives registration request message is next time detected duration, described detection duration is multiple predetermined period durations, if the duration that after Registering modules receives registration request message, distance receives registration request message is greater than detection duration next time, then delete the corresponding message information preserved in Registering modules, if the duration that after registration service receives registration request message, distance receives registration request message is less than or equal to detection duration next time, then the message information of correspondence is kept in registration service.
The invention has the beneficial effects as follows: the present invention by being multiple cluster server by assemblage classification, and runs described registration service, client and service end in each cluster server simultaneously, realizes cluster remote procedure call; The present invention by storing up-to-date RPC service information repository in each cluster server, and the inquiry realizing the RPC when the node failure of any amount in cluster is unaffected with access; The present invention is also by sending registration request message according to predetermined period to registration service multicast group in service end, and the cluster server realizing newly adding cluster can learn all RPC information on services in cluster within a certain period of time without the need to configuration; The present invention also detects duration by setting and carrys out the expired RPC log-on message of periodic cleaning, makes RPC information keep last state, avoids occurring when cluster server breaks down or remove continuing RPC access fault.
Embodiment
In order to make object of the present invention, technical scheme and advantage clearly understand, below in conjunction with drawings and Examples, the present invention is further elaborated.
As shown in Figure 1, be cluster remote procedure calling (PRC) method schematic flow sheet of the present invention, specifically comprise the following steps:
A, all registration services started in cluster, add registration service multicast group, and monitor multicast message by registration service.
As shown in Figure 2, be cluster schematic diagram in cluster remote procedure calling (PRC) method of the present invention.Cluster of the present invention comprises N number of cluster server, N >=1 here; Store up-to-date RPC service information repository in each cluster server, the inquiry achieving RPC during the node failure when any amount in cluster is unaffected with access; Run registration service, client and service end in each cluster server simultaneously.Registration service of the present invention is the manager of cluster RPC information on services, for receiving the registration request message of service end and preserving message information, receives the inquiry request of client simultaneously, after inquiring corresponding with service client information, information is returned to client.The present invention starts the registration service in cluster in each cluster server, after all registration services start, sets up the multicast network comprising all registration services, registration service is added registration service multicast group, and monitor multicast message.
First a multicast address is configured and multicast port uses as registration service, such as 224.0.1.1:8000 in the embodiment of the present invention.Then start the registration service in cluster in each cluster server, registration service is added registration service multicast group after starting by all registration services, and monitors multicast message.
B, send registration request message from service end according to predetermined period to registration service multicast group, registration service preserves message information after receiving registration request message.
The present invention sets one-period in service end, sends registration request message according to the cycle of setting to registration service multicast group, achieves the cluster server newly adding cluster and can learn all RPC information on services in cluster within a certain period of time without the need to configuration.Here registration request message comprises service name and call address information.After registration service receives registration request message, registration request message information is preserved in registration service.
Setting the transmission cycle in the embodiment of the present invention is 10 seconds, and namely service end sent registration service message every 10 seconds to corresponding multicast group.Registration service message is specially retrieval service, comprises service name and call address information, and service name is SearchServer, and service access address is http: // 192.168.1.1/SearchServer.do.After all registration services in cluster receive registration request message, relevant information is saved in internal memory or in local data base.
Step B of the present invention is further comprising the steps of:
Setting is greater than the detection duration of predetermined period duration, and judge registration service receive registration request message after the distance duration that next time receives registration request message whether be greater than detection duration;
If the duration that after registration service receives registration request message, distance receives registration request message is greater than detection duration next time, then delete the corresponding message information preserved in registration service;
If the duration that after registration service receives registration request message, distance receives registration request message is less than or equal to detection duration next time, then the message information of correspondence is kept in registration service.
Because cluster server may break down, therefore registration service needs periodic detection to upgrade.The present invention detect duration by setting and judge registration service receive registration request message after the distance duration that next time receives registration request message whether exceed detection duration, carry out the RPC log-on message that periodic cleaning is expired, make RPC information keep last state, avoid occurring when cluster server breaks down or remove continuing RPC access fault.
In the embodiment of the present invention, setting detects 3 times that duration is predetermined period, namely 30 seconds.When the cluster server at retrieval service SearchServer place breaks down, registration service did not receive the registration service message of retrieval service SearchServer in 30 seconds, then the log-on message before retrieval service SearchServer is deleted in registration service.If next client is query and search service SearchServer again, then can not inquire the call address information of retrieval service SearchServer.
C, the registration service needed according to client in the service name query correspondence cluster server of access, utilize the message information preserved in registration service inquire about the call address information corresponding with service name and return to client.
When certain client in cluster needs access registration service, initiate inquiry request to the registration service in the cluster server of client place, inquiry request here comprises service name; The call address information that registration service is corresponding with service name according to the message information inquiry of preserving, and return to client by inquiring about the call address information obtained.
In the cluster of the embodiment of the present invention, certain client needs to access retrieval service, then initiate inquiry request to the registration service in the cluster server at client place, inquiry request here comprises service name SearchServer; Registration service is http: // 192.168.1.1/SearchServer.do according to the message information inquiry call address information corresponding with SearchServer of preserving, and returns to client.
The service end that D, client are corresponding according to the call address message reference returned in step C, result is returned to client after completing access request by service end.
In the present invention, client initiates access request according to the call address information returned in step C to the service end of correspondence, and result is returned to client after completing access request by service end, completes cluster remote procedure call.
As shown in Figure 3, be cluster RPC system schematic diagram of the present invention.The invention allows for a kind of cluster RPC system, comprise Registering modules, access modules and service module;
Described registration service for starting all registration services in cluster, and is added registration service multicast group and monitors multicast message by described Registering modules; Described Registering modules preserves message information after receiving registration request message; When access modules inquiry registration service, described Registering modules is inquired about the call address information corresponding with service name according to the message information preserved and is returned to access modules;
Described access modules is located at client, for the service name query registration service according to client, and according to the call address message reference corresponding server that Registering modules returns;
Described service module is located at service end, for sending registration request message according to predetermined period to registration service multicast group; When access modules access services device, service module completes access request and result is returned to access modules.
In cluster RPC system of the present invention, cluster comprises multiple cluster server, and each server comprises Registering modules, access modules and access modules.
Cluster RPC system of the present invention also comprises detection module, whether detection module is greater than to preset for the duration that distance after judging Registering modules and receiving registration request message receives registration request message is next time detected duration, here detection duration is multiple predetermined period durations, if the duration that after Registering modules receives registration request message, distance receives registration request message is greater than detection duration next time, then delete the corresponding message information preserved in Registering modules, if the duration that after registration service receives registration request message, distance receives registration request message is less than or equal to detection duration next time, then the message information of correspondence is kept in registration service.
First cluster RPC system of the present invention utilizes the registration service in each cluster server of Registering modules startup cluster, registration service is added registration service multicast group and monitors multicast message; Recycling service module sends registration request message according to predetermined period to registration service multicast group, and registration request message here comprises service name and call address information; Utilize detection module judge Registering modules receive registration request message after the distance duration that next time receives registration request message whether be greater than to preset and detect duration, if the duration that after Registering modules receives registration request message, distance receives registration request message is greater than detection duration next time, then delete the corresponding message information preserved in Registering modules, if the duration that after registration service receives registration request message, distance receives registration request message is less than or equal to detection duration next time, then the message information of correspondence is kept in registration service; Registering modules preserves message information in internal memory or local data base after receiving registration request message; When the client in certain cluster server in cluster needs access registration service, utilize access modules according to the service name query registration service of client, Registering modules is inquired about the call address information corresponding with service name according to the message information preserved and is returned to access modules; Access modules is again according to the call address message reference corresponding server that Registering modules returns, and service module completes access request and result is returned to access modules, completes cluster remote procedure call.
Those of ordinary skill in the art will appreciate that, embodiment described here is to help reader understanding's principle of the present invention, should be understood to that protection scope of the present invention is not limited to so special statement and embodiment.Those of ordinary skill in the art can make various other various concrete distortion and combination of not departing from essence of the present invention according to these technology enlightenment disclosed by the invention, and these distortion and combination are still in protection scope of the present invention.