A transaction processing method and device supporting observation of asynchronous applications

By adding identification fields and asynchronous contexts to the access thread and processing thread of asynchronous applications, and sending data separately to the same message system partition, the problem of APM products being unable to handle asynchronous application transaction links is solved, and transaction requests for asynchronous applications are realized. Effective observation and optimization.

CN114296895BActive Publication Date: 2024-09-17TRAVELSKY TECHNOLOGY LIMITED
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111612129.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-27
Publication Date
2024-09-17
Estimated Expiration
2041-12-27

AI Technical Summary

Technical Problem

Existing application performance monitoring (APM) products cannot effectively process and optimize the transaction links of asynchronous applications, and cannot meet the growing business needs.

Method used

By adding identification fields to the access thread and processing thread of the asynchronous application, the asynchronous context is generated and set in thread local variables. The access thread data and processing thread data are separately sent to the same partition of the specified message system. Subsequent Observe and optimize by consuming the thread data of each partition in the message collection.

Benefits of technology

It achieves effective processing and optimization of asynchronous application transaction requests and meets the growing business needs without making major modifications to the existing APM model and logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114296895B
    Figure CN114296895B
Patent Text Reader

Abstract

The present invention provides a transaction processing method and device supporting observation of asynchronous applications, obtaining transaction requests of asynchronous applications; adding a first identification field to access thread data of an access thread corresponding to the asynchronous application, generating an asynchronous context in the access thread; setting the asynchronous context in the first thread local variable of the access thread; using the first thread local variable, setting the asynchronous context in the second thread local variable of a processing thread corresponding to the asynchronous application, and calling the processing thread to respond to the transaction request to obtain a corresponding return code; setting the return code corresponding to the processing thread in the second thread local variable, adding a second identification field to the processing thread data of the processing thread; and separately sending the access thread data and the processing thread data to the same partition in the target message set of a specified message system. Subsequently, the asynchronous application can be processed and optimized by consuming the thread data of each partition in the target message set to meet the growing business needs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular to a transaction processing method and device supporting observation of asynchronous applications. Background Art

[0002] Application Performance Monitoring (APM) provides end-to-end observability of transaction links. APM obtains link information for each transaction to provide early warning, alarm, and fault location functions for operation and maintenance personnel and developers.

[0003] Current APM products usually only support processing and optimization of synchronous applications. However, some application nodes and some basic component nodes (such as API gateways) in the transaction chain are usually implemented asynchronously. Existing APM products can no longer meet the growing business needs. Therefore, there is an urgent need for a method that can handle the transaction chain of asynchronous applications. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a transaction processing method and device that supports observing asynchronous applications to meet the growing business needs.

[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0006] A first aspect of an embodiment of the present invention discloses a transaction processing method supporting observation of asynchronous applications, the method comprising:

[0007] Get the transaction request of the asynchronous application;

[0008] Adding a first identification field to access thread data of an access thread corresponding to the asynchronous application, and generating an asynchronous context in the access thread;

[0009] Setting the asynchronous context in a first thread-local variable of the access thread;

[0010] Using the first thread-local variable, setting the asynchronous context in a second thread-local variable of a processing thread corresponding to the asynchronous application, and calling the processing thread to respond to the transaction request and obtain a corresponding return code;

[0011] Setting the return code corresponding to the processing thread in the second thread local variable, and adding a second identification field to the processing thread data of the processing thread;

[0012] The access thread data and the processing thread data are separately sent to the same partition in a target message set of a designated message system.

[0013] Preferably, after separately sending the access thread data and the processing thread data to the same partition in the target message set of the designated message system, the method further comprises:

[0014] When target data is consumed from the designated message system, the target data is written into a cache, wherein the target data is the access thread data or the processing thread data;

[0015] Determining whether the access thread data and the processing thread data exist in the cache at the same time;

[0016] If the access thread data and the processing thread data exist in the cache at the same time, using the processing thread data to update the request level return code and response time of the access thread data;

[0017] Respectively parsing and storing the access thread data and the processing thread data;

[0018] If the access thread data and the processing thread data do not exist in the cache at the same time, perform the following steps;

[0019] The following steps are:

[0020] Determining whether the number of times the step of determining whether the access thread data and the processing thread data exist in the cache at the same time is executed is greater than or equal to a number threshold;

[0021] If the number of times is greater than or equal to the number threshold, retain the access thread data and parse and store it;

[0022] If the number is less than the threshold, after a preset delay, the process returns to the step of determining whether the access thread data and the processing thread data exist in the cache at the same time.

[0023] Preferably, the processing thread data carries at least a return code and timestamp information corresponding to the processing thread;

[0024] The updating of the request level return code and response time of the access thread data by using the processing thread data includes:

[0025] Assigning the return code carried by the processing thread data to the request level return code of the access thread data;

[0026] The request level response time of the access thread data is calculated by using the start time in the processing thread data, the start time in the access thread data and the request level response time of the processing thread data.

[0027] Preferably, using the first thread-local variable to set the asynchronous context in a second thread-local variable of a processing thread corresponding to the asynchronous application, and calling the processing thread to respond to the transaction request to obtain a corresponding return code, comprises:

[0028] Execute the code logic of the asynchronous application until the processing thread is started, and pass the asynchronous context in the first thread local variable to the processing thread;

[0029] The processing thread is started, the asynchronous context is set in a second thread local variable of the processing thread, and the processing thread is called to respond to the transaction request to obtain a corresponding return code.

[0030] Preferably, the separately sending the access thread data and the processing thread data to the same partition in the target message set of the designated message system comprises:

