CN111580987A - Remote procedure calling method and device, storage medium and terminal equipment - Google Patents
Remote procedure calling method and device, storage medium and terminal equipment Download PDFInfo
- Publication number
- CN111580987A CN111580987A CN202010316388.1A CN202010316388A CN111580987A CN 111580987 A CN111580987 A CN 111580987A CN 202010316388 A CN202010316388 A CN 202010316388A CN 111580987 A CN111580987 A CN 111580987A
- Authority
- CN
- China
- Prior art keywords
- target
- interface
- stub
- communication channel
- client
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 162
- 238000004891 communication Methods 0.000 claims abstract description 165
- 238000004590 computer program Methods 0.000 claims description 20
- 230000008569 process Effects 0.000 abstract description 19
- 238000010586 diagram Methods 0.000 description 8
- 230000008859 change Effects 0.000 description 4
- 230000006870 function Effects 0.000 description 4
- 230000004044 response Effects 0.000 description 4
- 230000000903 blocking effect Effects 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 238000007792 addition Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 238000012545 processing Methods 0.000 description 2
- 241000412611 Consul Species 0.000 description 1
- 230000003190 augmentative effect Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000012217 deletion Methods 0.000 description 1
- 230000037430 deletion Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 230000003993 interaction Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/547—Remote procedure calls [RPC]; Web services
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/50—Allocation of resources, e.g. of the central processing unit [CPU]
- G06F9/5005—Allocation of resources, e.g. of the central processing unit [CPU] to service a request
- G06F9/5011—Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resources being hardware resources other than CPUs, Servers and Terminals
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/544—Buffers; Shared memory; Pipes
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/541—Client-server
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F2209/00—Indexing scheme relating to G06F9/00
- G06F2209/54—Indexing scheme relating to G06F9/54
- G06F2209/549—Remote execution
Landscapes
- Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computer And Data Communications (AREA)
Abstract
The application is applicable to the technical field of communication, and particularly relates to a remote procedure call method, a remote procedure call device, a computer-readable storage medium and terminal equipment. The method comprises the following steps: acquiring a remote procedure call request, wherein the remote procedure call request comprises interface information of a target interface requested to be called by a client; determining a candidate communication channel corresponding to the target interface according to the interface information, wherein the candidate communication channel is a communication channel stored locally at the client, and the candidate communication channel is a communication channel pre-established by the client according to first registration information of the target interface in the registration center; and selecting a target communication channel from the candidate communication channels by using a preset load balancing strategy, and calling a target interface by using the target communication channel so as to avoid the establishment of the communication channel in the remote procedure calling process by a mode of establishing and caching the communication channel in advance, reduce the time consumed by the establishment of the communication channel in the remote procedure calling, and improve the performance of the remote procedure calling.
Description
Technical Field
The present application belongs to the field of communications technologies, and in particular, to a remote procedure call method, an apparatus, a computer-readable storage medium, and a terminal device.
Background
GRPC provides a Remote Procedure Call (RPC) framework for google. In the GRPC framework, an application on a client can directly invoke an application on a remote server as if invoking a local object. In a conventional remote procedure call, a client needs to establish a communication channel with a remote server first in each call process, and then calls an application on the remote server through the currently established communication channel, that is, in the conventional remote procedure call, the communication channel between the client and the remote server is established in real time in each call process. Because the establishment of the communication channel is time-consuming, the performance of the remote procedure call is poor in the traditional way of establishing the communication channel in real time to perform the remote procedure call.
Disclosure of Invention
The embodiment of the application provides a remote procedure call method, a remote procedure call device, a computer readable storage medium and a terminal device, which can solve the problem of poor performance of the existing remote procedure call.
In a first aspect, an embodiment of the present application provides a remote procedure call method, including:
acquiring a remote procedure call request, wherein the remote procedure call request comprises interface information of a target interface requested to be called by a client;
determining a candidate communication channel corresponding to the target interface according to the interface information, wherein the candidate communication channel is a communication channel stored locally at the client, and the candidate communication channel is a communication channel pre-established by the client according to first registration information of the target interface in a registration center;
and selecting a target communication channel from the candidate communication channels by using a preset load balancing strategy, and calling the target interface by using the target communication channel.
In a possible implementation manner of the first aspect, the determining, according to the interface information, a candidate communication channel corresponding to the target interface may include:
judging whether a target stub is stored in the local part of the client according to the interface information, wherein the target stub is a stub created when the client calls the target interface before;
if the target stub is locally stored in the client, using the target stub to call the target interface;
and if the target stub is not locally stored in the client, determining a candidate communication channel corresponding to the target interface according to the interface information.
Optionally, the invoking the target interface by using the target stub may include:
determining a stub state of the target stub;
if the stub state is a first preset state, determining a candidate communication channel corresponding to the target interface according to the interface information;
and if the stub state is a second preset state, using the target stub to call the target interface.
For example, the determining the stub state of the target stub may include:
detecting a registration state of a target interface corresponding to the target stub in the registration center, wherein the registration state comprises a valid state and an invalid state;
when the registration state of the target interface corresponding to the target stub in the registration center is an effective state, determining that the stub state of the target stub is the second preset state;
and when the registration state of the target interface corresponding to the target stub in the registration center is an invalid state, determining that the stub state of the target stub is the first preset state.
In a possible implementation manner of the first aspect, the invoking the target interface using the target communication channel may include:
establishing a target stub corresponding to the target communication channel, and storing the target stub corresponding to the target communication channel in the local part of the client;
and calling the target interface by using the target stub corresponding to the target communication channel.
Optionally, the remote procedure call method may further include:
acquiring second registration information of each candidate interface in the registration center, wherein the candidate interfaces comprise the target interface;
and adjusting the candidate communication channel corresponding to each candidate interface in the local client according to the second registration information of each candidate interface.
In a second aspect, an embodiment of the present application provides a remote procedure call apparatus, which may include:
the system comprises a calling request acquisition module, a remote procedure calling module and a calling module, wherein the calling request acquisition module is used for acquiring a remote procedure calling request which comprises interface information of a target interface requested to be called by a client;
a candidate channel determining module, configured to determine, according to the interface information, a candidate communication channel corresponding to the target interface, where the candidate communication channel is a communication channel stored locally at the client, and the candidate communication channel is a communication channel pre-established by the client according to first registration information of the target interface in a registration center;
and the remote procedure calling module is used for selecting a target communication channel from the candidate communication channels by using a preset load balancing strategy and calling the target interface by using the target communication channel.
In a possible implementation manner of the second aspect, the candidate channel determining module may include:
a target stub determining unit, configured to determine, according to the interface information, whether a target stub is stored locally in the client, where the target stub is a stub created when the client calls the target interface before;
a target stub calling unit, configured to call the target interface using the target stub if the target stub is locally stored in the client;
and the candidate channel determining unit is used for determining a candidate communication channel corresponding to the target interface according to the interface information if the target stub is not locally stored in the client.
Optionally, the target stub invoking unit may include:
the stub state determination sub-unit is used for determining the stub state of the target stub;
a candidate channel determination subunit, configured to determine, if the stub state is a first preset state, a candidate communication channel corresponding to the target interface according to the interface information;
and the target stub calling sub-unit is used for calling the target interface by using the target stub if the stub state is a second preset state.
For example, the stub state determination subunit is specifically configured to detect a registration state of a target interface corresponding to the target stub in the registry, where the registration state includes a valid state and an invalid state; when the registration state of the target interface corresponding to the target stub in the registration center is an effective state, determining that the stub state of the target stub is the second preset state; and when the registration state of the target interface corresponding to the target stub in the registration center is an invalid state, determining that the stub state of the target stub is the first preset state.
In a possible implementation manner of the second aspect, the remote procedure call module may include:
the target stub establishing unit is used for establishing a target stub corresponding to the target communication channel and storing the target stub corresponding to the target communication channel in the local part of the client;
and the remote procedure calling unit is used for calling the target interface by using the target stub corresponding to the target communication channel.
Optionally, the remote procedure call apparatus may further include:
a registration information obtaining module, configured to obtain second registration information of each candidate interface in the registration center, where the candidate interface includes the target interface;
and the candidate channel adjusting module is used for adjusting the candidate communication channel corresponding to each candidate interface in the local client according to the second registration information of each candidate interface.
In a third aspect, an embodiment of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the remote procedure call method according to any one of the first aspect when executing the computer program.
In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored, and the computer program, when executed by a processor, implements the remote procedure call method according to any one of the first aspect.
In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a terminal device, causes the terminal device to execute the remote procedure call method according to any one of the above first aspects.
It is understood that the beneficial effects of the second aspect to the fifth aspect can be referred to the related description of the first aspect, and are not described herein again.
Compared with the prior art, the embodiment of the application has the advantages that:
in the embodiment of the application, candidate communication channels corresponding to the client and each interface can be pre-established according to the registration information of each interface registered in the registration center by the server, and the established candidate communication channels can be stored locally at the client. Therefore, when the remote procedure call is performed, the candidate communication channel corresponding to the target interface can be determined from the local client according to the interface information of the target interface called by the client request included in the remote procedure call request, and the target communication channel can be selected from the candidate communication channels by using a preset load balancing strategy so as to call the target interface by using the target communication channel. The method avoids the establishment of the communication channel in the remote procedure call process by establishing and caching the communication channel in advance, can greatly reduce the time consumed by the establishment of the communication channel in the remote procedure call, and improves the performance of the remote procedure call. In addition, the target communication channel is selected through a load balancing strategy, so that the performance of remote procedure call can be improved, and the user experience is improved.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without creative efforts.
FIG. 1 is a system diagram of a calling system to which a remote procedure call method according to an embodiment of the present application is applied;
FIG. 2 is a flowchart illustrating a remote procedure call method according to an embodiment of the present application;
fig. 3 is a system diagram of a calling system to which the remote procedure calling method provided in the second embodiment of the present application is applied;
FIG. 4 is a flowchart illustrating a remote procedure call method according to a second embodiment of the present application;
FIG. 5 is a schematic structural diagram of a remote procedure call device according to a third embodiment of the present application;
fig. 6 is a schematic structural diagram of a terminal device according to an embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
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 should also be 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.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.
The remote procedure call method provided by the embodiment of the application can be applied to mobile phones, tablet computers, wearable devices, vehicle-mounted devices, Augmented Reality (AR)/Virtual Reality (VR) devices, notebook computers, ultra-mobile personal computers (UMPCs), netbooks, Personal Digital Assistants (PDAs) and other terminal devices, and the embodiment of the application does not limit the specific types of the terminal devices at all.
[ EXAMPLES one ]
Fig. 1 is a system diagram illustrating a calling system to which a remote procedure calling method according to an embodiment of the present application is applied. As shown in fig. 1, the calling system provided in this embodiment may include a registry, a client and a server, where the client and the server are connected to the registry respectively. The client is one end requesting to call the interface, the server is one end providing the interface for the client to call, and both the client and the server can be terminal equipment.
For example, to improve the interface call performance, the server may be a server configured for the cluster. It should be understood that the registry may be a zookeeper registry, or may be a consul registry, or may be an eureka registry.
It should be noted that, when the server can provide an interface of an application for a client to call, the server can register information such as an IP address corresponding to the server, a port number corresponding to the application available for calling in the server, and an interface name corresponding to the interface available for calling in the application in the registry. For example, the server may obtain a configuration file of the server, determine whether the server can provide an application interface for the client to call according to the configuration file, and when it is determined that the server can provide the application interface for the client to call, the server may determine information such as an IP address corresponding to the server, a port number corresponding to the application that the server can call, and an interface name corresponding to the interface that the application can call, according to the configuration file, and register the information in the registration center. Here, in order to ensure the accuracy of acquiring the IP address, the server may also dynamically acquire the IP address corresponding to the server.
Here, the registry may detect whether each interface registered in the registry can be called by means of timed polling, and when detecting that a certain interface cannot be called, the registry may mark the registration status of the interface as an invalid status (i.e., an un-callable status) or delete the interface from the registry. It can be understood that, when the application provided by the server stops the service, the server may also send notification information to the registry to notify the registry to go down or delete the interface corresponding to the application.
It should be understood that, after the client is started, the client may connect to the registry and may obtain first registration information corresponding to each interface in the registry (i.e., an interface name corresponding to each interface, a port number of an application corresponding to each interface, an IP address of a server corresponding to each interface, etc.). For example, the client may connect to the registry according to configuration information of a configuration file in the client (the configuration information may include an address of the registry, a load balancing policy, a path of the server registered in the registry, and the like), so as to obtain first registration information corresponding to each interface in the registry. After the client acquires the first registration information corresponding to each interface from the registration center, the client can establish a communication channel with each interface according to the IP address and the port number corresponding to each interface, and can store the established communication channel and each interface in a local relation of the client to serve as a candidate communication channel corresponding to each interface. Here, different service terminals may provide the same interface, and one or more communication channels may be established between the client terminal and the same interface. The number of the servers capable of providing the same interface and the number of the communication channels established between the client and the same interface may be determined according to specific situations, which is not limited in the embodiments of the present application.
It should be noted that, after the client is connected to the registry, the client may monitor the interface change in the registry in real time, and may adjust the communication channel in the local client according to the interface change. Specifically, when the interface of the server registered in the registry changes, the server may send notification information to the registry to notify the registry to add, modify, or delete the registration information corresponding to the server, or the registry may detect the interface change of the server by itself, and may add, modify, or delete the registration information corresponding to the server by itself according to the interface change. At this time, the client connected to the registry can add, modify or delete the communication channel in the local client according to the addition, modification or deletion of the registration information.
The remote procedure call method provided in the first embodiment of the present application will be described in detail below with reference to the call system described above. The execution main body of the embodiment may be a client in the calling system, and the client may be a terminal device such as a mobile phone, a tablet computer, a computer, and the like. As shown in fig. 2, the remote procedure call method in this embodiment may include:
s201, obtaining a remote procedure call request, wherein the remote procedure call request comprises interface information of a target interface requested to be called by a client;
it should be understood that, when a remote procedure call needs to be made, the client may generate a remote procedure call request, where the remote procedure call request may include interface information of a target interface requested to be called by the client, where the interface information of the target interface may include at least an interface name of the target interface.
S202, determining a candidate communication channel corresponding to the target interface according to the interface information, wherein the candidate communication channel is a communication channel stored locally at the client, and the candidate communication channel is a communication channel pre-established by the client according to first registration information of the target interface in a registration center;
as can be seen from the foregoing description, the communication channels corresponding to the client and each interface registered in the registry are stored in advance in the client local. Therefore, after obtaining the interface information of the target interface requested to be called by the client, the client may search whether the communication channel corresponding to the target interface is stored in the client according to the interface information (such as the interface name) of the target interface, and when the communication channel corresponding to the target interface is stored in the client, the searched communication channel may be determined as the candidate communication channel corresponding to the target interface.
S203, selecting a target communication channel from the candidate communication channels by using a preset load balancing strategy, and calling the target interface by using the target communication channel.
Here, the preset load balancing policy may be a polling policy or a random policy, or may be a user-defined policy. As can be seen from the foregoing description, the client may determine the preset load balancing policy according to the configuration information in the client configuration file.
It should be noted that, when only one candidate communication channel corresponding to the target interface is included, the client may directly use the candidate communication channel to call the target interface. When the candidate communication channel corresponding to the target interface includes a plurality of candidate communication channels, the client may select one target communication channel from the plurality of candidate communication channels by using the preset load balancing policy, and may use the selected target communication channel to invoke the target interface. For example, in the scenario of interface 1 that the client requests to invoke, as shown in fig. 1, when the client selects a target communication channel as communication channel 2 by using a polling policy, the client may then invoke interface 1 provided by server B by using communication channel 2.
Specifically, when the client uses the target communication channel to invoke the target interface, a target stub corresponding to the target communication channel may be first established, and then the target stub corresponding to the target communication channel may be used to invoke the target interface. The target stub is a local object for the client to call the remote target interface, and is used for receiving the local method call of the client and delegating the method call to a remote concrete implementation object (such as a target interface). It should be understood that the target Stub may be a BlockingStub (i.e., one-to-one blocking), a FutureStub (i.e., one-to-one non-blocking), or a Stub (i.e., one-to-many non-blocking). Here, the process of establishing the target stub in this embodiment may specifically refer to an existing stub establishing process, and a specific type of the established target stub may be determined according to a specific parameter corresponding to an actual calling process, which is not limited in this embodiment.
Optionally, the remote procedure call method may further include: acquiring second registration information of each candidate interface in the registration center, wherein the candidate interfaces comprise the target interface; and adjusting the candidate communication channel corresponding to each candidate interface in the local client according to the second registration information of each candidate interface.
It can be understood that, when the interface provided by the server changes, the registration information of the interface registered in the registration center also changes, and here, the client can obtain the second registration information of each candidate interface in the registration center in real time, and when it is determined that a certain candidate interface changes according to the second registration information, the client can adjust the candidate communication channel corresponding to the candidate interface locally stored by the client according to the second registration information.
For example, in a scenario where the client locally stores a candidate communication channel corresponding to the candidate interface a provided by the server a, when the application a corresponding to the candidate interface a in the server a stops service, the server a may notify the registry of going offline or deleting the registration information of the candidate interface a corresponding to the server a in the registry, and at this time, the client may delete all candidate communication channels between the client locally stored in the client and the candidate interface a in the server a according to the offline or deleted registration information corresponding to the candidate interface a.
In this embodiment, candidate communication channels corresponding to the client and each interface may be pre-established according to registration information of each interface registered in the registration center by the server, and the established candidate communication channels may be stored locally at the client. Therefore, when the remote procedure call is performed, the candidate communication channel corresponding to the target interface can be determined from the local client according to the interface information of the target interface called by the client request included in the remote procedure call request, and the target communication channel can be selected from the candidate communication channels by using a preset load balancing strategy so as to call the target interface by using the target communication channel. The method avoids the establishment of the communication channel in the remote procedure call process by establishing and caching the communication channel in advance, can greatly reduce the time consumed by the establishment of the communication channel in the remote procedure call, and improves the performance of the remote procedure call. In addition, the target communication channel is selected through a load balancing strategy, so that the performance of remote procedure call can be improved, and the user experience is improved.
[ example two ]
Fig. 3 is a system diagram illustrating a calling system to which the remote procedure calling method according to the second embodiment of the present application is applied. As shown in fig. 3, the calling system provided in this embodiment may include a registry, a client and a server, where the client and the server are connected to the registry respectively. The calling system provided in this embodiment is different from the calling system provided in the first embodiment in that the target stub used in the previous calling process of the client may be stored in advance in the client in this embodiment.
The remote procedure call method provided in the second embodiment of the present application will be described in detail below with reference to the call system described above. As shown in fig. 4, the remote procedure call method in this embodiment may include:
s401, obtaining a remote procedure call request, wherein the remote procedure call request comprises interface information of a target interface which is requested to be called by a client;
here, S401 is similar to S201 in the first embodiment, and the basic principle is the same, and for brevity, the description is omitted here.
S402, judging whether a target stub is stored in the local part of the client according to the interface information, wherein the target stub is a stub created when the client calls the target interface before;
s403, if the target stub is stored in the local client, using the target stub to call the target interface;
s404, if the target stub is not stored in the local client, determining a candidate communication channel corresponding to the target interface according to the interface information;
for the above S402 to S404, it should be understood that, in the previous remote procedure call, when a certain interface is called through a certain communication channel, the client may establish a stub based on the communication channel, and use the established stub to call the interface, and at the same time, may also store the established stub and the interface association locally at the client, so that when the client calls the interface next time, the client may directly utilize the stub stored locally at the client to call the interface, reduce the selection process of the communication channel and the establishment process of the stub, thereby improving the calling speed and performance of the remote procedure call, and improving the user experience. The number of stubs established based on the same communication channel may be one or multiple, and the specific number may be determined according to actual conditions, which is not limited in this embodiment.
Therefore, after obtaining the interface information of the target interface requested to be called by the client, the client can firstly search whether the target stub matched with the interface information is stored in the client locally according to the interface information, and when the target stub matched with the interface information is stored in the client locally, the client can directly use the target stub to call the target interface.
For example, in the scenario shown in fig. 3 where the client requests to call the interface 2, since the client locally stores the target stub (i.e., the stub 3 shown in fig. 3) created by calling the interface 2 before, the client can directly use the stub 3 to call the interface 2 provided by the server C in the current call.
It should be understood that when the target stub determined according to the interface information is one, the client may then directly use the target stub to make a call of the target interface. And when the number of the target stubs determined according to the interface information is two or more, the client side can select the target stubs through a preset load balancing strategy, and can use the finally selected target stubs to call the target interfaces. The preset load balancing policy may be the same as the load balancing policy selected by the target communication channel, or may be a policy set separately by the user, which is not limited in this embodiment.
For example, in the scenario shown in fig. 3 where the client requests to invoke the interface 1, since the client locally stores the target stubs established by the previous invocation of the interface 1 (i.e. the stubs 1, 2, and 4 shown in fig. 3), in this invocation, the client may first select the target stub from the stubs 1, 2, and 4 by using a load balancing policy, and assume that the selected target stub is the stub 2, and then the client may invoke the interface 1 provided by the server a by using the stub 2.
For example, to ensure the validity of the remote procedure call, the client may first determine the stub state of the target stub when using the target stub to call the target interface; when the stub state of the target stub is a first preset state (namely an invalid state), the acquired target stub is considered to be unavailable, and at the moment, the client can determine a candidate communication channel corresponding to the target interface according to the interface information; when the stub state of the target stub is a second preset state (i.e., a valid state), the client may use the target stub to call the target interface.
It should be understood that, in the case that there are multiple target stubs, the client may determine the candidate communication channels according to the interface information when all the target stubs are unavailable. That is, under the condition that a plurality of target stubs exist, when a first target stub selected according to a preset load balancing strategy is unavailable, the client can immediately select a second target stub according to the preset load balancing strategy and can continuously judge whether the second target stub is available, when the second target stub is unavailable, a third target stub, a fourth target stub and the like can be continuously selected according to the preset load balancing strategy, and the client can determine the candidate communication channel according to the interface information until all the target stubs are unavailable.
Of course, in this embodiment, the client may also determine the candidate communication channel directly according to the interface information when the first target stub determined by using the preset load balancing policy is unavailable, which is not limited in this embodiment.
Specifically, the client may determine the stub state of the target stub by detecting a registration state of a target interface corresponding to the target stub in the registration center, where the registration state of the target interface in the registration center may include an active state and an inactive state, and the inactive state is information that registration information corresponding to the target interface is offline or deleted; when the registration state of the target interface corresponding to the target stub in the registration center is an effective state, determining that the stub state of the target stub is a second preset state (i.e., an effective state that can be used); when the registration state of the target interface corresponding to the target stub in the registration center is an invalid state, it may be determined that the stub state of the target stub is a first preset state (i.e., an invalid state that cannot be used).
S405, selecting a target communication channel from the candidate communication channels by using a preset load balancing strategy, and calling the target interface by using the target communication channel.
Here, the content of S405 is similar to that of S203 in the first embodiment, and the basic principle is the same, and for brevity, the description is omitted here.
For example, when the client calls the target interface using the target communication channel, the target stub corresponding to the target communication channel may be first established, and then the target interface may be called using the target stub corresponding to the target communication channel. For example, in order to improve the calling speed and performance of next target interface calling, after the client establishes the target stub corresponding to the target communication channel, the target stub corresponding to the target communication channel and the target interface may be stored locally in the client in an associated manner, so that when the client calls the target interface next time, the client may directly obtain the target stub locally from the client to call the interface, and the interface calling performance is improved.
In the embodiment, the target stub established in the previous remote procedure call of the client is stored locally at the client, so that the target interface can be called directly by using the local target stub of the client when the same target interface is called subsequently, the selection process of a target communication channel is reduced, the establishment process of the target stub is reduced, the call speed and performance of the remote procedure call can be greatly improved, and the user experience is improved.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[ EXAMPLE III ]
Fig. 5 shows a block diagram of a remote procedure call device provided in the third embodiment of the present application, which corresponds to the remote procedure call method described in the foregoing embodiment, and for convenience of description, only the parts related to the third embodiment of the present application are shown.
Referring to fig. 5, the remote procedure call apparatus may include:
a call request obtaining module 501, configured to obtain a remote procedure call request, where the remote procedure call request includes interface information of a target interface requested to be called by a client;
a candidate channel determining module 502, configured to determine, according to the interface information, a candidate communication channel corresponding to the target interface, where the candidate communication channel is a communication channel stored locally at the client, and the candidate communication channel is a communication channel pre-established by the client according to the first registration information of the target interface in the registry;
and a remote procedure call module 503, configured to select a target communication channel from the candidate communication channels by using a preset load balancing policy, and call the target interface using the target communication channel.
In a possible implementation manner, the candidate channel determining module 502 may include:
a target stub determining unit, configured to determine, according to the interface information, whether a target stub is stored locally in the client, where the target stub is a stub created when the client calls the target interface before;
a target stub calling unit, configured to call the target interface using the target stub if the target stub is locally stored in the client;
and the candidate channel determining unit is used for determining a candidate communication channel corresponding to the target interface according to the interface information if the target stub is not locally stored in the client.
Optionally, the target stub invoking unit may include:
the stub state determination sub-unit is used for determining the stub state of the target stub;
a candidate channel determination subunit, configured to determine, if the stub state is a first preset state, a candidate communication channel corresponding to the target interface according to the interface information;
and the target stub calling sub-unit is used for calling the target interface by using the target stub if the stub state is a second preset state.
Illustratively, the stub state determination subunit is configured to detect a registration state of a target interface corresponding to the target stub in the registry, where the registration state includes a valid state and an invalid state; when the registration state of the target interface corresponding to the target stub in the registration center is an effective state, determining that the stub state of the target stub is the second preset state; and when the registration state of the target interface corresponding to the target stub in the registration center is an invalid state, determining that the stub state of the target stub is the first preset state.
In a possible implementation manner, the remote procedure call module 503 may include:
the target stub establishing unit is used for establishing a target stub corresponding to the target communication channel and storing the target stub corresponding to the target communication channel in the local part of the client;
and the remote procedure calling unit is used for calling the target interface by using the target stub corresponding to the target communication channel.
Optionally, the remote procedure call apparatus may further include:
a registration information obtaining module, configured to obtain second registration information of each candidate interface in the registration center, where the candidate interface includes the target interface;
and the candidate channel adjusting module is used for adjusting the candidate communication channel corresponding to each candidate interface in the local client according to the second registration information of each candidate interface.
It should be noted that, for the information interaction, execution process, and other contents between the above-mentioned devices/units, the specific functions and technical effects thereof are based on the same concept as those of the embodiment of the method of the present application, and specific reference may be made to the part of the embodiment of the method, which is not described herein again.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
Fig. 6 is a schematic structural diagram of a terminal device according to an embodiment of the present application. As shown in fig. 6, the terminal device 6 of this embodiment includes: at least one processor 60 (only one shown in fig. 6), a memory 61, and a computer program 62 stored in the memory 61 and executable on the at least one processor 60, the processor 60 implementing the steps in any of the various remote procedure call method embodiments described above when executing the computer program 62.
The terminal device 6 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The terminal device may include, but is not limited to, a processor 60, a memory 61. Those skilled in the art will appreciate that fig. 6 is only an example of the terminal device 6, and does not constitute a limitation to the terminal device 6, and may include more or less components than those shown, or combine some components, or different components, such as an input/output device, a network access device, and the like.
The Processor 60 may be a Central Processing Unit (CPU), and the Processor 60 may be other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 61 may in some embodiments be an internal storage unit of the terminal device 6, such as a hard disk or a memory of the terminal device 6. The memory 61 may also be an external storage device of the terminal device 6 in other embodiments, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are equipped on the terminal device 6. Further, the memory 61 may also include both an internal storage unit and an external storage device of the terminal device 6. The memory 61 is used for storing an operating system, an application program, a BootLoader (BootLoader), data, and other programs, such as program codes of the computer program. The memory 61 may also be used to temporarily store data that has been output or is to be output.
The embodiments of the present application further provide a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program implements the steps in the above-mentioned method embodiments.
The embodiments of the present application provide a computer program product, which when running on a terminal device, enables the terminal device to implement the steps in the above method embodiments when executed.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the processes in the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium and can implement the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable storage medium may include at least: any entity or device capable of carrying computer program code to an apparatus/terminal device, recording medium, computer Memory, Read-Only Memory (ROM), random-access Memory (RAM), electrical carrier wave signals, telecommunications signals, and software distribution medium. Such as a usb-disk, a removable hard disk, a magnetic or optical disk, etc. In certain jurisdictions, computer-readable media may not be an electrical carrier signal or a telecommunications signal in accordance with legislative and patent practice.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. 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 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 apparatus/device embodiments are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, 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 be in an electrical, mechanical or other form.
The 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 embodiment.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.
Claims (10)
1. A remote procedure call method, comprising:
acquiring a remote procedure call request, wherein the remote procedure call request comprises interface information of a target interface requested to be called by a client;
determining a candidate communication channel corresponding to the target interface according to the interface information, wherein the candidate communication channel is a communication channel stored locally at the client, and the candidate communication channel is a communication channel pre-established by the client according to first registration information of the target interface in a registration center;
and selecting a target communication channel from the candidate communication channels by using a preset load balancing strategy, and calling the target interface by using the target communication channel.
2. The remote procedure call method according to claim 1, wherein said determining the candidate communication channel corresponding to the target interface according to the interface information comprises:
judging whether a target stub is stored in the local part of the client according to the interface information, wherein the target stub is a stub created when the client calls the target interface before;
if the target stub is locally stored in the client, using the target stub to call the target interface;
and if the target stub is not locally stored in the client, determining a candidate communication channel corresponding to the target interface according to the interface information.
3. The remote procedure call method as recited in claim 2, wherein said calling the target interface using the target stub comprises:
determining a stub state of the target stub;
if the stub state is a first preset state, determining a candidate communication channel corresponding to the target interface according to the interface information;
and if the stub state is a second preset state, using the target stub to call the target interface.
4. The remote procedure call method as recited in claim 3, wherein said determining a stub state of the target stub comprises:
detecting a registration state of a target interface corresponding to the target stub in the registration center, wherein the registration state comprises a valid state and an invalid state;
when the registration state of the target interface corresponding to the target stub in the registration center is an effective state, determining that the stub state of the target stub is the second preset state;
and when the registration state of the target interface corresponding to the target stub in the registration center is an invalid state, determining that the stub state of the target stub is the first preset state.
5. The remote procedure call method according to claim 1, wherein said calling the target interface using the target communication channel comprises:
establishing a target stub corresponding to the target communication channel, and storing the target stub corresponding to the target communication channel in the local part of the client;
and calling the target interface by using the target stub corresponding to the target communication channel.
6. The remote procedure call method according to any one of claims 1 to 5, wherein the remote procedure call method further comprises:
acquiring second registration information of each candidate interface in the registration center, wherein the candidate interfaces comprise the target interface;
and adjusting the candidate communication channel corresponding to each candidate interface in the local client according to the second registration information of each candidate interface.
7. A remote procedure call device, comprising:
the system comprises a calling request acquisition module, a remote procedure calling module and a calling module, wherein the calling request acquisition module is used for acquiring a remote procedure calling request which comprises interface information of a target interface requested to be called by a client;
a candidate channel determining module, configured to determine, according to the interface information, a candidate communication channel corresponding to the target interface, where the candidate communication channel is a communication channel stored locally at the client, and the candidate communication channel is a communication channel pre-established by the client according to first registration information of the target interface in a registration center;
and the remote procedure calling module is used for selecting a target communication channel from the candidate communication channels by using a preset load balancing strategy and calling the target interface by using the target communication channel.
8. The remote procedure call apparatus of claim 7, wherein the candidate channel determination module comprises:
a target stub determining unit, configured to determine, according to the interface information, whether a target stub is stored locally in the client, where the target stub is a stub created when the client calls the target interface before;
a target stub calling unit, configured to call the target interface using the target stub if the target stub is locally stored in the client;
and the candidate channel determining unit is used for determining a candidate communication channel corresponding to the target interface according to the interface information if the target stub is not locally stored in the client.
9. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the remote procedure call method according to any of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored which, when being executed by a processor, carries out the remote procedure call method according to any one of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010316388.1A CN111580987B (en) | 2020-04-21 | 2020-04-21 | Remote procedure call method, device, storage medium and terminal equipment |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010316388.1A CN111580987B (en) | 2020-04-21 | 2020-04-21 | Remote procedure call method, device, storage medium and terminal equipment |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111580987A true CN111580987A (en) | 2020-08-25 |
CN111580987B CN111580987B (en) | 2024-08-06 |
Family
ID=72126634
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010316388.1A Active CN111580987B (en) | 2020-04-21 | 2020-04-21 | Remote procedure call method, device, storage medium and terminal equipment |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111580987B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112162873A (en) * | 2020-09-28 | 2021-01-01 | 杭州安恒信息技术股份有限公司 | Remote calling method, electronic device and storage medium |
Citations (7)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO1995017718A1 (en) * | 1993-12-20 | 1995-06-29 | Taligent, Inc. | Object-oriented remote procedure call networking system |
CN101909061A (en) * | 2010-08-06 | 2010-12-08 | 福建升腾资讯有限公司 | Creation and application method of dynamic virtual channel based on remote display protocol |
CN104639539A (en) * | 2015-01-27 | 2015-05-20 | 深圳市汇朗科技有限公司 | Method and device for interface calling |
CN106998343A (en) * | 2016-01-26 | 2017-08-01 | 阿里巴巴集团控股有限公司 | A kind of remote procedure call processing method, apparatus and system |
CN110134528A (en) * | 2019-04-15 | 2019-08-16 | 平安普惠企业管理有限公司 | Interface message storage call method, device and the terminal device of micro services frame |
CN110674061A (en) * | 2019-09-24 | 2020-01-10 | 上海商汤临港智能科技有限公司 | Control method and device of machine equipment and storage medium |
WO2020019972A1 (en) * | 2018-07-23 | 2020-01-30 | 百富计算机技术(深圳)有限公司 | Communication method between applications, terminal device, and storage medium |
-
2020
- 2020-04-21 CN CN202010316388.1A patent/CN111580987B/en active Active
Patent Citations (8)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
WO1995017718A1 (en) * | 1993-12-20 | 1995-06-29 | Taligent, Inc. | Object-oriented remote procedure call networking system |
US5491800A (en) * | 1993-12-20 | 1996-02-13 | Taligent, Inc. | Object-oriented remote procedure call networking system |
CN101909061A (en) * | 2010-08-06 | 2010-12-08 | 福建升腾资讯有限公司 | Creation and application method of dynamic virtual channel based on remote display protocol |
CN104639539A (en) * | 2015-01-27 | 2015-05-20 | 深圳市汇朗科技有限公司 | Method and device for interface calling |
CN106998343A (en) * | 2016-01-26 | 2017-08-01 | 阿里巴巴集团控股有限公司 | A kind of remote procedure call processing method, apparatus and system |
WO2020019972A1 (en) * | 2018-07-23 | 2020-01-30 | 百富计算机技术(深圳)有限公司 | Communication method between applications, terminal device, and storage medium |
CN110134528A (en) * | 2019-04-15 | 2019-08-16 | 平安普惠企业管理有限公司 | Interface message storage call method, device and the terminal device of micro services frame |
CN110674061A (en) * | 2019-09-24 | 2020-01-10 | 上海商汤临港智能科技有限公司 | Control method and device of machine equipment and storage medium |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN112162873A (en) * | 2020-09-28 | 2021-01-01 | 杭州安恒信息技术股份有限公司 | Remote calling method, electronic device and storage medium |
CN112162873B (en) * | 2020-09-28 | 2024-03-26 | 杭州安恒信息技术股份有限公司 | Remote calling method, electronic device and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111580987B (en) | 2024-08-06 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US8832304B2 (en) | Protocol agnostic notification system | |
CN111240863B (en) | Data communication method, device, micro front-end system and storage medium | |
CN111163130B (en) | Network service system and data transmission method thereof | |
CN108429739B (en) | Method, system and terminal equipment for identifying honeypots | |
CN113076281B (en) | Method, system, equipment and medium for communication of Ceph kernel client | |
CN112818336A (en) | Data access method, data access device and computer readable storage medium | |
CN109976787A (en) | Application program updating method, apparatus, terminal and computer readable storage medium | |
CN114637703B (en) | Data access device, method, readable medium and electronic equipment | |
CN114268667B (en) | Data forwarding method, device, computer equipment and storage medium | |
CN111580987B (en) | Remote procedure call method, device, storage medium and terminal equipment | |
CN112702362B (en) | Method and device for enhancing TCP/IP protocol stack, electronic equipment and storage medium | |
CN106161647A (en) | The method of a kind of cloud terminal unit batch discovery and cloud terminal management system | |
CN111597041B (en) | Calling method and device of distributed system, terminal equipment and server | |
CN114697888B (en) | 5G message processing method, device and storage medium | |
CN110784510A (en) | Method for accessing target service node to bus and information interaction method of service node | |
CN113115400B (en) | Communication method and device | |
CN114244654B (en) | URL forwarding method, device, equipment and computer storage medium | |
CN113055250B (en) | Networking communication method, device, terminal equipment and storage medium | |
CN113051077A (en) | User request processing method and device, terminal equipment and storage medium | |
CN110519357B (en) | File transmission method and system, computer device and storage medium | |
CN113556370A (en) | Service calling method and device | |
CN113032820A (en) | File storage method, access method, device, equipment and storage medium | |
CN114915610B (en) | Method, device, electronic equipment and storage medium for sending network request | |
CN117640667B (en) | Transaction information access method and device, terminal equipment and storage medium | |
CN114785794B (en) | Resource allocation method, device, equipment, medium and system |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |