CN117009104A - Asynchronous request processing method, device, computer equipment and storage medium - Google Patents

Asynchronous request processing method, device, computer equipment and storage medium Download PDF

Info

Publication number
CN117009104A
CN117009104A CN202310904143.4A CN202310904143A CN117009104A CN 117009104 A CN117009104 A CN 117009104A CN 202310904143 A CN202310904143 A CN 202310904143A CN 117009104 A CN117009104 A CN 117009104A
Authority
CN
China
Prior art keywords
processed
asynchronous request
target
request
asynchronous
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.)
Pending
Application number
CN202310904143.4A
Other languages
Chinese (zh)
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.)
China Telecom Technology Innovation Center
China Telecom Corp Ltd
Original Assignee
China Telecom Technology Innovation Center
China Telecom Corp 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 China Telecom Technology Innovation Center, China Telecom Corp Ltd filed Critical China Telecom Technology Innovation Center
Priority to CN202310904143.4A priority Critical patent/CN117009104A/en
Publication of CN117009104A publication Critical patent/CN117009104A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The present application relates to an asynchronous request processing method, an asynchronous request processing device, a computer device, a storage medium and a computer program product. The method comprises the following steps: acquiring an asynchronous request to be processed and a target callback function corresponding to a target object; under the condition that the asynchronous request to be processed is in a ready state, determining a target method corresponding to the asynchronous request to be processed based on a preset configuration template and the asynchronous request to be processed; processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed; and sending the processing result to the target object based on the target callback function. The method can improve the processing efficiency of the asynchronous request.

Description