[0031] Adding a first preset header and a second preset header to the access thread data and the processing thread data, wherein the first preset header is used to point to a target message set of a specified message system, and the second preset header is set based on a transaction link ID of the transaction request;

[0032] sending the access thread data and the processing thread data to the target message set according to the first preset header;

[0033] In the target message set, the access thread data and the processing thread data are hashed according to the second preset header, and the access thread data and the processing thread data are written into the same partition in the target message set.

[0034] Preferably, the calculating the request-level response time of the access thread data by using the start time in the processing thread data, the start time in the access thread data, and the request-level response time of the processing thread data comprises:

[0035] Based on y=a-b+s, the request level response time of the access thread data is calculated, wherein y is the request level response time of the access thread data, a is the start time in the processing thread data, b is the start time in the access thread data, and s is the request level response time of the processing thread data.

[0036] Preferably, the designated message system is Kafka.

[0037] A second aspect of an embodiment of the present invention discloses a transaction processing device supporting observation of asynchronous applications, the device comprising:

[0038] An acquisition unit, used for acquiring a transaction request of an asynchronous application;

[0039] An adding unit, configured to add a first identification field to access thread data of an access thread corresponding to the asynchronous application, and generate an asynchronous context in the access thread;

[0040] A first setting unit, configured to set the asynchronous context in a first thread local variable of the access thread;

[0041] A processing unit, configured to set the asynchronous context in a second thread-local variable of a processing thread corresponding to the asynchronous application by using the first thread-local variable, and call the processing thread to respond to the transaction request and obtain a corresponding return code;

[0042] A second setting unit, configured to set a return code corresponding to the processing thread in the second thread local variable, and to add a second identification field to the processing thread data of the processing thread;

[0043] The distribution unit is used to separately send the access thread data and the processing thread data to the same partition in the target message set of the designated message system.

[0044] A third aspect of an embodiment of the present invention discloses an electronic device, comprising: a processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; and the memory is used to store a program, wherein the program is used to implement a transaction processing method supporting observation of asynchronous applications as disclosed in the first aspect of an embodiment of the present invention.

[0045] A fourth aspect of an embodiment of the present invention discloses a computer-readable storage medium, in which computer-executable instructions are stored. The computer-executable instructions are used to execute the transaction processing method supporting observation of asynchronous applications disclosed in the first aspect of an embodiment of the present invention.

[0046] Based on the above-mentioned embodiment of the present invention, a transaction processing method and device supporting observation of asynchronous applications are provided, the method comprising: obtaining a transaction request of an asynchronous application; adding a first identification field to the access thread data of the access thread corresponding to the asynchronous application, and generating an asynchronous context in the access thread; setting the asynchronous context in the first thread local variable of the access thread; using the first thread local variable, setting the asynchronous context in the second thread local variable of the processing thread corresponding to the asynchronous application, and calling the processing thread to respond to the transaction request to obtain a corresponding return code; setting the return code corresponding to the processing thread in the second thread local variable, and adding a second identification field to the processing thread data of the processing thread; and sending the access thread data and the processing thread data separately to the same partition in the target message set of the designated message system. Through this solution, the transaction request of the asynchronous application is processed, and the access thread data and the processing thread data of the same transaction request are sent to the same partition of the same message set. Subsequently, the observation data of the asynchronous application can be processed and optimized by consuming the thread data of each partition in the message set to meet the growing business needs. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0048] Figure 1 A schematic diagram of a method call tree for an asynchronous request provided by an embodiment of the present invention;

[0049] Figure 2 APM system architecture diagram provided for an embodiment of the present invention;

[0050] Figure 3 A flowchart of a transaction processing method supporting observation of asynchronous applications provided by an embodiment of the present invention;

[0051] Figure 4 A flowchart of consuming data from a specified message system provided by an embodiment of the present invention;

[0052] Figure 5 Another flow chart of consuming data from a specified message system provided by an embodiment of the present invention;

[0053] Figure 6 A structural block diagram of a transaction processing device supporting observation of asynchronous applications provided by an embodiment of the present invention;

[0054] Figure 7A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0055] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0056] In this application, the terms "comprises", "comprising" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "comprising a ..." does not exclude the presence of other identical elements in the process, method, article or device comprising the element.

[0057] As can be seen from the background technology, current application performance monitoring (APM) products usually only support processing and optimization of synchronous applications. For certain application nodes and certain basic component nodes (such as API gateways) that are implemented asynchronously in the transaction chain, existing APM products are unable to process and optimize asynchronous applications.

[0058] Therefore, an embodiment of the present invention provides a transaction processing method and device that supports observing asynchronous applications. Through this solution, transaction requests of asynchronous applications are processed, and access thread data and processing thread data of the same transaction request are sent to the same partition of the same message set. Subsequently, the observation data of the asynchronous application can be processed and optimized by consuming the thread data of each partition in the message set to meet the growing business needs.

[0059] It should be noted that, in order to better understand the contents provided by the following embodiments of the present invention, various professional terms are explained here, and the concept of asynchronous request is explained.

[0060] Trace: The call link of a single transaction request, which is mainly used to indicate which application nodes a single transaction request passes through and the time consumed by each node.

[0061] Span: mainly refers to the APM data generated by a method call, usually including span_id, parent_span_id and trace_id.

[0062] Propagation context: context information that needs to be transmitted between nodes in a transaction link. The data format is a string with a specific structure, usually including information such as trace_id and span_id.

[0063] ThreadLocal: Also known as thread local variables, a function provided by the JVM, mainly used to share data within the same thread.

[0064] Explanation of asynchronous requests:

