Search

CN-121996326-A - Request processing method, request processing device, electronic equipment, storage medium and program product

CN121996326ACN 121996326 ACN121996326 ACN 121996326ACN-121996326-A

Abstract

The application provides a request processing method, a request processing device, electronic equipment, a storage medium and a program product, and relates to the technical field of software architecture under Java ecology, wherein the method comprises the steps of receiving a request, packaging the request into a Fiber task, and carrying out asynchronous processing; in the asynchronous processing process of the Fiber task, the dependent service is accessed in an asynchronous non-blocking mode, a user response is formed according to the dependent data and task logic, and the user response is written back to the user side in an asynchronous non-blocking mode. By the technical scheme provided by the embodiment of the application, the utilization rate of system resources and disaster recovery capability under a high concurrency scene can be improved, and the service deployment cost is reduced.

Inventors

  • QU HAIYANG
  • DUAN HAOJIE
  • HU QIAO
  • JIANG YONGFENG
  • LI JIALE
  • LI RAN
  • WANG XUECHUN
  • WEI LIANGXIAO

Assignees

  • 北京京东远升科技有限公司

Dates

Publication Date
20260508
Application Date
20241106

Claims (19)

  1. 1.A method of processing a request, comprising: Receiving a request, packaging the request into a Fiber task, and carrying out asynchronous processing; in the asynchronous processing process of the Fiber task, accessing the dependent service in an asynchronous non-blocking mode, and forming a user response according to the dependent data and task logic; And writing the user response back to the user terminal in an asynchronous non-blocking mode.
  2. 2. The method for processing requests according to claim 1, wherein said receiving the request, encapsulating the request into a Fiber task, and performing asynchronous processing, comprises: based on the asynchronous non-blocking service provider, the request is packaged into the Fiber task in a request receiving thread pool, and is transferred to the Fiber thread pool for asynchronous processing.
  3. 3. The method of claim 1, wherein during the asynchronous processing of the Fiber task, accessing the dependent service in an asynchronous non-blocking manner and forming a user response based on the dependent data and the task logic comprises: Based on the asynchronous non-blocking IO component and the asynchronous subscription thread pool, accessing the dependent service and suspending the Fiber task; Setting dependent data returned by the dependent service and recovering the suspended Fiber task based on a subscription callback thread pool, wherein the asynchronous subscription thread pool and the subscription callback thread pool are used for isolating network IO request operation in the Fiber task processing process; the user response is obtained based on the Fiber task logic and the dependency data.
  4. 4. The method for processing a request according to claim 1, wherein writing back the user response to the user terminal in an asynchronous non-blocking manner comprises: and encapsulating the user response to form a user response task, and transmitting the user response task to a response write-back thread pool for writing back the response to the user terminal, wherein the response write-back thread pool is used for isolating network IO request operation in the Fiber task processing process.
  5. 5. The method for processing request according to claim 2, wherein the asynchronous non-blocking service provider comprises a Rpc asynchronous callback service provider, springWebFlux Http service provider; The Fiber task comprises a request participation of the request, a callback object which is served by an asynchronous context of a publisher or RPC under WebFlux ecology, a business logic processing object and request receiving thread context information.
  6. 6. The request processing method according to claim 2, characterized in that the method further comprises: acquiring and cloning a Java thread context mapping table of a thread for processing the request in the request receiving thread pool; extracting the context information of the request receiving thread from the Java thread context mapping table, and copying the context information in a Fiber thread for processing the Fiber task by the Fiber Cheng Chizhong.
  7. 7. The method of claim 3, wherein the asynchronous non-blocking IO component comprises a Rpc asynchronous callback service consumer component, a SpringWebFlux lazy downstream services responsive component, and a database/cache/MQ responsive or asynchronous non-blocking access component.
  8. 8. The request processing method according to claim 3, wherein the accessing the dependent service and suspending the Fiber task based on the asynchronous non-blocking IO component and the asynchronous subscription thread pool comprises: Acquiring and cloning a Java thread context mapping table in a Fiber; Constructing an asynchronous subscription task based on the context information in the Java thread context mapping table in the Fiber and the asynchronous non-blocking IO component, wherein the asynchronous subscription task comprises the context information, the asynchronous non-blocking IO component, a request participation request of the request and a listener object, and the listener object comprises a completable CompletionStage object and the context information; The asynchronous subscription task is handed over to the asynchronous subscription thread pool, and the corresponding context information in the Java thread context mapping table of the Fiber thread is copied into an asynchronous subscription thread for processing the asynchronous subscription task in the asynchronous subscription thread pool; Accessing the dependent service based on the asynchronous subscription thread; Deleting the context information except the memory allocation cache of the Netty bottom layer in the subscription thread; the Fiber task is suspended using a Fiber framework.
  9. 9. A request processing method according to claim 3, wherein said resuming said suspended Fiber task comprises: After the dependency service returns the dependency data, the completion method of the completable CompletionStage object is invoked to resume the Fiber task that was suspended.
  10. 10. A request processing method according to claim 3, characterized in that the method further comprises: In the Fiber task asynchronous processing process, based on extraction and copying of Spring transaction context or using the same responsive database connection object to perform database access, the dependent data is obtained by realizing database transactional access.
  11. 11. The method according to claim 10, wherein in the Fiber task asynchronous processing, based on extraction and copying of a Spring transaction context or using the same responsive database connection object to perform database access, implementing database transactional access to obtain the dependent data includes: And in the asynchronous processing process of the Fiber task, performing operation by using thread pool isolation of a small number of threads, and performing context transfer and clearing by using a database transaction context object in Spring, so as to realize transactional access of the database to obtain the dependent data.
  12. 12. The method according to claim 10, wherein in the Fiber task asynchronous processing, based on extraction and copying of a Spring transaction context or using the same responsive database connection object to perform database access, implementing database transactional access to obtain the dependent data includes: And in the asynchronous processing process of the Fiber task, using asynchronous subscription thread pool isolation to operate, and using the same responsive database connection object to perform database access operation to realize the transactional access of the database to obtain the dependent data.
  13. 13. The method of claim 4, wherein the user response task comprises a request entry, a response object, a callback object, and context information of the request, wherein the context information is copied in a Java thread context mapping table corresponding to a Fiber thread.
  14. 14. The method of claim 4, wherein encapsulating the user response into a user response task and passing the response to the client write-back thread pool includes: encapsulating the user response to form a user response task, and transferring the user response task to a response write-back thread in the response write-back thread pool; Acquiring and cloning a Java thread context mapping table in a Fiber; Copying corresponding context information in a Java thread context mapping table of the Fiber thread into the response write-back thread for processing the user response task in the response write-back thread pool; Deleting Java thread context in the Fiber; Asynchronous non-blocking write-back is carried out to the user side based on the response write-back thread; And deleting the context information except the memory allocation cache of the Netty bottom layer in the response write-back thread.
  15. 15. A responsive software architecture based on blocking programming, characterized in that it is implemented by encapsulating the request processing method of any of claims 1 to 14 into a base framework.
  16. 16. A request processing apparatus, comprising: The request receiving unit is used for receiving a request, packaging the request into a Fiber task and carrying out asynchronous processing; The processing unit is used for accessing the dependent service in an asynchronous non-blocking mode in the asynchronous processing process of the Fiber task and forming a user response according to the dependent data and task logic; and the write-back unit is used for writing back the user response to the user side in an asynchronous non-blocking mode.
  17. 17. An electronic device comprising a memory and a processor, the memory storing a computer program executable on the processor, the processor implementing the steps of the method of any one of claims 1 to 14 when the computer program is executed.
  18. 18. 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 14.
  19. 19. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, realizes the steps in the method of any one of claims 1 to 14.