Asynchronous request processing method, device, computer equipment and storage medium
Technical Field
The present application relates to the field of computer technology, and in particular, to an asynchronous request processing method, an asynchronous request processing apparatus, a computer device, a storage medium, and a computer program product.
Background
When the server receives the request sent by the sending end, the request is processed by calling a method corresponding to the request, a processing result corresponding to the request is obtained, and the processing result is sent to the sending end, so that the response of the server to the request is realized.
In the conventional technology, a server determines a method for processing a request through multi-layer judgment, and the judgment process takes a relatively long time, so that the processing efficiency of the request is low.
Disclosure of Invention
In view of the foregoing, it is desirable to provide an asynchronous request processing method, apparatus, computer device, computer readable storage medium, and computer program product that can improve the processing efficiency of asynchronous requests.
In a first aspect, the present application provides a method for processing an asynchronous request. The method comprises the following steps:
acquiring an asynchronous request to be processed and a target callback function corresponding to a target object;
determining a target method corresponding to the asynchronous request to be processed based on a preset configuration template and the asynchronous request to be processed under the condition that the asynchronous request to be processed is in a ready state;
processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed;
and based on the target callback function, sending the processing result to the target object.
In one embodiment, the preset configuration template includes a correspondence between paths and methods; the target method for determining the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed comprises the following steps:
Acquiring a target path from a request address of the asynchronous request to be processed;
and determining a method corresponding to the target path in the preset configuration template as a target method corresponding to the asynchronous request to be processed.
In one embodiment, the processing the to-be-processed asynchronous request based on the target method, to obtain a processing result corresponding to the to-be-processed asynchronous request includes:
acquiring a request parameter set corresponding to the asynchronous request to be processed;
and calling the target method to process the request parameter set to obtain a processing result corresponding to the asynchronous request to be processed.
In one embodiment, before determining the target method corresponding to the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed when the asynchronous request to be processed is in the ready state, the method further includes:
establishing and registering a target network connection channel corresponding to the asynchronous request to be processed;
acquiring an event state corresponding to the asynchronous request to be processed through the target network connection channel;
and when the event state corresponding to the asynchronous request to be processed is a preset event state, determining that the asynchronous request to be processed is in a ready state.
In one embodiment, the establishing and registering the target network connection channel corresponding to the pending asynchronous request includes:
storing the asynchronous request to be processed in a waiting queue;
when the to-be-processed asynchronous request is the head of the queue in the waiting queue, generating a target network connection channel corresponding to the to-be-processed asynchronous request;
registering the target network connection channel on a target monitor; the target monitor is used for acquiring an event state corresponding to the asynchronous request to be processed through the target network connection channel.
In one embodiment, before determining the target method corresponding to the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed when the asynchronous request to be processed is in the ready state, the method further includes:
determining a target thread corresponding to the asynchronous request to be processed;
and storing the to-be-processed asynchronous request in a target queue corresponding to the target thread.
In one embodiment, the processing the to-be-processed asynchronous request based on the target method, to obtain a processing result corresponding to the to-be-processed asynchronous request includes:
and calling the target method through the target thread, and processing the request parameter set of the asynchronous request to be processed to obtain a processing result corresponding to the asynchronous request to be processed.
In a second aspect, the application further provides an asynchronous request processing device. The device comprises:
the acquisition module is used for acquiring the asynchronous request to be processed and the target callback function corresponding to the target object;
the determining module is used for determining a target method corresponding to the asynchronous request to be processed based on a preset configuration template and the asynchronous request to be processed under the condition that the asynchronous request to be processed is in a ready state;
the processing module is used for processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed;
and the callback module is used for sending the processing result to the target object based on the target callback function.
In a third aspect, the present application also provides a computer device comprising a memory storing a computer program and a processor implementing the steps of the method of any one of the first aspects when the computer program is executed by the processor.
In a fourth aspect, the present application also provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method of any of the first aspects.
In a fifth aspect, the application also provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the method of any of the first aspects.
The method, the device, the computer equipment, the storage medium and the computer program product for processing the asynchronous request acquire the to-be-processed asynchronous request and the target callback function corresponding to the target object, determine the target method corresponding to the to-be-processed asynchronous request based on the preset configuration template and the to-be-processed asynchronous request under the condition that the to-be-processed asynchronous request is in a ready state, process the to-be-processed asynchronous request based on the target method to acquire a processing result corresponding to the to-be-processed asynchronous request, and send the processing result to the target object based on the target callback function. Under the condition that the asynchronous request to be processed is in a ready state, a target method corresponding to the asynchronous request to be processed is determined through a corresponding relation in a preset configuration template, compared with multi-layer judgment, the method has the advantages that the time length determined by the target method is shortened, the target method is called to process the asynchronous request to be processed, a processing result corresponding to the asynchronous request to be processed is obtained, and the processing result is sent to a target object through a target callback function, so that the processing efficiency of the asynchronous request to be processed is improved.
Drawings
FIG. 1 is an application environment diagram of an asynchronous request processing method in one embodiment;
FIG. 2 is a flow diagram of an asynchronous request processing method in one embodiment;
FIG. 3 is a flow chart of a ready state determination step in one embodiment;
FIG. 4 is a flowchart illustrating a target network connection channel registration procedure in one embodiment;
FIG. 5 is a schematic diagram of an asynchronous request processing system in one embodiment;
FIG. 6 is a schematic diagram of an injection module in one embodiment;
FIG. 7 is a block diagram of an asynchronous request processing device in one embodiment;
fig. 8 is an internal structural diagram of a computer device in one embodiment.
Detailed Description
The present application will be described in further detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present application more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the application.
The asynchronous request processing method provided by the embodiment of the application can be applied to an application environment shown in figure 1. Wherein the terminal 102 communicates with the server 104 via a network. The data storage system may store data that the server 104 needs to process. The data storage system may be integrated on the server 104 or may be located on a cloud or other network server. Both the terminal and the server can be used separately to execute the asynchronous request processing method provided in the embodiment of the application. The terminal and the server may also cooperate to perform the asynchronous request processing method provided in the embodiments of the present application. For example, the server acquires a to-be-processed asynchronous request and a target callback function corresponding to the target object, determines a target method corresponding to the to-be-processed asynchronous request based on a preset configuration template and the to-be-processed asynchronous request under the condition that the to-be-processed asynchronous request is in a ready state, processes the to-be-processed asynchronous request based on the target method to obtain a processing result corresponding to the to-be-processed asynchronous request, and sends the processing result to the target object based on the target callback function. The terminal 102 may be, but not limited to, various personal computers, notebook computers, smart phones, tablet computers, internet of things devices, and portable wearable devices, where the internet of things devices may be smart speakers, smart televisions, smart air conditioners, smart vehicle devices, and the like. The portable wearable device may be a smart watch, smart bracelet, headset, or the like. The server 104 may be implemented as a stand-alone server or as a server cluster of multiple servers.
In one embodiment, as shown in fig. 2, an asynchronous request processing method is provided, and this embodiment is described by taking the application of the method to a server as an example, and includes steps 202 to 208.
Step 202, obtaining a to-be-processed asynchronous request and a target callback function corresponding to a target object.
The target object refers to a device for sending an asynchronous request to be processed, and can be understood as a sending end of the asynchronous request to be processed. The target object may be, but is not limited to, a terminal, a computer device, a server, etc. Asynchronous requests refer to asynchronous requests whose transmission and processing does not block the thread or process that originated the request, it being understood that asynchronous requests allow the target object to continue to perform other operations after the pending asynchronous request is transmitted, as opposed to synchronous requests, without having to wait for the completion of the pending asynchronous request. The callback function refers to a function that sends an asynchronous request to be processed to the target object.
Illustratively, the target object sends the pending asynchronous request and the target callback function to the server, which receives the pending asynchronous request and the target callback function.
Step 204, determining a target method corresponding to the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed under the condition that the asynchronous request to be processed is in a ready state.
The ready state refers to a state when an event state corresponding to the asynchronous request to be processed changes, and can be understood as a state that the asynchronous request to be processed is ready to be processed. The ready state includes, but is not limited to, the event state being one of a ready to connect, a ready to read, a ready to write, and a ready to receive. The preset configuration template refers to a preset configuration template, and the preset configuration template includes a plurality of groups of corresponding relations between the method and the request address, for example, the corresponding relation between the request address and the method or the corresponding relation between the path and the method. A method refers to a piece of code in a class or object that performs a particular task, and it is understood that the method defines a series of statements for performing a particular function. The method can be an instance method and a class method, the instance method belongs to an object, only the object of which the class is created can call the instance method, the class method belongs to the class itself, the class method is not dependent on the object of the class, the class method can be directly called through the class name, and the instance of the class is not required to be created.
The server acquires an event state corresponding to the asynchronous request to be processed through the registration and monitoring module, judges the event state corresponding to the asynchronous request to be processed, acquires a preset configuration template when the asynchronous request to be processed is in a ready state, determines a target method corresponding to the asynchronous request to be processed from the preset configuration template, repeatedly executes the event state corresponding to the asynchronous request to be processed when the asynchronous request to be processed is in a non-ready state, and judges the event state corresponding to the asynchronous request to be processed until the asynchronous request to be processed is in the ready state.
And 206, processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed.
The processing result refers to a result obtained after the server processes the asynchronous request to be processed, and can be a result of calculation, operation and inquiry, and the result is determined according to service logic and requirements of the asynchronous request to be processed.
The server calls a target method to process the asynchronous request to be processed, and a processing result corresponding to the asynchronous request to be processed is obtained.
And step 208, transmitting the processing result to the target object based on the target callback function.
The server, after obtaining the processing result of the asynchronous request to be processed, sends the processing result to the target object through the target callback function.
In the above method for processing an asynchronous request, a to-be-processed asynchronous request and a target callback function corresponding to a target object are obtained, a target method corresponding to the to-be-processed asynchronous request is determined based on a preset configuration template and the to-be-processed asynchronous request under the condition that the to-be-processed asynchronous request is in a ready state, the to-be-processed asynchronous request is processed based on the target method, a processing result corresponding to the to-be-processed asynchronous request is obtained, and the processing result is sent to the target object based on the target callback function. Under the condition that the asynchronous request to be processed is in a ready state, a target method corresponding to the asynchronous request to be processed is determined through a corresponding relation in a preset configuration template, compared with multi-layer judgment, the method has the advantages that the time length determined by the target method is shortened, the target method is called to process the asynchronous request to be processed, a processing result corresponding to the asynchronous request to be processed is obtained, and the processing result is sent to a target object through a target callback function, so that the processing efficiency of the asynchronous request to be processed is improved.
In one embodiment, the preset configuration template includes a correspondence between paths and methods; based on a preset configuration template and the asynchronous request to be processed, the target method for determining the corresponding asynchronous request to be processed comprises the following steps:
acquiring a target path from a request address of an asynchronous request to be processed; and determining a method corresponding to the target path in the preset configuration template as a target method corresponding to the asynchronous request to be processed.
The request address refers to a complete URL (Uniform Resource Locator ) used when the target object initiates an asynchronous request to be processed, and includes components such as a protocol, a domain name or IP (Internet Protocol ) address, a port number, a path, and a query parameter, which are used to uniquely identify the location of the target object on the network. The path refers to the part of the request address, which is left after removing the protocol, domain name, port number and query parameters, i.e. the relative path of the asynchronous request to be processed, and represents the resource position of the asynchronous request to be processed on the server.
The server obtains a request address from the to-be-processed asynchronous request, obtains a target path from the request address, and determines a method corresponding to the target path in a preset configuration template as a target method corresponding to the to-be-processed asynchronous request.
In one embodiment, the preset configuration template includes a correspondence between paths and class methods, the server obtains a request address from the asynchronous request to be processed, obtains a target path from the request address, and determines the class method corresponding to the target path in the preset configuration template as the target class method corresponding to the asynchronous request to be processed. For example, the target class method is a controller1/method1, where controller1 is a class and method1 is one of the methods of controller 1.
In this embodiment, through presetting the correspondence between the paths and the methods in the configuration template, the target method corresponding to the asynchronous request to be processed is determined according to the target path in the asynchronous request to be processed, and compared with performing multi-layer judgment, the method shortens the time period determined by the target method, thereby improving the processing efficiency of the asynchronous request to be processed.
In one embodiment, processing an asynchronous request to be processed based on a target method, and obtaining a processing result corresponding to the asynchronous request to be processed includes:
acquiring a request parameter set corresponding to an asynchronous request to be processed; and calling a target method to process the request parameter set to obtain a processing result corresponding to the asynchronous request to be processed.
The request parameter set refers to a set formed by a plurality of request parameters of an asynchronous request to be processed. The request parameter set includes, but is not limited to, a request address, a request header, and a request body, wherein the request header refers to a set of key value pairs for transmitting additional information about a request, and the request body refers to main body data for transmitting the request.
The server obtains a request parameter set corresponding to the asynchronous request to be processed after determining a target method corresponding to the asynchronous request to be processed, and according to the actual setting condition of input parameters of the target method, at least one request parameter in the request parameter set is input into the target method as the input parameter, and the target method is operated to obtain a processing result corresponding to the asynchronous request to be processed.
In this embodiment, the server invokes the target method corresponding to the to-be-processed asynchronous request, and processes the request parameter set to obtain a processing result corresponding to the to-be-processed asynchronous request, thereby implementing the processing of the to-be-processed asynchronous request by the server.
In one embodiment, as shown in fig. 3, before determining the target method corresponding to the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed in the case that the asynchronous request to be processed is in a ready state, the method further includes:
Step 302, a target network connection channel corresponding to the register pending asynchronous request is established.
The network connection Channel refers to a Channel for network communication, provides a function of performing network communication through a TCP (Transmission Control Protocol ) protocol, and may be a Socket Channel in JAVA.
The server receives the asynchronous request to be processed, stores the asynchronous request to be processed in a waiting queue, establishes a target network connection channel corresponding to the asynchronous request to be processed when the asynchronous request to be processed is the head of the waiting queue, binds the asynchronous request to be processed with the target network connection channel, and registers the target network connection channel on the target monitor. Wherein the target listener allows a thread to simultaneously listen for events on multiple network connection channels, and the thread is notified when an event on any one of the network connection channels changes.
Step 304, obtaining an event state corresponding to the asynchronous request to be processed through the target network connection channel.
The event state refers to a state of an I/O (Input/Output) event on a target network connection channel corresponding to an asynchronous request to be processed, and is used to indicate whether the target network connection channel has a certain I/O operation condition at a certain moment. Event states include, but are not limited to, unconnected state, connected ready state, unreadable state, readable ready state, unwritable state, writable ready state, unconnected state, and received ready state, etc.
The target monitor of the server polls the registered network connection channel, acquires the event state of the target network connection channel, and determines the event state of the target network connection channel as the event state corresponding to the asynchronous request to be processed.
In one embodiment, a target monitor of the server acquires an event state of a target network connection channel based on a preset time interval, and determines the event state of the target network connection channel as an event state corresponding to an asynchronous request to be processed.
Step 306, determining that the asynchronous request to be processed is in a ready state when the event state corresponding to the asynchronous request to be processed is a preset event state.
The preset event state refers to a preset event state set, and the preset event state includes a connection ready state, a readable ready state, a writable ready state and a receiving ready state.
The server compares an event state corresponding to the asynchronous request to be processed with a preset event state, and determines that the asynchronous request to be processed is in a ready state when the event state corresponding to the asynchronous request to be processed is one of the preset event states.
In one embodiment, when the state of an event corresponding to the asynchronous request to be processed changes, the asynchronous request to be processed is determined to be in a ready state, wherein the change refers to the change of the state of the event from an unconnected state to a connected ready state, from an unreadable state to a readable ready state, from an unwritable state to a writable ready state and from an unacceptable connected state to a ready state.
In this embodiment, the server determines, by acquiring an event state of a target network connection channel corresponding to the to-be-processed asynchronous request, an event state corresponding to the to-be-processed asynchronous request according to the event state of the target network connection channel, and determines that the to-be-processed asynchronous request is in a ready state when the event state corresponding to the to-be-processed asynchronous request is a preset event state, and processes the to-be-processed asynchronous request when the to-be-processed asynchronous request is in the ready state, thereby avoiding that the to-be-processed asynchronous request is in a waiting state for a long time, and improving processing efficiency of the asynchronous request.
In one embodiment, as shown in fig. 4, establishing and registering a target network connection channel corresponding to an asynchronous request to be processed includes:
step 402, store pending asynchronous request in a wait queue.
The waiting queue is a queue for storing the to-be-processed asynchronous requests, the queue is a first-in first-out data structure, and it can be understood that the server receives a plurality of to-be-processed asynchronous requests, stores the plurality of to-be-processed asynchronous requests in the waiting queue before any processing is performed on the to-be-processed asynchronous requests, and then processes the plurality of to-be-processed asynchronous requests in sequence according to the arrangement sequence of the to-be-processed asynchronous requests in the waiting queue, and the server can store the to-be-processed asynchronous requests in the waiting queue based on the priority and the receiving time of the to-be-processed asynchronous requests.
Illustratively, the server, after receiving the pending asynchronous request, stores the pending asynchronous request in a wait queue.
And step 404, when the to-be-processed asynchronous request is the head of the queue in the waiting queue, generating a target network connection channel corresponding to the to-be-processed asynchronous request.
Where the head of the queue refers to the first element in the queue.
The server processes the asynchronous requests in the waiting queue in turn, and generates a target network connection channel corresponding to the asynchronous requests to be processed when the asynchronous requests to be processed are the head of the waiting queue.
Step 406, registering the target network connection channel on the target monitor; the target monitor is used for acquiring an event state corresponding to the asynchronous request to be processed through the target network connection channel.
The target monitor is a registration and monitoring module in the allocation module, and is configured to monitor event states of registered network connection channels.
Illustratively, the server registers the target network connection channel on the target listener.
In one embodiment, the server obtains the target listener, sets the target network connection channel to a non-blocking mode, invokes a register (Selector selector, int internestops, object attachment) method of the network connection channel, and registers the target network connection channel with the target listener. Wherein register is a registration method, selector is a Selector, selector parameter is a target monitor to be registered, int is integer data, interstaops parameter is a registered event type, object is a base class of class in Java, which represents a type of any Object, and attribute parameter is an optional additional Object which can be used for transferring additional information.
In this embodiment, by registering the target network connection channel on the target listener, an implementation basis is provided for determining the event state of the pending asynchronous request subsequently.
In one embodiment, in the case that the asynchronous request to be processed is in a ready state, before determining the target method corresponding to the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed, the method further includes:
determining a target thread corresponding to the asynchronous request to be processed; and storing the asynchronous request to be processed in a target queue corresponding to the target thread.
The thread is the minimum unit of the computer operating system capable of carrying out operation scheduling, is an execution flow in the process, and can independently run and be scheduled. The target queue refers to a task queue for storing pending asynchronous requests to be processed by the target thread, and it is understood that the target thread processes the pending asynchronous requests in the target queue.
The server determines a target thread corresponding to the asynchronous request to be processed based on a preset allocation mode, and then stores the asynchronous request to be processed in a target queue corresponding to the target thread.
In one embodiment, the server determines a target thread pool corresponding to the asynchronous request to be processed based on a preset allocation mode, and stores the asynchronous request to be processed in a target queue corresponding to the target thread pool.
In this embodiment, by determining the target thread corresponding to the to-be-processed asynchronous request, and storing the to-be-processed asynchronous request in the target queue corresponding to the target thread, it may be understood that the target thread only processes the asynchronous request in the target queue, thereby shortening the waiting time of the to-be-processed asynchronous request, and improving the processing efficiency of the to-be-processed asynchronous request.
In one embodiment, processing an asynchronous request to be processed based on a target method, and obtaining a processing result corresponding to the asynchronous request to be processed includes:
and calling a target method by a target thread, and processing a request parameter set of the asynchronous request to be processed to obtain a processing result corresponding to the asynchronous request to be processed.
The server calls a target method through a target thread, and inputs a request parameter set of the asynchronous request to be processed into the target method as an input parameter, and operates the target method to obtain a processing result corresponding to the asynchronous request to be processed.
In this embodiment, the target thread processes the asynchronous request to be processed, so as to shorten the waiting time of the asynchronous request to be processed, thereby improving the processing efficiency of the asynchronous request to be processed.
In one exemplary embodiment, as shown in FIG. 5, an asynchronous request processing system is provided that includes a boot module, a receiving module, a network communication module, an allocation module, an auto-inject module, and an execute module. The system comprises a Server boot strap, a boot module (Server boot strap), a boot module and a boot module, wherein the boot module (Server boot strap) is used for booting and configuring the starting of a Server program, is responsible for setting basic parameters of the Server and managing the whole starting process; the receiving module (Boss Group) is used for receiving connection establishment request events, namely, monitoring ports of the monitoring server, when new connection requests arrive, the receiving module receives and processes the requests, and the receiving module does not directly process the read-write operation of the requests, but distributes the connection requests to the distribution module for further processing; a network communication module (Channel) for performing asynchronous network I/O operations; the distribution module (workbench Group) is used for distributing thread processing requests, namely, processing actual read-write operations, and when connection establishment is completed, the receiving module distributes the connection requests to threads in the distribution module for processing; the automatic injection module is used for acquiring the request parameters and automatically injecting the request parameters into the execution module; the executing module (Handler) is used for executing specific business logic, such as read-write data, encoding and decoding, and the like, and obtains the required parameters through the automatic injection module and processes according to specific business requirements.
The automatic injection module is shown in fig. 6 and comprises a configuration module, a searching matching module and an injection module. The configuration module is used for configuring parameters required by the request class, including a request address, a request head, a request body and the like; the searching and matching module is used for matching the method required by the asynchronous request to be processed; the injection module is used for injecting the matched method into the execution module.
The method comprises the steps that a sending end sends an asynchronous request to be processed and a target callback function to a server, the server receives the asynchronous request to be processed and the target callback function, a receiving module stores the asynchronous request to be processed in a waiting queue, when the asynchronous request to be processed is the head of the queue in the waiting queue, a target network connection channel corresponding to the asynchronous request to be processed is generated, a network communication module registers the target network connection channel on a distribution module, a monitoring and registering module in the distribution module polls the registered network connection channel to obtain an event state of the target network connection channel, the event state of the target network connection channel is determined to be the event state corresponding to the asynchronous request to be processed, and when the event state corresponding to the asynchronous request to be processed changes, the asynchronous request to be processed is determined to be in a ready state.
When the allocation module determines that the asynchronous request to be processed is in a ready state, an automatic injection module is called, a configuration module in the automatic injection module acquires a request parameter set corresponding to the asynchronous request to be processed, the request parameter set comprises a request address, a request head and a request body, a target path is acquired from the request address, a search matching module acquires a preset configuration template, a method corresponding to the target path in the preset configuration template is determined to be a target method corresponding to the asynchronous request to be processed, and the injection module injects the request parameter set and the target method into an execution module.
The execution module calls a target method, the request parameter set is used as an input parameter to be input into the target method, the target method is operated to obtain a processing result corresponding to the asynchronous request to be processed, the execution module transmits the processing result to the network communication module, and the network communication module calls a target callback function to send the processing result to the sending end.
In the above method for processing an asynchronous request, a to-be-processed asynchronous request and a target callback function corresponding to a target object are obtained, a target method corresponding to the to-be-processed asynchronous request is determined based on a preset configuration template and the to-be-processed asynchronous request under the condition that the to-be-processed asynchronous request is in a ready state, the to-be-processed asynchronous request is processed based on the target method, a processing result corresponding to the to-be-processed asynchronous request is obtained, and the processing result is sent to the target object based on the target callback function. Under the condition that the asynchronous request to be processed is in a ready state, a target method corresponding to the asynchronous request to be processed is determined through a corresponding relation in a preset configuration template, compared with multi-layer judgment, the method has the advantages that the time length determined by the target method is shortened, the target method is called to process the asynchronous request to be processed, a processing result corresponding to the asynchronous request to be processed is obtained, and the processing result is sent to a target object through a target callback function, so that the processing efficiency of the asynchronous request to be processed is improved.
It should be understood that, although the steps in the flowcharts related to the embodiments described above are sequentially shown as indicated by arrows, these steps are not necessarily sequentially performed in the order indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least some of the steps in the flowcharts described in the above embodiments may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of the steps or stages is not necessarily performed sequentially, but may be performed alternately or alternately with at least some of the other steps or stages.
Based on the same inventive concept, the embodiment of the application also provides an asynchronous request processing device for realizing the above related asynchronous request processing method. The implementation of the solution provided by the device is similar to the implementation described in the above method, so the specific limitation in one or more embodiments of the asynchronous request processing device provided below may refer to the limitation of the asynchronous request processing method hereinabove, and will not be repeated herein.
In one embodiment, as shown in fig. 7, there is provided an asynchronous request processing apparatus, comprising: an acquisition module 702, a determination module 704, a processing module 706, and a callback module 708, wherein:
an obtaining module 702, configured to obtain a pending asynchronous request and a target callback function corresponding to a target object;
a determining module 704, configured to determine, based on a preset configuration template and the asynchronous request to be processed, a target method corresponding to the asynchronous request to be processed when the asynchronous request to be processed is in a ready state;
the processing module 706 is configured to process the asynchronous request to be processed based on a target method, so as to obtain a processing result corresponding to the asynchronous request to be processed;
and the callback module 708 is used for sending the processing result to the target object based on the target callback function.
In one embodiment, the determining module 704 is further configured to: acquiring a target path from a request address of an asynchronous request to be processed; and determining a method corresponding to the target path in the preset configuration template as a target method corresponding to the asynchronous request to be processed.
In one embodiment, the processing module 706 is further to: acquiring a request parameter set corresponding to an asynchronous request to be processed; and calling a target method to process the request parameter set to obtain a processing result corresponding to the asynchronous request to be processed.
In one embodiment, the asynchronous request processing apparatus further comprises a monitoring module for: establishing and registering a target network connection channel corresponding to the to-be-processed asynchronous request; acquiring an event state corresponding to the asynchronous request to be processed through a target network connection channel; and when the event state corresponding to the asynchronous request to be processed is a preset event state, determining that the asynchronous request to be processed is in a ready state.
In one embodiment, the monitoring module is further configured to: storing the asynchronous request to be processed in a waiting queue; when the to-be-processed asynchronous request is the head of a queue in the waiting queue, generating a target network connection channel corresponding to the to-be-processed asynchronous request; registering the target network connection channel on the target monitor; the target monitor is used for acquiring an event state corresponding to the asynchronous request to be processed through the target network connection channel.
In one embodiment, the asynchronous request processing apparatus further comprises a storage module for: determining a target thread corresponding to the asynchronous request to be processed; and storing the asynchronous request to be processed in a target queue corresponding to the target thread.
In one embodiment, the processing module 706 is further to: and calling a target method by a target thread, and processing a request parameter set of the asynchronous request to be processed to obtain a processing result corresponding to the asynchronous request to be processed.
The various modules in the asynchronous request processing apparatus described above may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above modules.
In one embodiment, a computer device is provided, which may be a terminal, and the internal structure thereof may be as shown in fig. 8. The computer device includes a processor, a memory, an input/output interface, a communication interface, a display unit, and an input means. The processor, the memory and the input/output interface are connected through a system bus, and the communication interface, the display unit and the input device are connected to the system bus through the input/output interface. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The input/output interface of the computer device is used to exchange information between the processor and the external device. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless mode can be realized through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement an asynchronous request processing method. The display unit of the computer device is used for forming a visual picture, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, can also be a key, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the structure shown in FIG. 8 is merely a block diagram of some of the structures associated with the present inventive arrangements and is not limiting of the computer device to which the present inventive arrangements may be applied, and that a particular computer device may include more or fewer components than shown, or may combine some of the components, or have a different arrangement of components.
In one embodiment, a computer device is provided, comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method embodiments described above when the computer program is executed.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, carries out the steps of the method embodiments described above.
In an embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the steps of the method embodiments described above.
The user information (including but not limited to user equipment information, user personal information, etc.) and the data (including but not limited to data for analysis, stored data, presented data, etc.) related to the present application are information and data authorized by the user or sufficiently authorized by each party.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile Memory may include Read-Only Memory (ROM), magnetic tape, floppy disk, flash Memory, optical Memory, high density embedded nonvolatile Memory, resistive random access Memory (ReRAM), magnetic random access Memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric Memory (Ferroelectric Random Access Memory, FRAM), phase change Memory (Phase Change Memory, PCM), graphene Memory, and the like. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, and the like. By way of illustration, and not limitation, RAM can be in the form of a variety of forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), and the like. The databases referred to in the embodiments provided herein may include at least one of a relational database and a non-relational database. The non-relational database may include, but is not limited to, a blockchain-based distributed database, and the like. The processor referred to in the embodiments provided in the present application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic unit, a data processing logic unit based on quantum computing, or the like, but is not limited thereto.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The foregoing examples illustrate only a few embodiments of the application and are described in detail herein without thereby limiting the scope of the application. It should be noted that it will be apparent to those skilled in the art that several variations and modifications can be made without departing from the spirit of the application, which are all within the scope of the application. Accordingly, the scope of the application should be assessed as that of the appended claims.

