[go: up one dir, main page]

WO2019001074A1 - 一种远程过程调用的方法、装置及计算机设备 - Google Patents

一种远程过程调用的方法、装置及计算机设备 Download PDF

Info

Publication number
WO2019001074A1
WO2019001074A1 PCT/CN2018/082164 CN2018082164W WO2019001074A1 WO 2019001074 A1 WO2019001074 A1 WO 2019001074A1 CN 2018082164 W CN2018082164 W CN 2018082164W WO 2019001074 A1 WO2019001074 A1 WO 2019001074A1
Authority
WO
WIPO (PCT)
Prior art keywords
processing function
target
asynchronous processing
parameter
identifier
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.)
Ceased
Application number
PCT/CN2018/082164
Other languages
English (en)
French (fr)
Inventor
杨亮
陈少杰
张文明
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Douyu Network Technology Co Ltd
Original Assignee
Wuhan Douyu Network Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Wuhan Douyu Network Technology Co Ltd filed Critical Wuhan Douyu Network Technology Co Ltd
Publication of WO2019001074A1 publication Critical patent/WO2019001074A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/133Protocols for remote procedure calls [RPC]
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

Definitions

  • the invention belongs to the technical field of communications, and in particular relates to a method, a device and a computer device for remote procedure call.
  • a remote procedure call is a method provided by one process to call another process, suitable for communication between processes.
  • the present invention provides a method, apparatus and computer device for remote procedure call to solve the above problems in the prior art.
  • the present invention provides a method, a device, and a computer device for remote procedure call, which are used to solve the problem that the thread scheduling and allocation cannot be flexibly performed when performing a remote procedure call in the prior art.
  • the present invention provides a method of remote procedure call, the method comprising:
  • the target asynchronous processing function is called in the main thread
  • the target asynchronous processing function is invoked in the main thread, including:
  • the target asynchronous processing function is delivered to the main thread, and the target asynchronous processing function is called in the main thread.
  • the generating a contextual environment block based on the parameter information and the identifier includes:
  • the second identifier is assigned to a second identification field of the contextual environment block.
  • the obtaining and sending the execution result by using the acquisition function includes:
  • the execution result is transmitted using the acquisition function RpcCompleteAsyncProcedure.
  • the method further includes: deleting the context environment block.
  • the method further includes:
  • a result set is returned, the result set including an indication value indicating that there is no search result.
  • the model of the asynchronous processing function includes:
  • the RpcAsyncProcedure is a name of the asynchronous processing function, the caller, lRpcArgument is an identification parameter; the args is parameter information in the target call request; the numArgs is a number of the args parameter; the RpcAsyncProcedureContext
  • the context is a parameter for recording a context context associated with the current response in the context context block.
  • the present invention also provides an apparatus for remote procedure call, the apparatus comprising:
  • a registration unit for registering the name of the pre-agreed remote method and the corresponding asynchronous processing function into the global dictionary
  • a receiving unit configured to receive a target call request
  • a determining unit configured to determine, according to the target call request, whether a target asynchronous processing function corresponding to the target call request can be found in the global dictionary
  • a calling unit configured to find the target asynchronous processing function in the global dictionary, and invoke the target asynchronous processing function in a main thread
  • An execution unit configured to determine a data amount of the target asynchronous processing function to be processed, allocate a sub-thread according to the data amount of the to-be-processed task, execute the target asynchronous processing function in the sub-thread, and acquire by using an acquisition function And send the execution result.
  • the present invention also provides a computer readable storage medium having stored thereon a computer program that, when executed by a processor, implements the following steps:
  • the target asynchronous processing function is called in the main thread
  • the invention also provides a remote process call computer device, comprising:
  • At least one processor At least one processor
  • At least one memory communicatively coupled to the processor, wherein
  • the memory stores program instructions executable by the processor, the processor invoking the program instructions to perform the method of any of the above.
  • the present invention provides a remote procedure call method, apparatus and computer apparatus, the method comprising: registering a name of a pre-agreed remote method and a corresponding asynchronous processing function into a global dictionary; receiving a target call request; Determining whether the target asynchronous processing function corresponding to the target calling request can be found in the global dictionary; if the target asynchronous processing function can be found in the global dictionary, calling the target in the main thread Determining a target asynchronous processing function; determining a data amount of the target asynchronous processing function to be processed, allocating a sub-thread according to the data amount of the to-be-processed task, executing the target asynchronous processing function in the sub-thread; using an acquisition function Obtain and send the execution result; in this way, the corresponding sub-thread can be allocated according to the data amount of the target asynchronous processing function to be processed, so that the thread scheduling allocation can be flexibly performed, and the multi-thread conflict is caused to cause the program to crash, thereby
  • FIG. 1 is a schematic flowchart of a method for remote procedure call according to Embodiment 1 of the present invention
  • FIG. 2 is a schematic structural diagram of an apparatus for remote procedure call according to Embodiment 2 of the present invention.
  • FIG. 3 is a schematic structural diagram of a computer device for remote procedure call according to Embodiment 3 of the present invention.
  • This embodiment provides a method for remote procedure call. As shown in FIG. 1, the method includes:
  • the RpcRegisterProcedure function needs to be called to register the name of the pre-agreed remote method and the asynchronous processing function corresponding to the remote method to the global dictionary Dict, so that when the call request is received, the request can be directly Find the corresponding asynchronous processing function in the global dictionary Dict, quickly build a remote procedure call model, and improve processing efficiency.
  • the pre-agreed remote method is pre-agreed by the calling end and the called end.
  • model of the asynchronous processing function includes:
  • S102 Receive a target call request, and determine, according to the target call request, whether a target asynchronous processing function corresponding to the target call request can be found in the global dictionary;
  • the receiving call end calls the RpcCallProcedure function to send a target call request, and based on the target call request, judges that Whether the target asynchronous processing function corresponding to the call request can be found in the global dictionary.
  • the target asynchronous processing function corresponding to the call request can be found in the global dictionary.
  • the procedure field in the RpcMessage message represents the name of the remote method to be called, and the target asynchronous processing function RpcAsyncProcedure is looked up in the global dictionary Dict according to the method name.
  • the target asynchronous processing function is called in a main thread.
  • the target asynchronous processing function RpcAsyncProcedure if the target asynchronous processing function RpcAsyncProcedure can be found in the global dictionary, the target asynchronous processing function RpcAsyncProcedure is called in the main thread.
  • obtaining a first identifier for indicating a successful network connection here, when the calling end establishes a network connection with the called end, a first identifier is generated to uniquely identify the calling end, The first identifier is the session.
  • the GetRpcArgsFromMessage function is called to obtain all the parameter information in the target call request from the RpcMessage message.
  • the lRpcArgument structure is obtained from the RpcMessage message by calling the GetRpcArgsFromMessage function, and then the parameter obtaining method i32Value in the lRpcArgument structure is called to obtain the parameter information in the target calling request.
  • the second identifier is a unique identifier of the target call request, and is used to distinguish from other call requests to avoid confusion; There is a unique identifier for the call request.
  • a second identifier is generated, and the identifier is written into the gid field of the RpcMessage message, and when the called end receives the RpcMessage message, The second identifier in the target call request can be obtained from the gid field.
  • an asynchronous context environment block is generated based on the parameter information, the first identifier, and the second identifier.
  • the parameter information is assigned to a parameter field of the contextual environment block (ie, an arg field); the first identifier is assigned to a first identification field (gid field) of the context environment; The second identifier is assigned to a second identification field (session field) of the contextual environment block.
  • a parameter field of the contextual environment block ie, an arg field
  • the first identifier is assigned to a first identification field (gid field) of the context environment
  • the second identifier is assigned to a second identification field (session field) of the contextual environment block.
  • the first identifier as a first parameter of the target asynchronous processing function, setting the parameter information as a second parameter of the target asynchronous processing function, and setting the number of parameters in the parameter list Set a third parameter of the target asynchronous processing function, and set the context environment block as a fourth parameter of the target asynchronous processing function; wherein the first parameter is the caller, lRpcArgument parameter
  • the second is the parameter args parameter; the third parameter is the numArgs parameter; and the fourth parameter is the RpcAsyncProcedureContext parameter.
  • the target asynchronous processing function is delivered to the main thread, and the target asynchronous processing function is called in the main thread.
  • S104 Determine a data quantity of the target asynchronous processing function to be processed, allocate a sub-thread according to the data quantity of the to-be-processed task, execute the target asynchronous processing function in the sub-thread, acquire and send the execution by using an acquisition function. result.
  • the target asynchronous processing function After the target asynchronous processing function is executed, in order to further improve the processing performance of the target asynchronous processing function, it is not necessary to return the execution result in the target asynchronous processing function, but the acquisition function is required to acquire and send the execution result to the calling end.
  • serializing the second identifier and the execution result into a network message specifically, calling the BuildRpcMessageFrom method to list the result set and the second identifier of the execution result into a network message, and
  • the gid field in the message is set to an identifier
  • the rpcType field in the network message is set to an RPC_MESSAGE_RESPONSE value, indicating that the network message is a remote response message.
  • the network message and the context environment block are set into corresponding parameters in the acquisition function RpcCompleteAsyncProcedure; the execution result is sent by using the acquisition function RpcCompleteAsyncProcedure.
  • the method further includes: deleting (releasing) the context environment block RpcAsyncProcedureContext.
  • the method further includes: returning a result set, where the result set includes an indication value for indicating no search result, and the content of the indication value is ERROR_RPC_NOT_FOUND, for Tell the caller that the called process does not have the remote procedure method.
  • the embodiment provides a remote procedure call device.
  • the remote procedure call device includes: a registration unit 21, a receiving unit 22, a determining unit 23, a calling unit 24, and an executing unit. 25; among them,
  • the registration unit 21 Before receiving the call request, the registration unit 21 needs to call the RpcRegisterProcedure function to register the name of the pre-determined remote method and the asynchronous processing function corresponding to the remote method into the global dictionary Dict, so that when the call request is received, Find the corresponding asynchronous processing function directly in the global dictionary Dict, quickly build a remote procedure call model, and improve processing efficiency.
  • the pre-agreed remote method is pre-agreed by the calling end and the called end.
  • model of the asynchronous processing function includes:
  • the receiving unit 22 receives the target call request sent by the number of calling terminals, and is called based on the target. The request determines whether the target asynchronous processing function corresponding to the call request can be found in the global dictionary.
  • the determining unit 23 acquires the name of the remote method, and based on the name, determines whether the global dictionary can find the location.
  • the procedure field in the RpcMessage message represents the name of the remote method to be called, and the target asynchronous processing function RpcAsyncProcedure is looked up in the global dictionary Dict according to the method name.
  • the calling unit 24 is configured to call the target asynchronous processing function RpcAsyncProcedure in the main thread.
  • the calling unit 24 first obtains a first identifier for indicating a successful network connection based on the callback function; where, after the calling end establishes a network connection with the called end, the first identifier is generated. To uniquely identify the caller, the first identifier is the session.
  • the calling unit 24 calls the GetRpcArgsFromMessage function to obtain all the parameter information in the target call request from the RpcMessage message.
  • the lRpcArgument structure is obtained from the RpcMessage message by calling the GetRpcArgsFromMessage function, and then the parameter obtaining method i32Value in the lRpcArgument structure is called to obtain the parameter information in the target calling request.
  • the calling unit 24 then acquires the second identifier in the target call request; the target second identifier is a unique identifier of the target call request, and is used to distinguish from other call requests to avoid confusion; The result is that there is a unique identifier for each call request.
  • a second identifier is generated, and the identifier is written into the gid field of the RpcMessage message, and when the called end receives the RpcMessage message, The calling unit 24 can obtain the second identifier in the target call request from the gid field.
  • an asynchronous context environment block is generated based on the parameter information, the first identifier, and the second identifier.
  • the parameter information is assigned to a parameter field of the contextual environment block (ie, an arg field); the first identifier is assigned to a first identification field (gid field) of the context environment; The second identifier is assigned to a second identification field (session field) of the contextual environment block.
  • a parameter field of the contextual environment block ie, an arg field
  • the first identifier is assigned to a first identification field (gid field) of the context environment
  • the second identifier is assigned to a second identification field (session field) of the contextual environment block.
  • the first identifier as a first parameter of the target asynchronous processing function, setting the parameter information as a second parameter of the target asynchronous processing function, and setting the number of parameters in the parameter list Set a third parameter of the target asynchronous processing function, and set the context environment block as a fourth parameter of the target asynchronous processing function; wherein the first parameter is the caller, lRpcArgument parameter
  • the second parameter is the args parameter; the third parameter is the numArgs parameter; and the fourth parameter is the RpcAsyncProcedureContext parameter.
  • the calling unit 24 delivers the target asynchronous processing function to the main thread, and invokes the target asynchronous processing function in the main thread.
  • the executing unit 25 determines the target asynchronous processing function.
  • the amount of data of the task to be processed, and the child thread is allocated according to the data amount of the task to be processed, and the target asynchronous processing function is executed in the child thread; wherein the to-be-processed task may include: accessing a database or calculating an operation Tasks with large data streams.
  • the execution unit 25 needs to acquire and send the execution result to the call by using the acquisition function. end.
  • the executing unit 25 serializes the second identifier and the execution result into a network message; specifically, calling the BuildRpcMessageFrom method to list the result set and the second identifier of the execution result into a network.
  • the message is set to the identifier in the network message, and the rpcType field in the network message is set to the RPC_MESSAGE_RESPONSE value, indicating that the network message is a remote response message.
  • the execution unit 25 After being serialized into a network message, the execution unit 25 sets the network message and the context environment block to corresponding parameters in the acquisition function RpcCompleteAsyncProcedure; and transmits the execution result by using the acquisition function RpcCompleteAsyncProcedure.
  • the acquisition function RpcCompleteAsyncProcedure After being serialized into a network message, the execution unit 25 sets the network message and the context environment block to corresponding parameters in the acquisition function RpcCompleteAsyncProcedure; and transmits the execution result by using the acquisition function RpcCompleteAsyncProcedure.
  • the executing unit 25 is further configured to: delete (release) the context environment block RpcAsyncProcedureContext.
  • the executing unit 25 is further configured to: return a result set, where the result set includes an indication value for indicating no search result, and the content of the indication value For ERROR_RPC_NOT_FOUND, it is used to inform the caller that the called process does not have the remote procedure method.
  • the called end calls the RpcRegisterProcedure function before receiving the call request, and registers the name of the pre-scheduled add remote method and the corresponding asynchronous processing function in the global dictionary Dict, so that when the call request is received, the global dictionary Dict can be directly used. Find the asynchronous processing function corresponding to the add remote method, quickly build the remote procedure call model, and improve the processing efficiency.
  • model of the asynchronous processing function includes:
  • the receiving call end calls the RpcCallProcedure function to call the target call request of the add remote method, and based on the target call request, determines whether the target asynchronous processing function corresponding to the call request can be found in the global dictionary.
  • the procedure field in the RpcMessage message represents the remote method name to be called, and the target asynchronous processing function RpcAsyncProcedure is looked up in the global dictionary Dict according to the method name.
  • the target asynchronous processing function RpcAsyncProcedure can be found in the global dictionary, the target asynchronous processing function RpcAsyncProcedure is called in the main thread.
  • obtaining a first identifier for indicating a successful network connection here, when the calling end establishes a network connection with the called end, a first identifier is generated to uniquely identify the calling end, The first identifier is the session.
  • the GetRpcArgsFromMessage function is called to obtain all the parameter information in the target call request from the RpcMessage message.
  • the lRpcArgument structure is obtained from the RpcMessage message by calling the GetRpcArgsFromMessage function, and then the parameter obtaining method i32Value in the lRpcArgument structure is called, and the value corresponding to the second parameter is obtained by using the i32Value method, that is, args[0]->i32Value ()
  • the value obtained is 1, and the value obtained by args[1]->i32Value() is 2.
  • the second identifier is a unique identifier of the target call request corresponding to the add remote method, and is used to distinguish from other call requests to avoid confusion;
  • the result is that there is a unique identifier for each call request.
  • a second identifier is generated, and the identifier is written into the gid field of the RpcMessage message, and when the called end receives the RpcMessage message, The second identifier in the target call request can be obtained from the gid field.
  • an asynchronous context environment block is generated based on the parameter information, the first identifier, and the second identifier.
  • the parameter information 1 and 2 are assigned to a parameter field (ie, an arg field) of the contextual environment block; the first identifier is assigned to a first identification field (gid field) of the context environment; The second identifier is assigned to a second identification field (session field) of the contextual environment block.
  • a parameter field ie, an arg field
  • the first identifier is assigned to a first identification field (gid field) of the context environment
  • the second identifier is assigned to a second identification field (session field) of the contextual environment block. This generates an asynchronous context environment block.
  • the first identifier as a first parameter of the target asynchronous processing function, setting the parameter information as a second parameter of the target asynchronous processing function, and setting the number of parameters in the parameter list Set a third parameter of the target asynchronous processing function, and set the context environment block as a fourth parameter of the target asynchronous processing function; wherein the first parameter is the caller, lRpcArgument parameter
  • the second parameter args parameter; the third parameter is the numArgs parameter; the fourth parameter is the RpcAsyncProcedureContext parameter.
  • the first parameter in the args parameter is the value 1
  • the second parameter is the value 2; the numArgs parameter should be 2.
  • the target asynchronous processing function is then posted to the main thread, and the target asynchronous processing function is called in the main thread.
  • the main thread calls the target asynchronous processing function of the add remote method
  • the target is asynchronous.
  • the task to be processed may include: accessing a database or computing a task with a large data stream.
  • the second identifier and the execution result are serialized into a network message; specifically, the BuildRpcMessageFrom method is invoked to list the result set and the second identifier of the execution result into a network message, and the gid in the network message is The field is set to an identifier, and the rpcType field in the network message is set to the RPC_MESSAGE_RESPONSE value to indicate that the network message is a remote response message.
  • the network message and the context environment block are set into corresponding parameters in the acquisition function RpcCompleteAsyncProcedure; the execution result is sent by using the acquisition function RpcCompleteAsyncProcedure.
  • the method further includes: deleting (releasing) the context environment block RpcAsyncProcedureContext.
  • the method further includes: returning a result set, where the result set includes an indication value for indicating that there is no search result, and the content of the indication value is ERROR_RPC_NOT_FOUND can be used to inform the caller that the called end does not have a remote procedure method.
  • the embodiment further provides a remote process call computer device.
  • the computer device includes: a radio frequency (RF) circuit 310, a memory 320, an input unit 330, a display unit 340, and an audio circuit 350. , WiFi module 360, processor 370, and power supply 380 and other components.
  • RF radio frequency
  • FIG. 3 does not constitute a limitation to a computer device, and may include more or fewer components than those illustrated, or a combination of certain components, or different component arrangements.
  • the RF circuit 310 can be used for receiving and transmitting signals, and in particular, receiving downlink information of the base station and processing it to the processor 370.
  • RF circuit 310 includes, but is not limited to, at least one amplifier, transceiver, coupler, Low Noise Amplifier (LNA), duplexer, and the like.
  • LNA Low Noise Amplifier
  • the memory 320 can be used to store software programs and modules, and the processor 370 executes various functional applications and data processing of the computer devices by running software programs and modules stored in the memory 320.
  • the memory 320 may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application required for at least one function, and the like; the storage data area may store data created according to usage of the computer device, and the like.
  • memory 320 can include high speed random access memory, and can also include non-volatile memory, such as at least one magnetic disk storage device, flash memory device, or other volatile solid state storage device.
  • the input unit 330 can be configured to receive input numeric or character information and to generate key signal inputs related to user settings and function control of the computer device.
  • the input unit 330 may include a touch panel 331 and other input devices 332.
  • the touch panel 331 can collect input operations of the user and drive the corresponding connecting device according to a preset program.
  • the touch panel 331 collects the output information and sends it to the processor 370.
  • the input unit 330 may also include other input devices 332.
  • other input devices 332 may include, but are not limited to, one or more of a touch panel, function keys (such as volume control buttons, switch buttons, etc.), trackballs, mice, joysticks, and the like.
  • the display unit 340 can be used to display information input by the user or information provided to the user as well as various menus of the computer device.
  • the display unit 340 can include a display panel 341.
  • the display panel 341 can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), or the like.
  • the touch panel 331 can cover the display panel 341. When the touch panel 331 detects a touch operation on or near the touch panel 331, it transmits to the processor 370 to determine the type of the touch event, and then the processor 370 according to the input event. The type provides a corresponding visual output on display panel 341.
  • the touch panel 331 and the display panel 341 are implemented as two separate components in FIG. 3 to implement input and input functions of the computer device, in some embodiments, the touch panel 331 may be integrated with the display panel 341. Implement the input and output functions of computer equipment.
  • An audio circuit 350, a speaker 351, and a microphone 352 can provide an audio interface between the user and the computer device.
  • the audio circuit 350 can transmit the converted electrical data of the received audio data to the speaker 351, and convert it into a sound signal output by the speaker 351;
  • WiFi is a short-range wireless transmission technology.
  • the computer device can help users to send and receive emails, browse web pages and access streaming media through the WiFi module 360. It provides users with wireless broadband Internet access.
  • FIG. 3 shows the WiFi module 360, it can be understood that it does not belong to the essential configuration of the computer device, and may be omitted as needed within the scope of not changing the essence of the invention.
  • Processor 370 is a control center for computer devices that connects various portions of the entire computer device using various interfaces and lines, by running or executing software programs and/or modules stored in memory 320, and recalling data stored in memory 320. , performing various functions and processing data of the computer device, thereby performing overall monitoring of the computer device.
  • the processor 370 may include one or more processing units; preferably, the processor 370 may integrate an application processor, wherein the application processor mainly processes an operating system, a user interface, an application, and the like.
  • the computer device also includes a power source 380 (such as a power adapter) that powers the various components.
  • a power source 380 such as a power adapter
  • the power source can be logically coupled to the processor 370 via a power management system.
  • the method, device and computer device provided by the remote procedure call of the invention can bring at least the following advantages:
  • the present invention provides a remote procedure call method, apparatus, and computer apparatus, the method comprising: registering a name of a pre-agreed remote method and a corresponding asynchronous processing function into a global dictionary; receiving a target call request; Calling a request, determining whether a target asynchronous processing function corresponding to the target call request can be found in the global dictionary; if the target asynchronous processing function can be found in the global dictionary, calling the main thread in the main thread a target asynchronous processing function; determining a data amount of the task to be processed by the asynchronous processing function, allocating a child thread according to the data amount of the to-be-processed task, executing the target asynchronous processing function in the child thread; acquiring the Sending the execution result; in this way, the corresponding sub-thread can be allocated according to the data amount of the target asynchronous processing function to be processed, so that the thread scheduling allocation can be flexibly performed, avoiding the multi-thread conflict causing the program to crash, ensuring the
  • modules in the devices of the embodiments can be adaptively changed and placed in one or more devices different from the embodiment.
  • the modules or units or components of the embodiments may be combined into one module or unit or component, and further they may be divided into a plurality of sub-modules or sub-units or sub-components.
  • any combination of the features disclosed in the specification, including the accompanying claims, the abstract and the drawings, and any methods so disclosed, or All processes or units of the device are combined.
  • Each feature disclosed in this specification (including the accompanying claims, the abstract and the drawings) may be replaced by alternative features that provide the same, equivalent or similar purpose.
  • the various component embodiments of the present invention may be implemented in hardware, or in a software module running on one or more processors, or in a combination thereof.
  • a microprocessor or digital signal processor may be used in practice to implement some or all of the functionality of some, or all, of the gateways, proxy servers, systems in accordance with embodiments of the present invention.
  • DSP digital signal processor
  • the invention can also be implemented as a device or device program (e.g., a computer program and a computer program product) for performing some or all of the methods described herein.
  • Such a program implementing the present invention may be stored on a computer readable storage medium or may be in the form of one or more signals.
  • Such signals may be downloaded from an Internet website, or provided on a carrier signal, or in any other form; when executed by the processor, the program implements the following steps: the name of the pre-agreed remote method and the corresponding asynchronous processing function.
  • the target asynchronous processing function is executed in the thread; the execution result is obtained and transmitted by using the acquisition function.

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 Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明提供了一种远程过程调用的方法、装置及计算机设备,方法包括:将预先预定的远程方法的名称及对应的异步处理函数注册至全局字典中;接收目标调用请求;基于目标调用请求,判断在全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;确定所述异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;利用获取函数获取并发送执行结果;如此,可以根据目标异步处理函数待处理任务的数据量分配相应的子线程,以能灵活地进行线程调度分配,避免造成多线程冲突导致程序崩溃。