[0065] like Figure 1 The schematic diagram of the method call tree of the asynchronous request is given. Each thread is composed of a method call tree. The method call tree of the non-connected thread is attached to the method call tree of the connected thread. The time relationship between different threads is as follows Figure 1 The timing diagram on the right. It can be understood that Figure 1 The "in" method in is the entry method for accessing the thread, which processes the thread ( Figure 1 The method call tree of the Thread-process in the access thread is hooked under the "in" method of the access thread. If there are other asynchronous threads (such as Figure 1 Thread-bar in the Thread-bar), other asynchronous threads are parallel to the processing thread, and each thread has a unique thread ID.

[0066] It is understandable that the transaction processing method supporting observation of asynchronous applications provided by the embodiment of the present invention can be applied to APM systems and API gateways, such as the APM system of TravelSky and the API gateway of TravelSky, and the transaction processing method supporting observation of asynchronous applications is implemented through the various components of APM. When implementing the transaction processing method supporting observation of asynchronous applications in APM, there is no need to modify the original model and original logic of APM. The transaction processing method supporting observation of asynchronous applications is mainly implemented by using the newly added logic between the various components of APM. Figure 2 The APM system architecture diagram shown implements a transaction processing method that supports observing asynchronous applications through components such as API gateway (including Javaagent and APM SDK), load balancing components, unified entry components, kafka and parsing warehousing components, stores the processed data and implements functions such as alarm and visualization front-end. For details, see the contents of the following embodiments.

[0067] See also Figure 3 , shows a flow chart of a transaction processing method supporting observation of asynchronous applications provided by an embodiment of the present invention, the transaction processing method comprising:

[0068] Step S301: Obtain a transaction request of an asynchronous application.

[0069] In the specific implementation of step S301, a transaction request sent by the client of the asynchronous application is obtained. The transaction request usually corresponds to a business transaction and a trace of the APM.

[0070] Step S302: adding a first identification field to access thread data of an access thread corresponding to an asynchronous application, and generating an asynchronous context in the access thread.

[0071] It should be noted that APM is mainly used to implement distributed tracing of different application nodes. Each application node must propagate a propagation context to the next application node. The propagation context (usually a string in a fixed format) contains necessary information of the tracing model such as trace_id and span_id. When tracing asynchronous application nodes, different threads within the asynchronous application node need to pass an asynchronous context. The asynchronous context is obtained by adding additional information to the propagation context. The asynchronous context usually consists of three parts. The first part is the propagation context passed from the previous application node, the second part is the propagation context that the current asynchronous application node needs to pass to the next application node, and the third part is the additional information of the current asynchronous application node. The propagation context passed from the previous application node and the propagation context passed to the next application node have differences in content. For example, the two propagation contexts mentioned above have the same trace_id and different span_id.

[0072] It can be understood that the propagation context is transferred between different application nodes (including synchronous application nodes and asynchronous application nodes), while the asynchronous context is only transferred between different threads within the asynchronous application node.

[0073] In some specific embodiments, at the collection end javaagent of APM, a plug-in is added for the API gateway to collect relevant data of the access thread and processing thread corresponding to the asynchronous application and add identification fields for the access thread and processing thread, as well as perform relevant operations on the access thread and processing thread. For details, see the contents of the following steps.

[0074] It should be noted that the processing thread mentioned in the embodiment of the present invention is a thread that responds to the transaction request of the asynchronous application. The processing thread may also be called an end thread or a response thread.

[0075] In the process of implementing step S302, javaagent is used in advance to perform bytecode conversion on the "in" method of the access thread corresponding to the asynchronous application, and the method corresponding to the javaagent is executed; at this time, relevant information of the APM model can be collected, and a first identification field is added to the access thread data (that is, the access span) of the access thread, for example: an identification field of async=0 is set in the access thread data, and this identification field is the first identification field; after adding the first identification field to the access thread data, the propagation context is obtained in the access thread and an asynchronous context is generated accordingly. The components of the asynchronous context can be found in the aforementioned content and will not be repeated here.

[0076] It is understandable that the first identification field is used to identify that the access thread data belongs to the access thread corresponding to the asynchronous application; in some specific embodiments, a unique identification suffix is ​​added to the id of the access thread to ensure the uniqueness of the access thread in the transaction request of the asynchronous application.

[0077] Step S303: setting the asynchronous context in the first thread local variable of the access thread.

[0078] In the specific implementation process of step S303, javaagent is used to call SDK to set the generated asynchronous context to the first thread local variable of the access thread (that is, the ThreadLocal of the access thread). After the asynchronous context is set to the ThreadLocal of the access thread, it indicates that the aspect of the enter phase is ended.

[0079] Step S304: using the first thread local variable, setting the asynchronous context in the second thread local variable of the processing thread corresponding to the asynchronous application, and calling the processing thread to respond to the transaction request to obtain a corresponding return code.

[0080] In the process of implementing step S304, the code logic of the asynchronous application is executed until the processing thread is started (at this time, tracking can be performed, such as manual tracking), and the asynchronous context in the local variable of the first thread is passed to the processing thread. Specifically, the SDK is called to obtain the asynchronous context in the local variable of the first thread, and the asynchronous context is passed to the processing thread to be started in the form of parameters and framework functions. It can be understood that due to the use of ThreadLocal to share the asynchronous context within the thread, the location of the SDK call only needs to be from the beginning of the "in" method to before the processing thread is started, which indicates that the access thread tracking is completed.

[0081] After the asynchronous context is passed to the processing thread, the processing thread is started, the asynchronous context is set in the second thread local variable of the processing thread, and the processing thread is called to respond to the transaction request to obtain the corresponding return code. Specifically, after the processing thread is started, the asynchronous context is obtained in the "process" method of the processing thread through the method provided by the framework, and then the SDK is called to set the obtained asynchronous context to the second thread local variable of the processing thread (that is, the ThreadLocal of the processing thread); at the same time, the processing thread is called to respond to the transaction request to obtain the corresponding return code.

[0082] It can be seen from the above steps S303 and S304 that the asynchronous context is first set to the ThreadLocal of the access thread (that is, the first thread local variable), and then the asynchronous context is obtained from the ThreadLocal of the access thread, and finally the obtained asynchronous context is set to the ThreadLocal of the processing thread (that is, the second thread local variable); thereby realizing the asynchronous context transfer between the access thread and the processing thread, that is, realizing the asynchronous context transfer between the access thread and the processing thread through the cooperation of ThreadLocal, asynchronous application and APM probe.

[0083] Step S305: setting the return code corresponding to the processing thread in the second thread local variable, and adding a second identification field to the processing thread data of the processing thread.

[0084] In the process of implementing step S305, the SDK is called in the "process" method of the processing thread to set the return code to the second thread local variable of the processing thread. The return code can be obtained by embedding the return code, that is, the return code is first set to the second thread local variable of the processing thread, and then the return code is obtained from the second thread local variable.

[0085] It is understandable that, in order to ensure that the data in the local variables of the second thread can be obtained, most of the collection operations of the processing thread need to be performed in the return aspect of the "process" method, and the tracking location for the processing thread only needs to be before the end of the "process" method. In the return aspect, the SDK is called by javaagent to obtain the asynchronous context and return code from the local variables of the second thread, and the asynchronous context is parsed to add a second identification field to the processing thread data (that is, the processing span) of the processing thread. For example: set the identification field of async=1 in the processing thread data, and this identification field is the second identification field.

[0086] It can be understood that the second identification field is used to identify that the processing thread data belongs to the processing thread corresponding to the asynchronous application; in some specific embodiments, a unique identification suffix is ​​added to the ID of the processing thread to ensure the uniqueness of the processing thread in the transaction request of the asynchronous application, which indicates that the return aspect ends and the processing thread burying point ends.

[0087] It should be noted that, in addition to the access thread and processing thread (thread that responds to transaction requests) mentioned above, there may be several threads between the access thread and the processing thread of the asynchronous application. However, the information such as response time and return code that need to be paid attention to in the embodiments of the present invention can be obtained only from the access thread and the processing thread, so the processing thread mentioned above is the end thread.

[0088] Step S306: separately sending the access thread data and the processing thread data to the same partition in the target message set of the designated message system.

[0089] It can be understood that after the above steps S302 to S305, the APM collection end has collected the access thread data and processing thread data corresponding to the transaction request. The above two data correspond to two method call trees. Due to asynchronous reasons, the access thread data and the processing thread data are collected and sent separately.

[0090] In the process of implementing step S306, a first preset header and a second preset header are added to the access thread data and the processing thread data. The first preset header is used to point to the target message set of the specified message system (such as kafka), and the second preset header is set based on the transaction link ID of the transaction request. For example: when the access thread data and the processing thread data are sent by javaagent in HTTP protocol, the two headers "kafka_topic=async" and "trace_id=xxx" are added to the access thread data and the processing thread data (that is, the data carrying the async identification field), and the access thread data and the processing thread data are distributed according to the first preset header and the second preset header added above; wherein, "kafka_topic=async" is the first preset header, and "trace_id=xxx" is the second preset header, and the value of trace_id can be determined according to the transaction request. By adding headers, the performance loss caused by some data parsing work can be avoided.

[0091] In some specific embodiments, the designated messaging system may be Kafka.

[0092] According to the first preset header, the access thread data and the processing thread data are sent to the target message collection. In the specific implementation, after receiving the access thread data and the processing thread data, the load balancing component of the APM backend forwards the access thread data and the processing thread data to the unified entry component of the backend; after receiving the access thread data and the processing thread data, the unified entry component sends the access thread data and the processing thread data to a separate target message collection (such as kafkatopic async) according to the value of the first preset header (such as the value of HTTP headerkafka_topic).

[0093] In the target message set, the access thread data and the processing thread data are hashed according to the second preset header, and the access thread data and the processing thread data are written to the same partition in the target message set. For example: in kafkatopic async, the access thread data and the processing thread data are hashed according to the value of HTTP header trace_id, so that the access thread data and the processing thread data of the same transaction request are written to the same partition (that is, the same partition), ensuring that the access thread data and the processing data in the same partition are consumed by the same consumer instance.

[0094] It should be noted that the unified entry component of the backend is also the producer of Kafka. The unified component adopts a load balancing architecture and there is no communication between nodes.

[0095] Through the contents of the above steps S301 to S306, for multiple transaction requests (asynchronous application requests), the access thread data and processing thread data corresponding to the same transaction request are written into the same partition, ensuring that the access thread data and processing thread data corresponding to the same transaction request are consumed by the same consumer instance.

[0096] In an embodiment of the present invention, the transaction request of the asynchronous application is processed, and the access thread data and the processing thread data of the same transaction request are sent to the same partition of the same message set. Subsequently, the observation data of the asynchronous application can be processed and optimized by consuming the thread data of each partition in the message set to meet the growing business needs.

[0097] The above embodiments of the present invention Figure 3 The thread data of each partition in the consumption message set involved in step S306 is taken as an example to consume the thread data in a certain partition. Figure 4 For explanation, see Figure 4 , shows a flow chart of consuming data from a specified message system provided by an embodiment of the present invention, including the following steps:

[0098] Step S401: When target data is consumed from a designated message system, the target data is written into a cache.

[0099] It should be noted that the target data is the access thread data or the processing thread data in a certain partition (a certain partition).

[0100] It can be understood that the parsing and warehousing component of the backend of APM is a consumer of Kafka. The parsing and warehousing component consumes data from the target message set of the specified message system (such as kafkatopic async) and stores it in the cache. The purpose of storing the data in the cache is: due to the asynchronous relationship, the access thread data and the processing thread data corresponding to the same transaction request are sent separately to the unified entry component and written to the same partition in the target message set of the specified message system. By hashing the transaction link ID (trace_id), it can only be guaranteed that the access thread data and the processing thread data are written to the same partition and consumed by the same consumer, but it cannot be guaranteed that the access thread data and the processing thread data are in adjacent positions in the partition. There will be a gap between the time when the parsing and warehousing component consumes the access thread data and the processing thread data (equivalent to a large offset difference). When it is necessary to calculate the access thread data and the processing thread data, a caching mechanism is required. See the following content for details.

[0101] In the specific implementation of step S401, when the target data corresponding to the same transaction request is consumed by the parsing warehousing component, that is, when the access thread data or processing thread data corresponding to a certain transaction request is consumed, the consumed target data is written into the cache.

[0102] Step S402: Determine whether the access thread data and the processing thread data exist in the cache at the same time. If the access thread data and the processing thread data exist in the cache at the same time, execute steps S403 and S404; if the access thread data and the processing thread data do not exist in the cache at the same time, execute steps S405 and S406.

[0103] In the specific implementation of step S402, after the target data is written into the cache, for the transaction request corresponding to the target data, it is determined whether the access thread data and the processing thread data corresponding to the transaction request exist in the cache at the same time.

[0104] It can be understood that for the access thread data and processing thread data corresponding to a certain transaction request, the access thread data and the processing thread data both carry the transaction link ID (trace_id) and the source ID (that is, span_id_from), and the access thread data also carries a first identification field, and the processing thread data also carries a second identification field.

[0105] For a transaction request corresponding to target data, the method for determining whether the access thread data and processing thread data corresponding to the transaction request exist in the cache at the same time is as follows: for a transaction request corresponding to the target data, the transaction link ID and source ID carried by the target data are used as keys, and the key is used as a query condition to query the cache. If the corresponding thread data can be queried, it is determined that the access thread data and processing thread data corresponding to the transaction request exist in the cache at the same time.

[0106] For example: assuming that the target data of a transaction request is the access thread data, the transaction link ID and source ID carried by the access thread data are used as the key, and the access thread data also carries the identification field of async=0. The key is used as the query condition to query the cache. If the processing thread data carrying the same transaction link ID and source ID can be queried, it means that the access thread data and processing thread data corresponding to the transaction request exist in the cache at the same time, and the processing thread data also carries the identification field of async=1; conversely, if the processing thread data carrying the same transaction link ID and source ID cannot be queried, it means that the access thread data and processing thread data corresponding to the transaction request do not exist in the cache at the same time.

[0107] Step S403: using the processing thread data, updating the return code and response time of the request level of the access thread data.

[0108] It should be noted that the processing thread data at least carries the return code and timestamp information corresponding to the processing thread.

[0109] In the process of implementing step S403, for a certain request, if the access thread data and the processing thread data corresponding to the transaction request exist in the cache at the same time, the access thread data and the processing thread data are taken out from the cache; and the request-level return code and response time of the access thread data are updated using the processing thread data.

[0110] It can be understood that, for the access thread data and processing thread data of a transaction request taken out from the cache, due to asynchronous reasons, the return code corresponding to the transaction request can only be obtained from the processing thread; therefore, in some specific embodiments, for the access thread data and processing thread data of a transaction request taken out from the cache, the request-level return code of the processing thread data is directly assigned to the request-level return code of the access thread data; the request-level response time of the access thread data is calculated using the start time in the processing thread data, the start time in the access thread data and the request-level response time of the processing thread data.

[0111] It should be noted that the request level refers to the overall transaction situation corresponding to the transaction request, such as the time taken for a single transaction, whether a single transaction is successful, and other transaction situations.

[0112] Specifically, the request-level response time of access thread data can be calculated by formula (1).

[0113] y=a-b+s(1)

[0114] In formula (1), y is the request-level response time of access thread data, a is the start time in processing thread data, b is the start time in access thread data, and s is the request-level response time of processing thread data.

[0115] It can be understood that after updating the return code and response time of the request level of the access thread data, the functions of the second identification field set for the processing thread data and the first identification field set for the access thread data are terminated.

[0116] Step S404: respectively parse and store the access thread data and the processing thread data into a database.

[0117] In the process of implementing step S404, after updating the request-level return code and response time of the access thread data through the content of step S403, the parsing and warehousing component can be used to separately parse and store the access thread data and the processing thread data corresponding to the same transaction request. After the parsing and warehousing, there is no need to associate the access thread data and the processing thread data in the parsing and warehousing component.

[0118] It can be understood that after updating the return code and response time of the request level of the access thread data, the functions of the second identification field set for the processing thread data and the first identification field set for the access thread data are terminated. When parsing and warehousing are performed, the first identification field and the second identification field do not need to be stored.

[0119] It should be noted that the above-mentioned parsing and storing of access thread data and processing thread data is not a necessary step. For some application scenarios, the access thread data and processing thread data do not need to be parsed and stored. For example, updating the access thread data is for the correct display of the visual front end and the normal execution of the alarm function. At this time, the access thread data and processing thread data do not need to be parsed and stored.

[0120] By parsing and storing the access thread data and the processing thread data through the parsing and storing component, it is possible to avoid changing too many components related to the APM, so as to maintain the unity of the original model of the original APM.

[0121] Step S405: Determine whether the number of times step S402 is executed is greater than or equal to the number threshold. If the number is greater than or equal to the number threshold, execute step S406; if the number is less than the number threshold, after a preset delay, return to execute step S402.

[0122] In the process of implementing step S405, for a certain request, if the access thread data and processing thread data corresponding to the transaction request do not exist in the cache at the same time, first determine whether the number of executions of step S402 is greater than or equal to the number threshold, that is, determine whether the number of queries from the cache for thread data with the same transaction link ID and source ID as the target data is greater than or equal to the number threshold; if the number is greater than or equal to the number threshold, execute step S406; if the number is less than the number threshold, return to execute step S402 after a preset delay, and query the cache again for thread data with the same transaction link ID and source ID as the target data.

[0123] For example: for a certain request, if the access thread data and processing thread data corresponding to the transaction request do not exist in the cache at the same time, determine whether the number of times the cache is queried for thread data with the same transaction link ID and source ID as the target data is greater than or equal to 2; if the number is greater than or equal to 2, execute step S406; if the number is less than 2, after a delay of 30s, query the cache again for thread data with the same transaction link ID and source ID as the target data.

[0124] Step S406: retain the access thread data and parse and store it into the database.

[0125] In the process of implementing step S406, if the number of times the thread data having the same transaction link ID and source ID as the target data is queried from the cache is greater than or equal to the number threshold, it means that one of the access thread data and the processing thread data having the same transaction link ID and source ID is lost, or it means that the delay between the access thread data and the processing thread data having the same transaction link ID and source ID is too large. In this case, only the access thread data is retained and parsed and put into storage.

[0126] In an embodiment of the present invention, when the target data is consumed from the designated message system, the target data is written into the cache. The cache is queried for thread data with the same transaction link ID and source ID as the target data. If the thread data with the same transaction link ID and source ID as the target data can be queried, the request-level return code and response time of the access thread data are updated by processing the thread data, thereby realizing the processing and optimization of the observation data of the asynchronous application to meet the growing business needs.

[0127] To better explain the above embodiments of the present invention Figure 4The contents of each step in the NioEventLoopGroup mechanism are passed Figure 5 Another flowchart showing consumption of data from a specified messaging system is provided as an example. Figure 5 The following steps are involved:

[0128] Step S501: Consume target data with a certain trace_id and a certain span_id_from from kafka.

[0129] It should be noted that trace_id is the transaction link ID, span_id_from is the source ID, and the target data is the access thread data (carrying an identification field of async=0) or the processing thread data (carrying an identification field of async=1).

[0130] Step S502: query the cache using the key composed of the trace_id and span_id_from of the target data as the query condition.

[0131] In the specific implementation of step S502, key = trace_id$$span_id_from, and the cache is queried using the key as a query condition.

[0132] Step S503: Determine whether thread data with the same trace_id and span_id_from as the target data is obtained. If thread data with the same trace_id and span_id_from as the target data can be obtained from the cache, execute step S504; if thread data with the same trace_id and span_id_from as the target data cannot be obtained from the cache, execute step S505 and subsequent steps.

[0133] In the specific implementation of step S503, when the target data is access thread data, it is determined whether the processing thread data (carrying an identification field of async=1) having the same trace_id and span_id_from as the access thread data is queried. When the target data is processing thread data, it is determined whether the access thread data (carrying an identification field of async=0) having the same trace_id and span_id_from as the processing thread data is queried.

[0134] If thread data having the same trace_id and span_id_from as the target data can be queried from the cache, step S504 is executed; if thread data having the same trace_id and span_id_from as the target data cannot be queried from the cache, step S505 and subsequent steps are executed.

[0135] Step S504: using the processing thread data, update the return code and response time of the request level of the access thread data.

[0136] Step S505: register the task to NioEventLoopGroup with the key consisting of trace_id and span_id_from, and trigger the task after a delay of 30s; write the target data into the cache.

[0137] Step S506: query the cache using the key consisting of the target data's trace_id and span_id_from as the query condition.

[0138] Step S507: Determine whether thread data with the same trace_id and span_id_from as the target data is obtained. If thread data with the same trace_id and span_id_from as the target data can be obtained from the cache, execute step S508; if thread data with the same trace_id and span_id_from as the target data cannot be obtained from the cache, execute step S509.

[0139] Step S508: using the processing thread data, update the return code and response time of the request level of the access thread data.

[0140] Step S509: retain the access thread data and parse and store it into the database.

[0141] The execution principle of steps S501 to S509 can be found in the above-mentioned embodiment of the present invention. Figure 4 The contents in will not be repeated here.

[0142] By the above Figures 1 to 5 It can be seen from the illustrated embodiment that there is no need to modify the backend storage, visual front-end, alarm and other components of the APM product. The newly added async identification field (first identification field and second identification field) in the access span and processing span has completed its function at the parsing and warehousing component. Therefore, there is no need to store the async identification field in the warehouse, and there is no need to change the storage table structure. In other words, there is no need to make too many changes to the components of the APM product. It is only necessary to incrementally design the APM product to enable the APM product to process and optimize synchronous applications and asynchronous applications. In addition, this solution is not only applicable to the Java language, but can also be applied to other languages, which are not specifically limited in this embodiment.

[0143] Corresponding to the transaction processing method supporting observation of asynchronous applications provided by the above embodiment of the present invention, see Figure 6, the embodiment of the present invention also provides a structural block diagram of a transaction processing device supporting observation of asynchronous applications, the transaction processing device comprising: an acquisition unit 601, an adding unit 602, a first setting unit 603, a processing unit 604, a second setting unit 605 and a distribution unit 606;

[0144] The acquisition unit 601 is used to acquire a transaction request of an asynchronous application.

[0145] The adding unit 602 is configured to add a first identification field to the access thread data of the access thread corresponding to the asynchronous application, and generate an asynchronous context in the access thread.

[0146] The first setting unit 603 is used to set the asynchronous context in the first thread local variable of the access thread.

[0147] The processing unit 604 is used to set the asynchronous context in the second thread local variable of the processing thread corresponding to the asynchronous application by using the first thread local variable, and call the processing thread to respond to the transaction request to obtain a corresponding return code.

[0148] In a specific implementation, the processing unit 604 is specifically used to: execute the code logic of the asynchronous application until the processing thread is started, and pass the asynchronous context in the first thread local variable to the processing thread; start the processing thread, set the asynchronous context in the second thread local variable of the processing thread, and call the processing thread to respond to the transaction request to obtain a corresponding return code.

[0149] A second setting unit 605 is used to set the return code corresponding to the processing thread in the second thread local variable, and add a second identification field to the processing thread data of the processing thread;

[0150] The distribution unit 606 is used to separately send the access thread data and the processing thread data to the same partition in the target message set of the designated message system.

[0151] In a specific implementation, the distribution unit 606 is specifically used to: add a first preset header and a second preset header to the access thread data and the processing thread data, the first preset header is used to point to the target message set of the specified message system, and the second preset header is set based on the transaction link ID of the transaction request; according to the first preset header, the access thread data and the processing thread data are sent to the target message set; in the target message set, the access thread data and the processing thread data are hashed according to the second preset header, and the access thread data and the processing thread data are written to the same partition in the target message set.

[0152] In some specific embodiments, the designated messaging system is Kafka.

[0153] In an embodiment of the present invention, the transaction request of the asynchronous application is processed, and the access thread data and the processing thread data of the same transaction request are sent to the same partition of the same message set. Subsequently, the observation data of the asynchronous application can be processed and optimized by consuming the thread data of each partition in the message set to meet the growing business needs.

[0154] Preferably, combined Figure 6 The transaction processing device further includes:

[0155] The consumption unit is used to write the target data into the cache when consuming the target data from the specified message system. The target data is the access thread data or the processing thread data.

[0156] The determination unit is used to determine whether the access thread data and the processing thread data exist in the cache at the same time.

[0157] The updating unit is used to update the request-level return code and response time of the access thread data by using the processing thread data if both the access thread data and the processing thread data exist in the cache.

[0158] In a specific implementation, the processing thread data carries at least a return code and timestamp information corresponding to the processing thread; the update unit is specifically used to: assign the return code carried by the processing thread data to the return code of the request level of the access thread data; and calculate the response time of the request level of the access thread data by using the start time in the processing thread data, the start time in the access thread data, and the response time of the request level of the processing thread data.

[0159] In some specific embodiments, the above formula (1) is used to calculate the request level response time of access thread data.

[0160] The parsing unit is used to parse and store the access thread data and the processing thread data respectively.

[0161] The execution unit is used to execute the following steps if the access thread data and the processing thread data do not exist in the cache at the same time;

[0162] The following steps are:

[0163] Determine whether the number of times the step of determining whether access thread data and processing thread data exist in the cache at the same time is greater than or equal to a number threshold;

[0164] If the number of times is greater than or equal to the number threshold, the access thread data is retained and parsed and stored in the database;

[0165] If the number is less than the threshold, the process returns to the execution determination unit after a preset delay.

[0166] In an embodiment of the present invention, when the target data is consumed from the designated message system, the target data is written into the cache. The cache is queried for thread data with the same transaction link ID and source ID as the target data. If the thread data with the same transaction link ID and source ID as the target data can be queried, the request-level return code and response time of the access thread data are updated by processing the thread data, thereby realizing the processing and optimization of the observation data of the asynchronous application to meet the growing business needs.

[0167] An embodiment of the present invention also provides an electronic device, which includes: a processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; and the memory is used to store a program, wherein the program is used to implement a transaction processing method that supports observation of asynchronous applications.

[0168] Reference below Figure 7 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic device in the embodiments of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 7 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.

[0169] like Figure 7 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 706 into a random access memory (RAM) 703. In RAM 703, various programs and data required for the operation of the electronic device are also stored. The processing device 701, ROM 702, and RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0170] Typically, the following devices may be connected to the I / O interface 705: input devices 706 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 708 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 709. The communication devices 709 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 7An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0171] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 709, or installed from a storage device 708, or installed from a ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.