Claims (10)

1. A method of asynchronous request processing, the method comprising:
acquiring an asynchronous request to be processed and a target callback function corresponding to a target object;
determining a target method corresponding to the asynchronous request to be processed based on a preset configuration template and the asynchronous request to be processed under the condition that the asynchronous request to be processed is in a ready state;
processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed;
And based on the target callback function, sending the processing result to the target object.
2. The method according to claim 1, wherein the preset configuration template includes a correspondence between paths and methods; the target method for determining the asynchronous request to be processed based on the preset configuration template and the asynchronous request to be processed comprises the following steps:
acquiring a target path from a request address of the asynchronous request to be processed;
and determining a method corresponding to the target path in the preset configuration template as a target method corresponding to the asynchronous request to be processed.
3. The method of claim 1, wherein the processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed comprises:
acquiring a request parameter set corresponding to the asynchronous request to be processed;
and calling the target method to process the request parameter set to obtain a processing result corresponding to the asynchronous request to be processed.
4. The method according to claim 1, wherein, in the case that the pending asynchronous request is in a ready state, before determining the target method corresponding to the pending asynchronous request based on a preset configuration template and the pending asynchronous request, the method further comprises:
Establishing and registering a target network connection channel corresponding to the asynchronous request to be processed;
acquiring an event state corresponding to the asynchronous request to be processed through the target network connection channel;
and when the event state corresponding to the asynchronous request to be processed is a preset event state, determining that the asynchronous request to be processed is in a ready state.
5. The method of claim 4, wherein the establishing and registering the target network connection channel corresponding to the pending asynchronous request comprises:
storing the asynchronous request to be processed in a waiting queue;
when the to-be-processed asynchronous request is the head of the queue in the waiting queue, generating a target network connection channel corresponding to the to-be-processed asynchronous request;
registering the target network connection channel on a target monitor; the target monitor is used for acquiring an event state corresponding to the asynchronous request to be processed through the target network connection channel.
6. The method according to claim 1, wherein, in the case that the pending asynchronous request is in a ready state, before determining the target method corresponding to the pending asynchronous request based on a preset configuration template and the pending asynchronous request, the method further comprises:
Determining a target thread corresponding to the asynchronous request to be processed;
and storing the to-be-processed asynchronous request in a target queue corresponding to the target thread.
7. The method of claim 6, wherein the processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed comprises:
and calling the target method through the target thread, and processing the request parameter set of the asynchronous request to be processed to obtain a processing result corresponding to the asynchronous request to be processed.
8. An asynchronous request processing apparatus, the apparatus comprising:
the acquisition module is used for acquiring the asynchronous request to be processed and the target callback function corresponding to the target object;
the determining module is used for determining a target method corresponding to the asynchronous request to be processed based on a preset configuration template and the asynchronous request to be processed under the condition that the asynchronous request to be processed is in a ready state;
the processing module is used for processing the asynchronous request to be processed based on the target method to obtain a processing result corresponding to the asynchronous request to be processed;
And the callback module is used for sending the processing result to the target object based on the target callback function.
9. A computer device comprising a memory and a processor, the memory storing a computer program, characterized in that the processor implements the steps of the method of any of claims 1 to 7 when the computer program is executed.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1 to 7.
CN202310904143.4A 2023-07-21 2023-07-21 Asynchronous request processing method, device, computer equipment and storage medium Pending CN117009104A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310904143.4A CN117009104A (en) 2023-07-21 2023-07-21 Asynchronous request processing method, device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310904143.4A CN117009104A (en) 2023-07-21 2023-07-21 Asynchronous request processing method, device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117009104A true CN117009104A (en) 2023-11-07