Description

一种远程过程调用的方法、装置及计算机设备 技术领域
本发明属于通信技术领域,尤其涉及一种远程过程调用的方法、装置及计算机设备。
背景技术
远程过程调用,就是一个进程调用另外一个进程所提供的方法,适用于进程间的通信。
现有技术中在远程过程调用中,无法灵活地进行线程调度分配,易引起多线程冲突导致程序崩溃问题;而在获取利用某些异步与互斥的方法来解决多线程问题时,又会降低程序性能。
基于此,本发明提供一种远程过程调用的方法、装置及计算机设备,以解决现有技术中的上述问题。
发明内容
针对现有技术存在的问题,本发明实施例提供了一种远程过程调用的方法、装置及计算机设备,用于解决现有技术中,在进行远程过程调用时,无法灵活地进行线程调度分配,易引起多线程冲突导致程序崩溃,导致工作效率下降的技术问题。
本发明提供一种远程过程调用的方法,所述方法包括:
将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;
接收目标调用请求;
基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;
若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;
确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;
利用获取函数获取并发送执行结果。
上述方案中,所述若在所述全局字典中能查找到所述目标异步处理函数,则在主线程中调用所述目标异步处理函数,包括:
获取用于指示网络连接成功后的第一标识符、所述目标调用请求中的参数 信息和所述目标调用请求中的第二标识符;
基于所述参数信息、所述第一标识符及所述第二标识符生成上下文环境块:
将所述第一标识符设置为所述目标异步处理函数的第一个参数,将所述参数信息设置为所述目标异步处理函数的第二个参数,将所述参数列表中的参数个数设置为所述目标异步处理函数的第三个参数,将所述上下文环境块设置为所述目标异步处理函数的第四个参数;
将所述目标异步处理函数投递至主线程中,在主线程中调用所述目标异步处理函数。
上述方案中,所述基于所述参数信息及所述标识符生成上下文环境块,包括:
将所述参数信息赋值给所述上下文环境块的参数字段;
将所述第一标识符赋值给所述上下文环境的第一标识字段;
将所述第二标识符赋值给所述上下文环境块的第二标识字段。
上述方案中,所述利用获取函数获取并发送执行结果,包括:
将第二标识符及所述执行结果序列化为一个网络消息;
将所述网络消息及上下文环境块设置到所述获取函数RpcCompleteAsyncProcedure中的相应参数中;
利用所述获取函数RpcCompleteAsyncProcedure发送所述执行结果。
上述方案中,所述获取并发送执行结果后,还包括:删除上下文环境块。
上述方案中,若在所述全局字典中没有查找到目标异步处理函数,还包括:
返回结果集,所述结果集中包括用于指示无查找结果的指示值。
上述方案中,所述异步处理函数的模型包括:
void(*RpcAsyncProcedure)(void*caller,lRpcArgument**args,intnumArgs,RpcAsyncProcedureContext context);其中,
所述RpcAsyncProcedure为所述异步处理函数的名称,所述caller,lRpcArgument为标识参数;所述args为所述目标调用请求中的参数信息;所述numArgs为所述args参数的个数;所述RpcAsyncProcedureContext为上下文环境块,所述context为用于记录在所述上下文环境块中与当前响应相关联的上下文环境的参数。
本发明还提供一种远程过程调用的装置,所述装置包括:
注册单元,用于将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;
接收单元,用于接收目标调用请求;
判断单元,用于基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;
调用单元,用于在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;
执行单元,用于确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;利用获取函数获取并发送执行结果。
本发明还提供一种计算机可读存储介质,其上存储有计算机程序,该程序被处理器执行时实现以下步骤:
将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;
接收目标调用请求;
基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;
若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;
确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;
利用获取函数获取并发送执行结果。
本发明还提供一种远程过程调用的计算机设备,包括:
至少一个处理器;以及
与所述处理器通信连接的至少一个存储器,其中,
所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行如上述任一所述的方法。
本发明提供了一种远程过程调用的方法、装置及计算机设备,所述方法包括:将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;接收目标调用请求;基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;利用获取函数获取并发送执行结果;如此,可以根据目标异步处理函数待处理任务的数据量分配相应的子线程,以能灵活地进行线程调度分配,避免造成多线程冲突导致程序崩溃,确保了工作效率。
附图说明
通过阅读下文优选实施方式的详细描述,各种其他的优点和益处对于本领域普通技术人员将变得清楚明了。附图仅用于示出优选实施方式的目的,而并不认为是对本发明的限制。而且在整个附图中,用相同的参考符号表示相同的部件。在附图中:
图1为本发明实施例一提供的远程过程调用的方法流程示意图;
图2为本发明实施例二提供的远程过程调用的装置结构示意图;
图3为本发明实施例三提供的远程过程调用的计算机设备的结构示意图。
具体实施方式
下面将参照附图更详细地描述本公开的示例性实施例。虽然附图中显示了本公开的示例性实施例,然而应当理解,可以以各种形式实现本公开而不应被这里阐述的实施例所限制。相反,提供这些实施例是为了能够更透彻地理解本公开,并且能够将本公开的范围完整的传达给本领域的技术人员。
下面通过附图及具体实施例对本发明的技术方案做进一步的详细说明。
实施例一
本实施例提供一种远程过程调用的方法,如图1所示,所述方法包括:
S101,将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;
本步骤中,在接收调用请求之前,需要调用RpcRegisterProcedure函数,将预先约定的远程方法的名称及该远程方法对应的异步处理函数注册至全局字典Dict中,以能在接收到调用请求时,可以直接在全局字典Dict中查找相应的异步处理函数,快速搭建远程过程调用模型,提高处理效率。所述预先约定的远程方法为调用端与被调用端预先约定的。
这里,所述异步处理函数的模型包括:
void(*RpcAsyncProcedure)(void*caller,lRpcArgument**args,intnumArgs,RpcAsyncProcedureContext context);其中,所述RpcAsyncProcedure为所述异步处理函数的名称,所述caller,lRpcArgument为标识参数;所述args为所述目标调用请求中的参数信息;所述numArgs为所述args参数的个数;所述RpcAsyncProcedureContext为上下文环境块,所述context为用于记录在所述上下文环境块中与当前响应相关联的上下文环境的参数。
S102,接收目标调用请求;基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;
本步骤中,将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典Dict中后,接收调用端通过调用RpcCallProcedure函数发送的目标调用请求,基于所述目标调用请求,判断在所述全局字典中是否能查找到所述调用请求对应的目标异步处理函数。
具体地,接收目标调用请求后,也就是接收到RpcMessage消息时,获取远程方法的名称,基于所述名称,判断在所述全局字典中是否能查找到所述调用请求对应的目标异步处理函数。这里,RpcMessage消息中的procedure字段代表要调用的远程方法名,根据该方法名在全局字典Dict中查找目标异步处理函数RpcAsyncProcedure。
S103,若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;
本步骤中,若在所述全局字典中能查找到所述目标异步处理函数RpcAsyncProcedure,在主线程中调用所述目标异步处理函数RpcAsyncProcedure。
首先基于回调函数,获取用于指示网络连接成功后的第一标识符;这里,当调用端与被调用端建立起网络连接后,就生成了第一标识符,来唯一标识这个调用端,所述第一标识符即为session。
然后调用GetRpcArgsFromMessage函数从RpcMessage消息中获取到获取所述目标调用请求中所有的参数信息。具体是通过调用GetRpcArgsFromMessage函数从RpcMessage消息中获取到lRpcArgument结构,然后调用lRpcArgument结构中的参数获取方法i32Value,获取所述目标调用请求中的参数信息。
然后再获取所述目标调用请求中的第二标识符;所述标第二识符是目标调用请求的唯一标识符,用于与其他调用请求进行区分,避免混淆;需要说明的是,每个调用请求都会存在一个唯一的标识符。
具体地,当调用端调用RpcCallProcedure函数向被调用端发送目标调用请求时,会生成第二标识符,并将这个标识符写入RpcMessage消息中gid字段中,当被调用端接收到RpcMessage消息后,即可从gid字段获取所述目标调用请求中的第二标识符。
当获取到参数信息、第一标识符及第二标识符后,基于所述参数信息、所述第一标识符及所述第二标识符生成异步上下文环境块。
具体地,将所述参数信息赋值给所述上下文环境块的参数字段(即arg字段);将所述第一标识符赋值给所述上下文环境的第一标识字段(gid字段);将所述第二标识符赋值给所述上下文环境块的第二标识字段(session字段)。这样就生成了一个异步上下文环境块。
将所述第一标识符设置为所述目标异步处理函数的第一个参数,将所述参数信息设置为所述目标异步处理函数的第二个参数,将所述参数列表中的参数个数设置为所述目标异步处理函数的第三个参数,将所述上下文环境块设置为所述目标异步处理函数的第四个参数;其中,所述第一个参数即为所述caller,lRpcArgument参数;所述第二个为参数args参数;所述第三个参数为所述numArgs参数;所述第四个参数为RpcAsyncProcedureContext参数。
将所述目标异步处理函数投递至主线程中,在主线程中调用所述目标异步处理函数。
S104,确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;利用获取函数获取并发送执行结果。
本步骤中,在主线程调用所述目标异步处理函数时,为了避免目标异步处理函数待处理的数据量过大,引起多线程冲突导致程序崩溃的现象,还要确定所述目标异步处理函数待处理任务的数据量,并根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;其中,所述待处理任务可以包括:访问数据库或计算操作等数据流较大的任务。
当所述目标异步处理函数执行完毕后,为了进一步提高了目标异步处理函数的处理性能,无需在目标异步处理函数中返回执行结果,而需要利用获取函数获取并发送执行结果至调用端。
当获取到执行结果后,将第二标识符及所述执行结果序列化为一个网络消息;具体是调用BuildRpcMessageFrom方法将执行结果的结果集及第二标识符列化为一个网络消息,并将网络消息中的gid字段设置为标识符,将网络消息中的rpcType字段设置为RPC_MESSAGE_RESPONSE值,用于表示该网络消息是一个远程响应消息。
序列化为网络消息后,将所述网络消息及所述上下文环境块设置到所述获取函数RpcCompleteAsyncProcedure中的相应参数中;利用所述获取函数RpcCompleteAsyncProcedure发送所述执行结果。这样就无需在所述异步处理函数返回执行结果,进一步提高了所述异步处理函数的性能。
进一步地,所述获取并发送执行结果后,为了避免资源泄漏,还包括:删除(释放)上下文环境块RpcAsyncProcedureContext。
另外,若在全局字典Dict中没有查找到目标异步处理函数,还包括:返回结果集,所述结果集中包括用于指示无查找结果的指示值,所述指示值的内容为可以ERROR_RPC_NOT_FOUND,用于告知调用端,被调用端没有该远程过程方法。
实施例二
相应于实施例一,本实施例提供一种远程过程调用的装置,如图2所示,所述远程过程调用装置包括:注册单元21、接收单元22、判断单元23、调用单元24及执行单元25;其中,
在接收调用请求之前,所述注册单元21需要调用RpcRegisterProcedure函数,将预先预定的远程方法的名称及该远程方法对应的异步处理函数注册至全局字典Dict中,以能在接收到调用请求时,可以直接在全局字典Dict中查找相应的异步处理函数,快速搭建远程过程调用模型,提高处理效率。所述预先约定的远程方法为调用端与被调用端预先约定的。
这里,所述异步处理函数的模型包括:
void(*RpcAsyncProcedure)(void*caller,lRpcArgument**args,intnumArgs,RpcAsyncProcedureContext context);其中,所述RpcAsyncProcedure为所述异步处理函数的名称,所述caller,lRpcArgument为标识参数;所述args为所述目标调用请求中的参数信息;所述numArgs为所述args参数的个数;所述RpcAsyncProcedureContext为上下文环境块,所述context为用于记录在所述上下文环境块中与当前响应相关联的上下文环境的参数。
所述注册单元21将预先约定的远程方法的名称及对应的远程方法对应的异步处理函数注册至全局字典Dict中后,所述接收单元22接收调用端数发送的目标调用请求,基于所述目标调用请求,判断在所述全局字典中是否能查找到所述调用请求对应的目标异步处理函数。
具体地,所述接收单元22接收目标调用请求后,也就是接收到RpcMessage消息时,所述判断单元23获取远程方法的名称,基于所述名称,判断在所述全局字典中是否能查找到所述调用请求对应的目标异步处理函数。这里,RpcMessage消息中的procedure字段代表要调用的远程方法名,根据该方法名在全局字典Dict中查找目标异步处理函数RpcAsyncProcedure。
若在所述全局字典中能查找到所述目标异步处理函数RpcAsyncProcedure,所述调用单元24用于在主线程中调用所述目标异步处理函数RpcAsyncProcedure。
具体地,所述调用单元24首先基于回调函数,获取用于指示网络连接成功后的第一标识符;这里,当调用端与被调用端建立起网络连接后,就生成了第一标识符,来唯一标识这个调用端,所述第一标识符即为session。
然后所述调用单元24调用GetRpcArgsFromMessage函数从RpcMessage消息中获取到获取所述目标调用请求中所有的参数信息。具体是通过调用 GetRpcArgsFromMessage函数从RpcMessage消息中获取到lRpcArgument结构,然后调用lRpcArgument结构中的参数获取方法i32Value,获取所述目标调用请求中的参数信息。
然后所述调用单元24再获取所述目标调用请求中的第二标识符;所述标第二识符是目标调用请求的唯一标识符,用于与其他调用请求进行区分,避免混淆;需要说明的是,每个调用请求都会存在一个唯一的标识符。
具体地,当调用端调用RpcCallProcedure函数向被调用端发送目标调用请求时,会生成第二标识符,并将这个标识符写入RpcMessage消息中gid字段中,当被调用端接收到RpcMessage消息后,所述调用单元24即可从gid字段获取所述目标调用请求中的第二标识符。
当所述调用单元24获取到参数信息、第一标识符及第二标识符后,基于所述参数信息、所述第一标识符及所述第二标识符生成异步上下文环境块。
具体地,将所述参数信息赋值给所述上下文环境块的参数字段(即arg字段);将所述第一标识符赋值给所述上下文环境的第一标识字段(gid字段);将所述第二标识符赋值给所述上下文环境块的第二标识字段(session字段)。这样就生成了一个异步上下文环境块。
将所述第一标识符设置为所述目标异步处理函数的第一个参数,将所述参数信息设置为所述目标异步处理函数的第二个参数,将所述参数列表中的参数个数设置为所述目标异步处理函数的第三个参数,将所述上下文环境块设置为所述目标异步处理函数的第四个参数;其中,所述第一个参数即为所述caller,lRpcArgument参数;所述第二个参数为args参数;所述第三个参数为所述numArgs参数;所述第四个参数为RpcAsyncProcedureContext参数。
所述调用单元24将所述目标异步处理函数投递至主线程中,在主线程中调用所述目标异步处理函数。
在主线程调用所述目标异步处理函数时,为了避免目标异步处理函数待处理的数据量过大,引起多线程冲突导致程序崩溃的现象,所述执行单元25还要确定所述目标异步处理函数待处理任务的数据量,并根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;其中,所述待处理任务可以包括:访问数据库或计算操作等数据流较大的任务。
当所述目标异步处理函数执行完毕后,为了进一步提高了目标异步处理函数的处理性能,无需在目标异步处理函数中返回执行结果,所述执行单元25需要利用获取函数获取并发送执行结果至调用端。
当获取到执行结果后,所述执行单元25将第二标识符及所述执行结果序列化为一个网络消息;具体是调用BuildRpcMessageFrom方法将执行结果的结果 集及第二标识符列化为一个网络消息,并将网络消息中的gid字段设置为标识符,将网络消息中的rpcType字段设置为RPC_MESSAGE_RESPONSE值,用于表示该网络消息是一个远程响应消息。
序列化为网络消息后,所述执行单元25将所述网络消息及所述上下文环境块设置到所述获取函数RpcCompleteAsyncProcedure中的相应参数中;利用所述获取函数RpcCompleteAsyncProcedure发送所述执行结果。这样就无需在所述异步处理函数返回执行结果,进一步提高了所述异步处理函数的性能。
进一步地,所述获取并发送执行结果后,为了避免资源泄漏,所述执行单元25还用于:删除(释放)上下文环境块RpcAsyncProcedureContext。
另外,若在全局字典Dict中没有查找到目标异步处理函数,所述执行单元25还用于:返回结果集,所述结果集中包括用于指示无查找结果的指示值,所述指示值的内容为可以ERROR_RPC_NOT_FOUND,用于告知调用端,被调用端没有该远程过程方法。
实施例三
实际应用中,利用实施例一提供的调用方法及实施例二提供的调用装置对add远程方法进行调用时,具体实现如下:
被调用端在接收调用请求之前,调用RpcRegisterProcedure函数,将预先预定的add远程方法的名称及对应的异步处理函数注册至全局字典Dict中,以能在接收到调用请求时,可以直接在全局字典Dict中查找add远程方法对应的异步处理函数,快速搭建远程过程调用模型,提高处理效率。
这里,所述异步处理函数的模型包括:
void(*RpcAsyncProcedure)(void*caller,lRpcArgument**args,intnumArgs,RpcAsyncProcedureContext context);其中,所述RpcAsyncProcedure为所述异步处理函数的名称,所述caller,lRpcArgument为标识参数;所述args为所述目标调用请求中的参数信息;所述numArgs为所述args参数的个数;所述RpcAsyncProcedureContext为上下文环境块,所述context为用于记录在所述上下文环境块中与当前响应相关联的上下文环境的参数。比如,在调用add远程方法时,调用端将提供两个参数:第一个参数是数值1,第二个参数是数值2,那么,参数信息即为数值1和数值2,而numArgs的值则为2。
然后,接收调用端通过调用RpcCallProcedure函数发送的调用add远程方法的目标调用请求,基于所述目标调用请求,判断在所述全局字典中是否能查找到所述调用请求对应的目标异步处理函数。
具体地,接收调用端收目标调用请求后,也就是接收到RpcMessage消息时, 获取add远程方法的名称,基于所述名称,判断在所述全局字典中是否能查找到所述调用请求对应的目标异步处理函数。这里,RpcMessage消息中的procedure字段代表要调用的远程方法名,根据该方法名在全局字典Dict中查找目标异步处理函RpcAsyncProcedure。
若在所述全局字典中能查找到所述目标异步处理函数RpcAsyncProcedure,在主线程中调用所述目标异步处理函数RpcAsyncProcedure。
首先基于回调函数,获取用于指示网络连接成功后的第一标识符;这里,当调用端与被调用端建立起网络连接后,就生成了第一标识符,来唯一标识这个调用端,所述第一标识符即为session。
然后调用GetRpcArgsFromMessage函数从RpcMessage消息中获取到获取所述目标调用请求中所有的参数信息。具体是通过调用GetRpcArgsFromMessage函数从RpcMessage消息中获取到lRpcArgument结构,然后调用lRpcArgument结构中的参数获取方法i32Value,利用i32Value方法获取第一个参数与第二参数对应的数值,即args[0]->i32Value()获取的值就是1,args[1]->i32Value()获取的值就是2。
然后再获取所述目标调用请求中的第二标识符;所述标第二识符是add远程方法对应的目标调用请求的唯一标识符,用于与其他调用请求进行区分,避免混淆;需要说明的是,每个调用请求都会存在一个唯一的标识符。
具体地,当调用端调用RpcCallProcedure函数向被调用端发送目标调用请求时,会生成第二标识符,并将这个标识符写入RpcMessage消息中gid字段中,当被调用端接收到RpcMessage消息后,即可从gid字段获取所述目标调用请求中的第二标识符。
当获取到add远程方法中的参数信息、第一标识符及第二标识符后,基于所述参数信息、所述第一标识符及所述第二标识符生成异步上下文环境块。
具体地,将所述参数信息1和2赋值给所述上下文环境块的参数字段(即arg字段);将所述第一标识符赋值给所述上下文环境的第一标识字段(gid字段);将所述第二标识符赋值给所述上下文环境块的第二标识字段(session字段)。这样就生成了一个异步上下文环境块。
将所述第一标识符设置为所述目标异步处理函数的第一个参数,将所述参数信息设置为所述目标异步处理函数的第二个参数,将所述参数列表中的参数个数设置为所述目标异步处理函数的第三个参数,将所述上下文环境块设置为所述目标异步处理函数的第四个参数;其中,所述第一个参数即为所述caller,lRpcArgument参数;所述第二个参数args参数;所述第三个参数为所 述numArgs参数;所述第四个参数为RpcAsyncProcedureContext参数。那么,args参数中第一个参数是数值1,第二个参数是数值2;numArgs参数应为2。
然后将所述目标异步处理函数投递至主线程中,在主线程中调用所述目标异步处理函数。
具体地,在主线程调用所述add远程方法的目标异步处理函数时,为了避免目标异步处理函数待处理的数据量过大,引起多线程冲突导致程序崩溃的现象,还要确定所述目标异步处理函数待处理任务的数据量,并根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;将参数转换为整数内容,即将第一个参数转换为数值1,将第二个参数转换为数值2,然后执行add方法,即执行加法运算得到执行结果,即执行结果为3。其中,所述待处理任务可以包括:访问数据库或计算操作等数据流较大的任务。
为了进一步提高了目标异步处理函数的处理性能,无需在目标异步处理函数中返回执行结果,而需要利用获取函数获取并发送执行结果至调用端。
具体地,将第二标识符及所述执行结果序列化为一个网络消息;具体是调用BuildRpcMessageFrom方法将执行结果的结果集及第二标识符列化为一个网络消息,并将网络消息中的gid字段设置为标识符,将网络消息中的rpcType字段设置为RPC_MESSAGE_RESPONSE值,用于表示该网络消息是一个远程响应消息。
序列化为网络消息后,将所述网络消息及所述上下文环境块设置到所述获取函数RpcCompleteAsyncProcedure中的相应参数中;利用所述获取函数RpcCompleteAsyncProcedure发送所述执行结果。这样就无需在所述异步处理函数返回执行结果,进一步提高了所述异步处理函数的性能。
进一步地,所述获取并发送执行结果后,为了避免资源泄漏,还包括:删除(释放)上下文环境块RpcAsyncProcedureContext。
另外,若在全局字典Dict中没有查找到add远程方法对应的目标异步处理函数,还包括:返回结果集,所述结果集中包括用于指示无查找结果的指示值,所述指示值的内容为可以ERROR_RPC_NOT_FOUND,用于告知调用端,被调用端没有add远程过程方法。
实施例四
本实施例还提供一种远程过程调用的计算机设备,如图3所示,所述计算机设备包括:射频(Radio Frequency,RF)电路310、存储器320、输入单元330、显示单元340、音频电路350、WiFi模块360、处理器370、以及电源380等部件。本领域技术人员可以理解,图3中示出的计算机设备结构并不构成对计算机设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件, 或者不同的部件布置。
下面结合图3对计算机设备的各个构成部件进行具体的介绍:
RF电路310可用于信号的接收和发送,特别地,将基站的下行信息接收后,给处理器370处理。通常,RF电路310包括但不限于至少一个放大器、收发信机、耦合器、低噪声放大器(Low Noise Amplifier,LNA)、双工器等。
存储器320可用于存储软件程序以及模块,处理器370通过运行存储在存储器320的软件程序以及模块,从而执行计算机设备的各种功能应用以及数据处理。存储器320可主要包括存储程序区和存储数据区,其中,存储程序区可存储操作系统、至少一个功能所需的应用程序等;存储数据区可存储根据计算机设备的使用所创建的数据等。此外,存储器320可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件、闪存器件、或其他易失性固态存储器件。
输入单元330可用于接收输入的数字或字符信息,以及产生与计算机设备的用户设置以及功能控制有关的键信号输入。具体地,输入单元330可包括触控面板331以及其他输入设备332。触控面板331,可收集用户在其上的输入操作,并根据预先设定的程式驱动相应的连接装置。触控面板331采集到输出信息后再送给处理器370。除了触控面板331,输入单元330还可以包括其他输入设备332。具体地,其他输入设备332可以包括但不限于触控面板、功能键(比如音量控制按键、开关按键等)、轨迹球、鼠标、操作杆等中的一种或多种。
显示单元340可用于显示由用户输入的信息或提供给用户的信息以及计算机设备的各种菜单。显示单元340可包括显示面板341,可选的,可以采用液晶显示器(Liquid Crystal Display,LCD)、有机发光二极管(Organic Light-Emitting Diode,OLED)等形式来配置显示面板341。进一步的,触控面板331可覆盖显示面板341,当触控面板331检测到在其上或附近的触摸操作后,传送给处理器370以确定触摸事件的类型,随后处理器370根据输入事件的类型在显示面板341上提供相应的视觉输出。虽然在图3中触控面板331与显示面板341是作为两个独立的部件来实现计算机设备的输入和输入功能,但是在某些实施例中,可以将触控面板331与显示面板341集成而实现计算机设备的输入和输出功能。
音频电路350、扬声器351,传声器352可提供用户与计算机设备之间的音频接口。音频电路350可将接收到的音频数据转换后的电信号,传输到扬声器351,由扬声器351转换为声音信号输出;
WiFi属于短距离无线传输技术,计算机设备通过WiFi模块360可以帮助用户收发电子邮件、浏览网页和访问流式媒体等,它为用户提供了无线的宽带互 联网访问。虽然图3示出了WiFi模块360,但是可以理解的是,其并不属于计算机设备的必须构成,完全可以根据需要在不改变发明的本质的范围内而省略。
处理器370是计算机设备的控制中心,利用各种接口和线路连接整个计算机设备的各个部分,通过运行或执行存储在存储器320内的软件程序和/或模块,以及调用存储在存储器320内的数据,执行计算机设备的各种功能和处理数据,从而对计算机设备进行整体监控。可选的,处理器370可包括一个或多个处理单元;优选的,处理器370可集成应用处理器,其中,应用处理器主要处理操作系统、用户界面和应用程序等。
计算机设备还包括给各个部件供电的电源380(比如电源适配器),优选的,电源可以通过电源管理系统与处理器370逻辑相连。
本发明提供的远程过程调用的方法、装置及计算机设备能带来的有益效果至少是:
本发明提供一种远程过程调用的方法、装置及计算机设备,所述方法包括:将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;接收目标调用请求;基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;确定所述异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;利用获取函数获取并发送执行结果;如此,可以根据目标异步处理函数待处理任务的数据量分配相应的子线程,以能灵活地进行线程调度分配,避免造成多线程冲突导致程序崩溃,确保了工作效率;并且无需在异步处理函数中返回执行结果,而是利用获取函数来获取并返回执行结果,这样又进一步提高了程序的性能。
在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。
在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。
类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法 解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。
本领域那些技术人员可以理解,可以对实施例中的设备中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个设备中。可以把实施例中的模块或单元或组件组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者单元中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的的替代特征来代替。
此外,本领域的技术人员能够理解,尽管在此的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在下面的权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。
本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的网关、代理服务器、系统中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读存储介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供;该程序被处理器执行时实现以下步骤:将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;接收目标调用请求;基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;确定所述异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;利用获取函数获取并发送执行结果。
应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并 且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。
以上所述,仅为本发明的较佳实施例而已,并非用于限定本发明的保护范围,凡在本发明的精神和原则之内所作的任何修改、等同替换和改进等,均应包含在本发明的保护范围之内。