[0172] Furthermore, an embodiment of the present invention also provides a computer-readable storage medium, in which computer-executable instructions are stored, and the computer-executable instructions are used to execute a transaction processing method that supports observing asynchronous applications.

[0173] The above-mentioned computer-readable medium carries one or more programs. When the above-mentioned one or more programs are executed by the electronic device, the electronic device: processes the transaction request of the asynchronous application, sends the access thread data and processing thread data of the same transaction request to the same partition of the same message set, and subsequently processes and optimizes the observation data of the asynchronous application by consuming the thread data of each partition in the message set.

[0174] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0175] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0176] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can refer to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system or system embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The system and system embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without creative work.

[0177] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0178] The above description of the disclosed embodiments enables one skilled in the art to implement or use the present invention. Various modifications to these embodiments will be apparent to one skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A transaction processing method supporting observation of asynchronous applications, characterized in that: The method comprises: Get the transaction request of the asynchronous application; Adding a first identification field to access thread data of an access thread corresponding to the asynchronous application, and generating an asynchronous context in the access thread; Setting the asynchronous context in a first thread-local variable of the access thread; Using the first thread-local variable, setting the asynchronous context in a second thread-local variable of a processing thread corresponding to the asynchronous application, and calling the processing thread to respond to the transaction request and obtain a corresponding return code; Setting the return code corresponding to the processing thread in the second thread local variable, and adding a second identification field to the processing thread data of the processing thread; Separately sending the access thread data and the processing thread data to the same partition in a target message set of a designated message system; After separately sending the access thread data and the processing thread data to the same partition in the target message set of the designated message system, the method further includes: When target data is consumed from the designated message system, the target data is written into a cache, wherein the target data is the access thread data or the processing thread data; Determining whether the access thread data and the processing thread data exist in the cache at the same time; If the access thread data and the processing thread data exist in the cache at the same time, using the processing thread data to update the request level return code and response time of the access thread data; Respectively parsing and storing the access thread data and the processing thread data; If the access thread data and the processing thread data do not exist in the cache at the same time, perform the following steps; The following steps are: Determining whether the number of times the step of determining whether the access thread data and the processing thread data exist in the cache at the same time is executed is greater than or equal to a number threshold; If the number of times is greater than or equal to the number threshold, retain the access thread data and parse and store it; If the number is less than the threshold, after a preset delay, the process returns to the step of determining whether the access thread data and the processing thread data exist in the cache at the same time.