Description

Request processing method, request processing device, electronic equipment, storage medium and program product Technical Field The present application relates to the technical field of software architecture in Java ecology, and in particular, to a request processing method, apparatus, electronic device, storage medium, and program product. Background In the related technology, the current back-end online software application service realized based on Java ecology occupies a larger application scene. However, these back-end online application architectures mainly take traditional threads as units for performing blocking type data calculation and storage. However, under the condition that the use efficiency of resources is guaranteed by a single process, the upper limit of the number of threads borne is very low, the use efficiency of the resources is low due to high coupling degree, and the high concurrency system is not easy to build. Although a lightweight thread Fiber component or Spring WebFlux-based responsive programming scheme is provided, the problem of low upper limit of the number of single-process threads and serious resource coupling can be solved. However: 1. The direct use of traditional IO components in the Fiber can degrade into a blocking mode, access IO in the Fiber can occupy a large amount of memory, a custom thread pool can not inherit the context of the Fiber, and the ecology of the Fiber components is incomplete and can not fall to the ground independently. 2. Spring WebFlux the learning and reconstruction costs of stream programming are excessive. 3. The virtual threads behind the software development kit (Java Development Kit, JDK) 21 in Java language are also in experimental development, truly forming a complete and reliable ecology, and require very long time at the enterprise level to land. Because of the above factors, there is still no more flexible application architecture for realizing lightweight threads that can be quickly landed at low cost under Java ecology at present. When the thread is utilized to carry out blocking processing in the face of high concurrent requests, the problems of low utilization rate of system resources, poor disaster recovery capability, high service deployment cost and the like exist ≡! Disclosure of Invention The request processing method, the request processing device, the electronic equipment, the storage medium and the program product provided by the embodiment of the application can improve the utilization rate of system resources and disaster recovery capability under a high concurrency scene and reduce the service deployment cost. The technical scheme of the application is realized as follows: the embodiment of the application provides a request processing method, which comprises the following steps: Receiving a request, packaging the request into a Fiber task, and carrying out asynchronous processing; in the asynchronous processing process of the Fiber task, accessing the dependent service in an asynchronous non-blocking mode, and forming a user response according to the dependent data and task logic; And writing the user response back to the user terminal in an asynchronous non-blocking mode. In the above scheme, the receiving the request, and encapsulating the request into a Fiber task includes: based on the asynchronous non-blocking service provider, the request is packaged into the Fiber task in a request receiving thread pool, and is transferred to the Fiber thread pool for asynchronous processing. In the above scheme, in the asynchronous processing process of the Fiber task, accessing the dependent service in an asynchronous non-blocking mode, and forming a user response according to the dependent data and task logic, including: Based on the asynchronous non-blocking IO component and the asynchronous subscription thread pool, accessing the dependent service and suspending the Fiber task; Setting dependent data returned by the dependent service and recovering the suspended Fiber task based on a subscription callback thread pool, wherein the asynchronous subscription thread pool and the subscription callback thread pool are used for isolating network IO request operation in the Fiber task processing process; the user response is obtained based on the Fiber task logic and the dependency data. In the above scheme, the writing back the user response to the user end in an asynchronous non-blocking mode includes: and encapsulating the user response to form a user response task, and transmitting the user response task to a response write-back thread pool for writing back the response to the user terminal, wherein the response write-back thread pool is used for isolating network IO request operation in the Fiber task processing process. In the scheme, the asynchronous non-blocking service provider comprises an Rpc asynchronous callback service provider and SpringWebFlux Http service providers; The Fiber task comprises a request participation o