Claims (10)

  1. 一种远程过程调用的方法,其特征在于,所述方法包括:
    将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;
    接收目标调用请求;
    基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;
    若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;
    确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;
    利用获取函数获取并发送执行结果。
  2. 如权利要求1所述的方法,其特征在于,所述若在所述全局字典中能查找到所述目标异步处理函数,则在主线程中调用所述目标异步处理函数,包括:
    获取用于指示网络连接成功后的第一标识符、所述目标调用请求中的参数信息和所述目标调用请求中的第二标识符;
    基于所述参数信息、所述第一标识符及所述第二标识符生成上下文环境块;
    将所述第一标识符设置为所述目标异步处理函数的第一个参数,将所述参数信息设置为所述目标异步处理函数的第二个参数,将所述参数列表中的参数个数设置为所述目标异步处理函数的第三个参数,将所述上下文环境块设置为所述目标异步处理函数的第四个参数;
    将所述目标异步处理函数投递至主线程中,在主线程中调用所述目标异步处理函数。
  3. 如权利要求2所述的方法,其特征在于,所述基于所述参数信息及所述标识符生成上下文环境块,包括:
    将所述参数信息赋值给所述上下文环境块的参数字段;
    将所述第一标识符赋值给所述上下文环境的第一标识字段;
    将所述第二标识符赋值给所述上下文环境块的第二标识字段。
  4. 如权利要求1所述的方法,其特征在于,所述利用获取函数获取并发送执行结果,包括:
    将第二标识符及所述执行结果序列化为一个网络消息;
    将所述网络消息及上下文环境块设置到所述获取函数RpcCompleteAsyncProcedure中的相应参数中;
    利用所述获取函数RpcCompleteAsyncProcedure发送所述执行结果。
  5. 如权利要求1所述的方法,其特征在于,所述获取并发送执行结果后,还包括:删除上下文环境块。
  6. 如权利要求1所述的方法,其特征在于,若在所述全局字典中没有查找到目标异步处理函数,还包括:
    返回结果集,所述结果集中包括用于指示无查找结果的指示值。
  7. 如权利要求1或2所述的方法,其特征在于,所述异步处理函数的模型包括:
    void(*RpcAsyncProcedure)(void*caller,IRpcArgument**args,int numArgs,RpcAsyncProcedureContext context);其中,
    所述RpcAsyncProcedure为所述异步处理函数的名称,所述caller,IRpcArgument为标识参数;所述args为所述目标调用请求中的参数信息;所述numArgs为所述args参数的个数;所述RpcAsyncProcedureContext为上下文环境块,所述context为用于记录在所述上下文环境块中与当前响应相关联的上下文环境的参数。
  8. 一种远程过程调用的装置,其特征在于,所述装置包括:
    注册单元,用于将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;
    接收单元,用于接收目标调用请求;
    判断单元,用于基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;
    调用单元,用于在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;
    执行单元,用于确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的数据量分配子线程,在所述子线程中执行所述目标异步处理函数;利用获取函数获取并发送执行结果。
  9. 一种计算机可读存储介质,其上存储有计算机程序,其特征在于,该程序被处理器执行时实现以下步骤:
    将预先约定的远程方法的名称及对应的异步处理函数注册至全局字典中;
    接收目标调用请求;
    基于所述目标调用请求,判断在所述全局字典中是否能查找到所述目标调用请求对应的目标异步处理函数;
    若在所述全局字典中能查找到所述目标异步处理函数,在主线程中调用所述目标异步处理函数;
    确定所述目标异步处理函数待处理任务的数据量,根据所述待处理任务的 数据量分配子线程,在所述子线程中执行所述目标异步处理函数;
    利用获取函数获取并发送执行结果。
  10. 一种远程过程调用的计算机设备,其特征在于,包括:
    至少一个处理器;以及
    与所述处理器通信连接的至少一个存储器,其中,
    所述存储器存储有可被所述处理器执行的程序指令,所述处理器调用所述程序指令能够执行如权利要求1至7任一所述的方法。