2. The method according to claim 1, characterized in that The processing thread data at least carries the return code and timestamp information corresponding to the processing thread; The updating of the request level return code and response time of the access thread data by using the processing thread data includes: Assigning the return code carried by the processing thread data to the request level return code of the access thread data; The request level response time of the access thread data is calculated by using the start time in the processing thread data, the start time in the access thread data and the request level response time of the processing thread data.

3. The method according to claim 1, characterized in that The using the first thread local variable to set the asynchronous context in the second thread local variable of the processing thread corresponding to the asynchronous application, and calling the processing thread to respond to the transaction request to obtain a corresponding return code, includes: Execute the code logic of the asynchronous application until the processing thread is started, and pass the asynchronous context in the first thread local variable to the processing thread; The processing thread is started, the asynchronous context is set in a second thread local variable of the processing thread, and the processing thread is called to respond to the transaction request to obtain a corresponding return code.

4. The method according to claim 1, characterized in that: The step of separately sending the access thread data and the processing thread data to the same partition in the target message set of the designated message system includes: Adding a first preset header and a second preset header to the access thread data and the processing thread data, wherein the first preset header is used to point to a target message set of a specified message system, and the second preset header is set based on a transaction link ID of the transaction request; sending the access thread data and the processing thread data to the target message set according to the first preset header; In the target message set, the access thread data and the processing thread data are hashed according to the second preset header, and the access thread data and the processing thread data are written into the same partition in the target message set.