Family

ID=88568385

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310904143.4A Pending CN117009104A (en) 2023-07-21 2023-07-21 Asynchronous request processing method, device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117009104A (en)

Similar Documents

Publication Publication Date Title
US10291704B2 (en) Networked solutions integration using a cloud business object broker
CN112685148A (en) Asynchronous communication method and device of mass terminals, computer equipment and storage medium
CN113297305A (en) Session state processing method, device, equipment and storage medium
CN117009104A (en) Asynchronous request processing method, device, computer equipment and storage medium
CN114254278A (en) User account merging method and device, computer equipment and storage medium
CN117453759B (en) Service data processing method, device, computer equipment and storage medium
CN111221858B (en) Data processing method, device and equipment
CN114238292B (en) Data cleaning method, device, computer equipment and computer readable storage medium
CN110266665B (en) Connection method, device and equipment of network block equipment and readable storage medium
CN118018545A (en) Data exchange method, device, computer equipment and storage medium
CN116366724A (en) Business process processing method, device, computer equipment and storage medium
CN116795871A (en) Task state determining method and device and computer equipment
CN114915573A (en) Test method, device, equipment, storage medium and program product
CN117076076A (en) Task processing method, device, computer equipment and storage medium
CN117632395A (en) Workflow processing method, device, apparatus, storage medium and program product
CN116541145A (en) Data calling method, device, computer equipment and computer storage medium
CN117707602A (en) Data request processing method, device, server and storage medium
CN115858371A (en) Script testing method and device, computer equipment and storage medium
CN116628666A (en) Interaction method, interaction device, computer equipment and storage medium
CN116662016A (en) Port switching method, device, computer equipment, storage medium and program product
CN116881154A (en) Pressure testing method, pressure testing device, computer equipment and storage medium
CN116800833A (en) Data pushing method, device, computer equipment and storage medium
CN117194036A (en) Contract information processing method and device and computer equipment
CN117935406A (en) Digital key activation method, device, computer equipment and storage medium
CN116775284A (en) Task processing method, device, computer equipment and storage medium

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