PCT/CN2018/082164 2017-06-30 2018-04-08 一种远程过程调用的方法、装置及计算机设备 Ceased WO2019001074A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710523235.2 2017-06-30
CN201710523235.2A CN107277029B (zh) 2017-06-30 2017-06-30 一种远程过程调用的方法、装置及计算机设备

Publications (1)

Publication Number Publication Date
WO2019001074A1 true WO2019001074A1 (zh) 2019-01-03

Family

ID=60071403

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/082164 Ceased WO2019001074A1 (zh) 2017-06-30 2018-04-08 一种远程过程调用的方法、装置及计算机设备

Country Status (2)

Country Link
CN (1) CN107277029B (zh)
WO (1) WO2019001074A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112328410A (zh) * 2020-11-04 2021-02-05 网易(杭州)网络有限公司 远程过程调用的实现方法、装置、设备及存储介质
CN113407363A (zh) * 2021-06-23 2021-09-17 京东科技控股股份有限公司 一种基于远程字典服务的滑窗计数方法及装置
CN113821355A (zh) * 2021-09-06 2021-12-21 长沙博为软件技术股份有限公司 基于Node.js的RPC同步通信方法及设备
CN114584500A (zh) * 2022-02-25 2022-06-03 网易(杭州)网络有限公司 异步通信的测试方法、装置及电子设备

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107277029B (zh) * 2017-06-30 2020-01-03 武汉斗鱼网络科技有限公司 一种远程过程调用的方法、装置及计算机设备
CN108228365B (zh) * 2017-12-28 2021-04-06 杭州马猴烧韭科技有限公司 一种函数请求发送方法、函数请求调用方法及装置
CN108829387B (zh) * 2018-06-07 2021-10-08 中国电子科技集团公司第四十一研究所 一种基于Windows平台的RPC函数生成方法
CN110659139A (zh) * 2018-06-28 2020-01-07 武汉斗鱼网络科技有限公司 一种远程过程调用方法、计算机设备和存储介质
CN110659140B (zh) * 2018-06-30 2022-01-04 武汉斗鱼网络科技有限公司 一种指令执行的方法以及相关设备
CN110659141B (zh) * 2018-06-30 2022-01-04 武汉斗鱼网络科技有限公司 一种指令执行的方法以及相关设备
CN109240834B (zh) * 2018-07-10 2021-01-01 武汉斗鱼网络科技有限公司 一种优化方法、计算机设备和存储介质
CN109408147B (zh) * 2018-10-22 2022-04-19 深圳市元征科技股份有限公司 一种协议确定方法、系统、装置及可读存储介质
CN111385255B (zh) * 2018-12-28 2022-05-06 北京金山云网络技术有限公司 一种异步调用实现方法、装置、服务器及服务器集群
CN115220880B (zh) * 2021-04-15 2025-05-27 网易(杭州)网络有限公司 一种数据处理方法、装置、存储介质及服务器
CN117009104B (zh) * 2023-07-21 2025-11-07 中国电信股份有限公司技术创新中心 异步请求处理方法、装置、计算机设备和存储介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101697139A (zh) * 2009-11-06 2010-04-21 金蝶软件(中国)有限公司 一种远程过程调用方法、装置和注册库
CN105763619A (zh) * 2016-03-31 2016-07-13 广州华多网络科技有限公司 客户端与服务端进行通讯的方法及装置
CN106648940A (zh) * 2017-03-13 2017-05-10 北京百悟科技有限公司 远程过程调用方法及装置
CN106713226A (zh) * 2015-11-12 2017-05-24 卓望数码技术(深圳)有限公司 一种用于分布式系统的远程过程调用处理方法和系统
CN107277029A (zh) * 2017-06-30 2017-10-20 武汉斗鱼网络科技有限公司 一种远程过程调用的方法、装置及计算机设备

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090260023A1 (en) * 2008-04-11 2009-10-15 Hewlett-Parckard Development Commpany, Lp Multiplexing Reserved Ports

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101697139A (zh) * 2009-11-06 2010-04-21 金蝶软件(中国)有限公司 一种远程过程调用方法、装置和注册库
CN106713226A (zh) * 2015-11-12 2017-05-24 卓望数码技术(深圳)有限公司 一种用于分布式系统的远程过程调用处理方法和系统
CN105763619A (zh) * 2016-03-31 2016-07-13 广州华多网络科技有限公司 客户端与服务端进行通讯的方法及装置
CN106648940A (zh) * 2017-03-13 2017-05-10 北京百悟科技有限公司 远程过程调用方法及装置
CN107277029A (zh) * 2017-06-30 2017-10-20 武汉斗鱼网络科技有限公司 一种远程过程调用的方法、装置及计算机设备

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112328410A (zh) * 2020-11-04 2021-02-05 网易(杭州)网络有限公司 远程过程调用的实现方法、装置、设备及存储介质
CN112328410B (zh) * 2020-11-04 2023-08-08 网易(杭州)网络有限公司 远程过程调用的实现方法、装置、设备及存储介质
CN113407363A (zh) * 2021-06-23 2021-09-17 京东科技控股股份有限公司 一种基于远程字典服务的滑窗计数方法及装置
CN113407363B (zh) * 2021-06-23 2024-05-17 京东科技控股股份有限公司 一种基于远程字典服务的滑窗计数方法及装置
CN113821355A (zh) * 2021-09-06 2021-12-21 长沙博为软件技术股份有限公司 基于Node.js的RPC同步通信方法及设备
CN114584500A (zh) * 2022-02-25 2022-06-03 网易(杭州)网络有限公司 异步通信的测试方法、装置及电子设备
CN114584500B (zh) * 2022-02-25 2024-03-22 网易(杭州)网络有限公司 异步通信的测试方法、装置及电子设备