5. The method according to claim 2, characterized in that: The step of calculating the request level response time of the access thread data by using the start time in the processing thread data, the start time in the access thread data, and the request level response time of the processing thread data comprises: Based on y=a-b+s, the request level response time of the access thread data is calculated, wherein y is the request level response time of the access thread data, a is the start time in the processing thread data, b is the start time in the access thread data, and s is the request level response time of the processing thread data.

6. The method according to any one of claims 1 to 4, characterized in that: The designated message system is Kafka.

7. A transaction processing device supporting observation of asynchronous applications, characterized in that: The device comprises: An acquisition unit, used for acquiring a transaction request of an asynchronous application; An adding unit, configured to add a first identification field to access thread data of an access thread corresponding to the asynchronous application, and generate an asynchronous context in the access thread; A first setting unit, configured to set the asynchronous context in a first thread local variable of the access thread; A processing unit, configured to set the asynchronous context in a second thread-local variable of a processing thread corresponding to the asynchronous application by using the first thread-local variable, and call the processing thread to respond to the transaction request and obtain a corresponding return code; A second setting unit, configured to set a return code corresponding to the processing thread in the second thread local variable, and to add a second identification field to the processing thread data of the processing thread; A distribution unit, used for separately sending the access thread data and the processing thread data to the same partition in the target message set of the designated message system; a consumption unit, configured to write the target data into a cache when consuming the target data from the designated message system, wherein the target data is the access thread data or the processing thread data; a determining unit, configured to determine whether the access thread data and the processing thread data exist in the cache at the same time; An updating unit, configured to update a request-level return code and a response time of the access thread data by using the processing thread data if both the access thread data and the processing thread data exist in the cache; A parsing unit, used for parsing and storing the access thread data and the processing thread data respectively; An execution unit, configured to execute the following steps if the access thread data and the processing thread data do not exist in the cache at the same time; The following steps are: Determining whether the number of times the step of determining whether the access thread data and the processing thread data exist in the cache at the same time is executed is greater than or equal to a number threshold; If the number of times is greater than or equal to the number threshold, retain the access thread data and parse and store it; If the number is less than the threshold, after a preset delay, the process returns to the step of determining whether the access thread data and the processing thread data exist in the cache at the same time.

8. An electronic device, characterized in that: include: A processor and a memory, wherein the processor and the memory are connected via a communication bus; wherein the processor is used to call and execute a program stored in the memory; The memory is used to store a program, and the program is used to implement the transaction processing method supporting observation of asynchronous applications as described in any one of claims 1-6.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are used to execute the transaction processing method supporting observation of asynchronous applications described in any one of claims 1-6.