Also Published As

Publication number Publication date
CN107277029B (zh) 2020-01-03
CN107277029A (zh) 2017-10-20

Similar Documents

Publication Publication Date Title
WO2019001074A1 (zh) 一种远程过程调用的方法、装置及计算机设备
CN110268751B (zh) 用于在接入网环境中选择接入和移动性管理功能的方法和系统
CN116018788A (zh) 为动态发现的对等体或网络功能配置服务网格联网资源
US10579442B2 (en) Inversion-of-control component service models for virtual environments
CN110753129A (zh) 消息传输方法、系统、装置、设备及计算机可读存储介质
WO2021013056A1 (zh) 基于微服务的数据处理方法、装置、设备及可读存储介质
WO2017096909A1 (zh) 建立数据连接的方法及装置
CN113645259B (zh) 微服务弹性伸缩方法、系统及相关设备
CN110933075B (zh) 服务调用方法、装置、电子设备及存储介质
WO2019001073A1 (zh) 一种远程过程调用的方法、装置及计算机设备
WO2019205555A1 (zh) 消息推送方法及装置
CN106775952B (zh) 一种安卓应用的进程管理方法和装置
CN111200606A (zh) 深度学习模型任务处理方法、系统、服务器及存储介质
WO2018086454A1 (zh) 页面数据处理方法和装置
WO2015062234A1 (zh) 移动终端资源处理方法、装置和设备
JP2005228183A (ja) プログラム実行方法、および、プログラム実行のための計算機システム
WO2017166093A1 (zh) 前置系统
CN112732548B (zh) 一种接口测试方法以及装置
WO2019134288A1 (zh) 一种用于实现视图控制器的方法、装置及计算机设备
CN114189436B (zh) 一种多集群配置部署方法、装置、电子设备和存储介质
CN108874381B (zh) 一种输出页面视图控制器的方法、装置及电子设备
CN112799857A (zh) 一种应用访问方法以及装置
CN117194068A (zh) 一种跨进程数据传输方法、系统、设备及存储介质
CN112468952B (zh) 定位方法、装置、存储介质及电子设备
CN109426572B (zh) 任务处理方法、装置及电子设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 18822951

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 18822951

Country of ref document: EP

Kind code of ref document: A1