Method and device for. NET application hotspot analysis in cloud native container
By deploying the analyzer Daemonset in the cloud native container and using the namespace mechanism to dynamically attach the analyzer, the problem of hot code analysis of .NET applications in the cloud native container is solved, real-time analysis and performance optimization at runtime are achieved, and the service quality is ensured. Ease of monitoring stability and performance.
Patent Information
- Application Number
- CN202410828180.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-10-29
AI Technical Summary
In a cloud-native container environment, existing technology cannot conduct hot code analysis of .NET applications in real time, especially because the analysis tools are not pre-deployed inside the container and cannot add analyzers in real time at runtime to capture and analyze problems.
Deploy the analyzer Daemonset on each Node node in Kubernetes, use the namespace mechanism of the Linux kernel to dynamically copy the analyzer to the inside of the container, and use the user identity UID and GID of the .NET application process to run the appender and dynamically attach the analyzer to the .NET application process. NET application process, collect hot code data and send it to the analysis center regularly. After the analysis is completed, the analyzer is uninstalled to ensure the cleanliness of the application environment and service continuity.
Realizes dynamic hotspot code analysis of .NET applications in a cloud-native container environment, avoids application interruption and restart, ensures service stability and convenience of performance monitoring, can quickly locate and solve performance bottlenecks, and obtain rich hotspots data.
Smart Images

Figure CN118860426A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer technology and relates to performance optimization of .NET applications in cloud native scenarios, and specifically to a method and device for hot spot analysis of .NET applications in a cloud native container. Background Art
[0002] Cloud native is a software architecture and development concept that aims to take advantage of the advantages of cloud computing environments, such as elasticity, scalability, and flexibility. It emphasizes the seamless integration of application design, development, and deployment with the cloud service environment, and fully utilizes the features provided by cloud infrastructure, such as containerization, microservice architecture, automated deployment, and elastic computing. Cloud native technologies include the use of container technologies such as Docker and CRI-O, orchestration tools such as Kubernetes, microservice architecture, automated operations, and continuous integration / continuous delivery (CI / CD).
[0003] Cloud-native .NET applications are various types of applications developed using .NET Core and .NET 5 or later, a cross-platform open source framework developed by Microsoft, including Web applications, microservices, desktop applications, cloud services, etc. Cloud-native .NET applications provide cross-platform support and can run on multiple operating systems such as Windows, Linux, and macOS. They support the construction of microservice architectures to take advantage of their lightweight and modular features, support containerization and cloud services, such as packaging and deployment using Docker, and can be easily deployed to various cloud service providers.
[0004] Hot code is a section of code or function that is frequently called during program execution. These code segments usually occupy a large proportion of CPU execution time due to frequent execution, which is important in performance optimization. Hot code can be any section that is frequently called during program execution, which can be a specific function, loop, algorithm, or a group of instructions. These codes are often the main source of program performance bottlenecks because they consume a lot of system resources, such as CPU cycles, and may cause performance degradation.
[0005] In non-container deployment scenarios, when a .NET application has a problem, it often relies on the dotnet-trace and dotnet-dump tools provided by Microsoft. They provide the necessary analysis functions specifically for .NET applications and can obtain application stack information and other key data. In addition, there are some third-party analysis tools that can start the analysis tool by loading specific environment variables when the process starts, thereby helping to diagnose the problem.
[0006] However, in cloud-native containerized deployment, the situation is slightly different. Current technologies cannot provide a solution for real-time hot code analysis while the program is running in a cloud-native container environment. Possible situations include:
[0007] 1) Since dotnet-trace, dotnet-dump or other similar tools may not be pre-deployed inside the container, you cannot use these tools directly.
[0008] 2) When the tool is pre-deployed inside the container, this method also has a limitation. The analyzer must be started immediately when the application starts, that is, the analyzer must exist throughout the life cycle of the application process. If the analyzer is not loaded when the application starts, it is impossible to append the analyzer in real time at runtime and capture and analyze problems. Summary of the invention
[0009] In view of the problem that current technology cannot perform hotspot code analysis in real time when the program is running in a cloud-native container environment, the present invention provides a method and device for hotspot analysis of .NET applications in a cloud-native container, realizing a dynamic technology without interrupting the operation of the application process to perform hotspot code analysis on .NET applications running in a cloud-native container environment, thereby effectively optimizing the performance monitoring and tuning capabilities of .NET applications in the cloud-native container environment.
[0010] The present invention provides a method for hot spot analysis of .NET applications in a cloud native container, comprising the following steps:
[0011] Step 1: Deploy the analyzer Daemonset on each Node of Kubernetes. The analyzer Daemonset consists of two parts: the analyzer and the appender. Set the analyzer Daemonset to have root permissions to access processes and resources on the node.
[0012] Step 2: After Daemonset is deployed successfully, start a scanning process to obtain a list of all processes on the Node node, traverse each process, obtain a list of modules loaded by the process through / proc / [PID] / maps, and identify whether the process belongs to a .Net application through the module list;
[0013] Step 3: Daemonset records the properties of each identified .Net application process, including the process identifier PID, startup time, startup command parameters, and the list of loaded modules, and then executes steps 4 to 9 for each .Net application process;
[0014] Step 4: Copy the copies of the appender and analyzer to the specified path / proc / [PID] / root inside the container;
[0015] Step 5: Enter the namespace of the .Net application process;
[0016] Step 6: Get the user identity UID and GID of the application process when it is running in the container and the PID of the process in the container, and mark the PID of the process in the container as a;
[0017] Step 7: Use the user identity UID and GID of the .NET application process to run the appender, dynamically attach the analyzer to the .NET application process with PID a, and the analyzer collects hot code data through the .Net interface;
[0018] Step 8: The analyzer sends the regularly collected hotspot code data to the collection and analysis center;
[0019] Step 9: After the analyzer finishes its task, uninstall the analyzer module in application process a and delete the copies of the appender and analyzer in the container.
[0020] In step 1, the analyzer Daemonset is set with permission to read the host proc file and permission to write to the container Namespace.
[0021] In step 6, the Namespace namespace technology of the Linux kernel is used to obtain the Uid list, Gid list and NSpid list in the / proc / [PID] / status file, and the user identity UID when the container process is running is obtained from the last column of the Uid list. The user group identity GID when the container process is running is obtained from the last column of the Gid list, and the PID of the process in the container is obtained from the last column of the NSpid list.
[0022] The step 7 comprises the following steps:
[0023] Step 7.1: Start the appender process. The appender process uses the ICLRProfiling::AttachProfiler interface to load the profiler into the specified process, that is, the .NET application process with PID a. After the profiler loading action is completed, the appender process exits; the profiler starts the analysis function, and executes steps 7.2 and 7.3 regularly to collect hot code data;
[0024] Step 7.2: The analyzer uses the ICorProfilerInfo4::EnumThreads interface to enumerate all managed threads in process a, record the thread collection slice, record thread information including thread id, thread name, etc., and construct a thread life cycle diagram, including attribute information such as thread id, thread name, creation time and destruction time;
[0025] Step 7.3: Traverse all threads in this thread collection slice, and use the ICorProfilerInfo2::DoStackSnapshot interface to obtain the instantaneous code stack method list of the thread. Traverse the instantaneous code stack method list of each thread, and construct hot code data, including hot thread graph, hot method graph and hot stack graph; among them, the hot thread graph records the thread id, thread name, running time and running status; the hot method graph records the method function name, assembly name, method class name and running time; the hot stack graph records the fragment size, fragment entry method function name, fragment assembly name, fragment method class name and running time.
[0026] Accordingly, the present invention provides a .NET application hotspot analysis device in a cloud native container, including an analyzer and an appender. The appender is an auxiliary program. When started, the appender process uses the ICLRProfiling::AttachProfiler interface to load the analyzer's dll file into the analyzed application process. After the analyzer is loaded successfully, the appender process exits.
[0027] The analyzer collects hot code data of the application process through the .Net interface, including the following:
[0028] (1) Use the ICorProfilerInfo4::EnumThreads interface to enumerate all managed threads in the process, record the current thread collection slice, record the thread id and name in the thread collection slice, compare it with the previous thread collection slice, construct a thread life cycle diagram, and record the thread id, thread name, creation time and destruction time;
[0029] (2) Traverse all threads in this thread collection slice, use ICorProfilerInfo2::DoStackSnapshot interface to obtain the instantaneous code stack method list of the thread, and obtain hot code data, including hot thread graph, hot method graph and hot stack graph; among them, the hot thread graph records the hot thread id, name, running time and running status; the hot method graph records the function name, assembly name, method class name and running time of the hot method; the hot stack graph records the size of the hot fragment, the fragment entry method function name, the fragment assembly name, the fragment method class name and running time;
[0030] The device is deployed on each Node of Kubernetes and has root permissions.
[0031] Compared with the prior art, the advantages and positive effects of the present invention are:
[0032] (1) The method and device of the present invention focus on implementing hot code analysis of .NET applications in cloud native containers. The analyzer is introduced into the container only when needed, and can be dynamically attached when the application is running. It is dynamically uninstalled after the analysis is completed, and the copy of the analyzer file in the container is deleted. This means that the cleanliness of the application environment is ensured, pollution of the application's operating environment is avoided, and interruption or restart of the container or application can be avoided, thereby ensuring the continuity and stability of the service and saving unnecessary performance overhead caused by analysis and monitoring. The method and device of the present invention make the diagnosis and analysis of performance problems more convenient and immediate, and help to quickly locate and solve performance bottlenecks or problems related to hot code.
[0033] (2) The method and apparatus of the present invention can obtain the user identity UID and GID of the container application process from the host machine, and use the user identity UID and GID of the .NET application process to run the appender, thereby ensuring the unity of the identity and permissions of the analyzer and the .NET application process, and avoiding analysis failure due to permission reasons.
[0034] (3) The method and device of the present invention can analyze and obtain multi-dimensional data such as thread life cycle, hot threads, hot methods, hot stacks, etc. of .NET applications, and can obtain rich hot data. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 is a schematic diagram of a .NET application hotspot analysis device in a cloud native container according to an embodiment of the present invention;
[0036] Figure 2 is a schematic diagram of a hotspot analysis method for .NET applications in a cloud native container according to an embodiment of the present invention;
[0037] Figure 3 It is a flow chart of the analyzer collecting hotspot code data in an embodiment of the present invention. DETAILED DESCRIPTION
[0038] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments.
[0039] The present invention proposes a device and method for hotspot analysis of .NET applications in a cloud-native container, which utilizes the namespace mechanism of the Linux kernel to dynamically copy the analyzer into the container, and then utilizes the namespace mechanism of the kernel to obtain the user identity of the .NET application in the container, and uses the user identity of the .NET application to dynamically attach the analyzer to the .NET application process, obtain information such as thread creation, thread destruction, and thread code stack, and construct a thread life cycle diagram, a hot thread diagram, and a hot method diagram, thereby realizing hotspot analysis of the .NET application.
[0040] The .NET application hotspot analysis device in a cloud native container provided by the embodiment of the present invention is as follows Figure 1 As shown in the figure, the corresponding .NET application hotspot analysis method in the cloud native container is as follows Figure 2 As shown in the figure, we can perform hot code analysis on .NET applications running in a cloud-native container environment.
[0041] like Figure 1 As shown, on each Kubernetes Node node, the application process runs in a Pod. The analysis device Daemonset of the present invention is deployed on each Kubernetes Node node, and the device includes an appender and an analyzer. The appender is an auxiliary program that runs as an independent exe process. It uses the ICLRProfiling::AttachProfiler interface to load the analyzer's dll file into the analyzed application process. When the analyzer is loaded successfully, the appender process exits. The analyzer implements the specific logic of application hot spot analysis. It is a dll file (dynamically loaded library) that runs in the process of the analyzed application, obtains the process, thread, managed code, code stack and other information of the application process, and generates hot code analysis data. How the specific analysis device Daemonset implements hot code analysis is described in the following method.
[0042] In the Pod, an appender copy and an analyzer copy are deployed for each .NET application process. The kernel's namespace mechanism is used to obtain the user identity of the .NET application inside the container, and the analyzer is dynamically attached to the .NET application process using the user identity of the .NET application to obtain information such as thread creation, thread destruction, and thread code stack, and construct thread life cycle diagrams, hot thread diagrams, and hot method diagrams.
[0043] like Figure 2 As shown, the implementation steps of the .NET application hotspot analysis method in the cloud native container of an embodiment of the present invention are as follows 1 to 9.
[0044] Step 1: Deploy the analyzer Daemonset. Deploy the original file of the analyzer Daemonset on each Node node of the container orchestrator Kubernetes. It has root permissions to access processes and resources on the node.
[0045] The embodiment of the present invention uses a Kubernetes YAML file to define an analyzer Daemonset. The analyzer Daemonset needs to have permission to read the host proc file (hostPID: true) and needs to have privileged permission to write to the container namespace (privileged: true).
[0046] The following is a sample YAML file snippet:
[0047]
[0048] The above example demonstrates how to deploy daemonset and apply for root permissions, hostPID, and hostIPC permissions. The purpose of obtaining hostPID and hostIPC permissions is to obtain a list and information of all processes on the Node node.
[0049] Step 2: Identify the .NET application process. Get a list of all processes on the Node node, enumerate each process, get a list of modules loaded by the process through / proc / [PID] / maps, and identify whether the process belongs to a .NET application through the module list.
[0050] After Daemonset is deployed successfully, a scanning process is started to read the / proc / file system on the Node node and enumerate each process. The / proc / file system on the Linux system provides detailed information about the running processes. The subdirectories under this directory can be traversed, and each subdirectory corresponds to a process. For each process, the / proc / [PID] / maps file is checked to obtain the list of modules loaded by the process. The list of modules loaded by the process is searched for module names that are unique to .NET applications, such as Microsoft.AspNetCore.dll, mscorlib.dll, or coreclr.dll. Once these unique module names are found, the process is considered to be a .NET application.
[0051] Step 3: Record the attribute information of the .NET application process. If the process category is .NET application, record the attribute information of the .NET application process, including the process identifier PID, startup time, startup command parameters, and the list of modules loaded by the process obtained in step 2, and execute steps 4 to 9.
[0052] Step 4: Copy the appender and analyzer to the container: Use the characteristics of the Linux kernel to copy the copies of the appender and analyzer to the specified path of / proc / [PID] / root in the container.
[0053] If you want the analyzer copy to be loaded normally by the .Net application process in the container, you must ensure that the .Net application process in the container can normally identify the file path of the analyzer in the container. By using the technical feature that the container process file system is mapped to the host machine's / proc / [PID] / root, copy the analyzer copy to the Node node's / proc / [PID] / root / path to ensure that the .Net application process can read the analyzer file. For each .NET application process, a copy of the appender and analyzer will be copied to its own root file.
[0054] For example, the path where the appender and analyzer files are placed on the Node node is / analyzer-daemonset / analyzer_[version]. This folder contains the appender file attacher and the analyzer file analyzer.dll, as shown below:
[0055]
[0056] You can then execute the following command to copy the appender and analyzer to the container, as follows:
[0057] cp-rf / analyzer-daemonset / analyzer_[version] / proc / [pid] / root /
[0058] That is, copy the attachment file and the analyzer file to the root file of the corresponding .Net application process, so that for the .Net application process in the container, " / analyzer_[version] / attacher" and " / analyzer_[version] / analyzer.dll" are legal file paths.
[0059] Step 5: Enter the namespace of the application process. Use the Namespace technology of the Linux kernel to enter the PID and mount namespace corresponding to the .Net application process.
[0060] Using the nsenter command is a simple method to enter the namespace of another process. In the embodiment of the present invention, the nsenter command is used in combination with the --target parameter to specify the PID of the target process and select the namespace type to be entered.
[0061] For example, enter the Mount namespace of the .NET application process as follows:
[0062] nsenter--target <pid>--mount < / pid>
[0063] For example, entering the PID namespace of a .NET application process is as follows:
[0064] nsenter--target <pid>--pid < / pid>
[0065] Step 6: Get the user identity UID and GID of the .NET application process and the process PID in the container. Use the Namespace technology of the Linux kernel to find the user identity UID and group identity GID of the .NET application process and the PID in the container.
[0066] When a .NET application is running, it has specific user permissions. To ensure that the analyzer can run perfectly, you must run the analyzer with the same user identity as the .NET application, otherwise it may cause security verification errors.
[0067] Use the Namespace technology of the Linux kernel to obtain the Uid list in the / proc / [PID] / status file. The last column in the Uid list is the user identity UID when the container process is running. Obtain the Gid list in the / proc / [PID] / status file. The last column in the Gid list is the user group identity GID when the container process is running.
[0068] Use the Namespace technology of the Linux kernel to obtain the NSpid list in the / proc / [PID] / status file. The last column in the NSpid list is the process PID in the container.
[0069] Step 7: Use the user identity UID and GID of the .NET application process obtained in step 6 to run the appender, dynamically attach the analyzer to the .NET application process, and the analyzer collects hot code data through the .Net interface provided by Microsoft.
[0070] Use the -S and -G parameters of nsenter to pass in the user identity obtained in step 6, and run the attach action of the attacher copy on the specified .NET application process:
[0071] nsenter--target <pid> -S <uid> -G <gid> / analyzer_[version] / attacher-pid <Container PID> < / gid> < / uid> < / pid>
[0072] In the above code, the -pid parameter is used to specify the target .Net application process, the appender process is run in the specified process using the obtained user identity, and the analyzer dll file is loaded into the specified process space.
[0073] After the appender attaches the analyzer to the specified .NET application process, the analyzer calls the .Net interface provided by Microsoft to collect hot code data and obtain the running time and status of threads and codes, including the following steps 7.1 to 7.3.
[0074] Step 7.1: The attacher uses the ICLRProfiling::AttachProfiler interface to load the profiler into the specified process. The profiler starts the analysis function and collects the hotspot code data at a certain time, such as once a second.
[0075] After the appender is started, it reads the PID of the .NET process in the container passed in through the startup parameters, sets the process number to a, and calls the .NET runtime kernel ICLRProfiling::AttachProfiler provided by Microsoft to load the profiler into the specified .NET process. After the profiler loading action is completed, the work of the appender ends and the appender process exits.
[0076] After the analyzer is loaded into the specified .NET process, set a scheduled task or use a scheduler to periodically trigger steps 7.2 and 7.3 to collect the code execution information of the process, such as Figure 3 shown.
[0077] Step 7.2: The analyzer uses the ICorProfilerInfo4::EnumThreads interface to enumerate all managed threads in process a, record the thread collection slice, including thread id, thread name, etc., and construct a thread life cycle diagram, including thread id, thread name, creation time, destruction time and other attribute information.
[0078] The profiler uses the current thread collection slice returned by ICorProfilerInfo4::EnumThreads to compare with the last thread collection slice collected in the last collection cycle, including:
[0079] Step 7.2.1. Traverse all threads in the last thread set slice.
[0080] If the last thread id does not exist in the current thread set slice, it is considered that the last thread has been destroyed, and the thread destruction time and other information are recorded.
[0081] Step 7.2.2. Traverse all threads in this thread set slice.
[0082] If the current thread id does not exist in the previous thread set slice, the thread is considered to be a new thread, and the thread name is obtained, and the thread creation time and other information are recorded.
[0083] Step 7.3: Traverse all threads in this thread collection slice, and use the ICorProfilerInfo2::DoStackSnapshot interface to obtain the instantaneous code stack method list of the thread. Traverse the instantaneous code stack method list of each thread and construct hot code data, including: hot thread graph, including thread id, thread name, running time and running status; hot method graph, including method function name, assembly name, method class name and running time; hot stack graph, including fragment size, fragment entry method function name, fragment assembly name, fragment method class name and running time.
[0084] Step 7.3.1. The analyzer loops through the instantaneous code stack method list of each thread, obtains the stack method ID of each method, and uses the hash table HashMap cache to improve the efficiency of obtaining the stack method: if there is cache information of the method ID in the HashMap, the method function name, assembly name, method class name and other attribute information stored in the HashMap is used; otherwise, the stack method ID is passed in through the .NET application process runtime interface to obtain the method function name, assembly name, method class name and other attribute information corresponding to the stack method, and the above information is stored in the HashMap.
[0085] Step 7.3.2. How to identify hot threads: Enumerate the instantaneous code stack method list of the thread. If any stack method contains states such as Sleep and Wait that do not consume CPU, the thread will be marked as a non-hot thread. After the enumeration is completed, if the thread is not marked as a non-hot thread, the thread is a hot thread in the current time slot.
[0086] Step 7.3.3. How to identify hot methods: Get the top method ID of the instantaneous code stack method list, determine whether this method is in the hot thread, and in each timing loop, accumulate the counters of the methods in the hot thread and sort them according to the counter counts. The method with the highest count is the hot method.
[0087] Step 7.3.4. Method for determining hot stacks: Compare the continuous stack fragments in the stack method lists of multiple threads. If multiple threads contain the same continuous stack fragment, then this stack fragment is determined to be a hot stack and sorted according to the cumulative duration of the hot stack. The stack fragment with the longest duration is the hot stack.
[0088] Step 8: The analyzer periodically collects the hotspot code data generated in step 7 and sends it to the collection and analysis center.
[0089] Step 9: After the analysis is completed, uninstall the analyzer module in the application process and delete the analyzer copy.
[0090] To ensure the cleanliness of the container environment, after the analyzer completes the analysis task, the analyzer module is uninstalled in the application process, and the appender and analyzer copy files in the container are deleted. The implementation code is as follows:
[0091] rm -rf / analyzer_[version]
[0092] As shown above, rm -rf indicates the deletion command, which means deleting the file analyzer_[version] under / proc / [PID] / root.
[0093] The method of the present invention utilizes the characteristics of the Linux system kernel, copies the appender and the analyzer to the inside of the container, obtains the user identity UID and GID of the application process and the PID in the container, uses the user identity UID and GID of the .NET application process to run the appender, and dynamically attaches the analyzer to the .NET application process. The method of the present invention dynamically copies the analyzer to the inside of the container only when needed, and dynamically appends the analyzer when the application is running without restarting the container or the application process, dynamically uninstalls after the analysis is completed, and deletes the copy of the analyzer file in the container.
[0094] In the prior art, when analyzing, the analysis tools need to be packaged into the image in advance when the container image is made. If analysis is required, the container needs to be restarted and the analysis tools need to be loaded by specifying environment variables or startup scripts. If these analysis tools are not deployed in advance in a .Net application image, these tools cannot be used, and additional workloads such as repackaging the image, designing the interface of the loading tool, and waiting for the container restart window are required in the operation and maintenance operation. The present invention realizes that the analyzer is dynamically copied to the container only when needed, and the analyzer is dynamically appended when the application is running without restarting the container or application process. After the analysis is completed, it is dynamically uninstalled and the copy of the analyzer file inside the container is deleted. The code method executed by the .NET application is dynamically tracked and analyzed inside the analyzer, and the hot code is summarized and summarized using a specific algorithm. It solves the problem of how to dynamically and flexibly load the .NET analysis tool without changing the existing .NET application container image in a cloud-native environment.
[0095] Except for the technical features described in the specification, all of them are known technologies to those skilled in the art. The present invention omits the description of known components and known technologies to avoid redundancy and unnecessary limitation of the present invention. The implementation methods described in the above embodiments do not represent all implementation methods consistent with the present application. On the basis of the technical solution of the present invention, various modifications or variations that can be made by those skilled in the art without creative labor are still within the protection scope of the present invention.
Claims
1. A method for hotspot analysis of .NET applications in a cloud-native container, comprising the following steps: Step 1: Deploy the analysis device Daemonset on each Kubernetes node. Daemonset consists of two parts: analyzer and appender. Set Daemonset with root permissions to access processes and resources on the node. Step 2: After Daemonset is successfully deployed, a scanning process is started to obtain a list of all processes on the Node node. Each process is traversed and the list of modules loaded by the process is obtained through / proc / [PID] / maps. The module list is used to identify whether the process belongs to a .NET application. Step 3: Daemonset records the properties of each identified .Net application process, including the process identifier (PID), startup time, startup command parameters, and the list of loaded modules. It then executes steps 4-9 for each .Net application process. Step 4: Copy the copies of the analyzer and appender to the specified path / proc / [PID] / root in the container; Step 5: Enter the namespace of the .Net application process; Step 6: Obtain the user identity UID and group identity GID of the .Net application process when it is running in the container, as well as the process PID in the container; mark the process PID in the container as a; Step 7: Use the user identity UID and GID of the .NET application process obtained in step 6 to run the appender. The appender dynamically attaches the analyzer to the .NET application process with PID a. The analyzer collects hotspot code data through the .NET interface. Step 8: The analyzer sends the regularly collected hotspot code data to the collection and analysis center; Step 9: After the analyzer finishes the analysis task, the analyzer module is unloaded in process a, and the appender and analyzer copies in the container are deleted.
2. The method according to claim 1, characterized in that In step 1, the analyzer Daemonset is defined using a Kubernetes YAML file and is set with permissions to read the host's proc file and write to the container's namespace.
3. The method according to claim 1, characterized in that In step 6, the Namespace namespace technology of the Linux kernel is used to obtain the Uid list, Gid list and NSpid list in the / proc / [PID] / status file, obtain the user identity UID when the container process is running from the last column of the Uid list, obtain the user group identity GID when the container process is running from the last column of the Gid list, and obtain the process PID in the container from the last column of the NSpid list.
4. The method according to claim 1, wherein The step 7 includes: Step 7.1: Start the appender process. The appender process uses the ICLRProfiling::AttachProfiler interface to load the profiler into the .NET application process with PID a. After the profiler is loaded, the appender process exits. The profiler starts the profiling function and executes steps 7.2 and 7.3 periodically to collect hotspot code data. Step 7.2: The profiler uses the ICorProfilerInfo4::EnumThreads interface to enumerate all managed threads in process a, records the current thread set slice, records the thread ID and name in the thread set slice, compares it with the previous thread set slice, constructs a thread lifecycle diagram, and records the thread ID, thread name, creation time, and destruction time; Step 7.3: Traverse all threads in this thread collection slice, use the ICorProfilerInfo2::DoStackSnapshot interface to obtain the instantaneous code stack method list of the thread, and obtain the hot code data, including the hot thread graph, hot method graph and hot stack graph; among them, the hot thread graph records the hot thread id, name, running time and running status; the hot method graph records the function name, assembly name, method class name and running time of the hot method; the hot stack graph records the size of the hot fragment, the fragment entry method function name, the fragment assembly name, the fragment method class name and running time.
5. The method according to claim 4, characterized in that In the step 7.2, the analyzer traverses all threads in the previous thread set slice. If a thread does not exist in the current thread set slice, it is considered that the thread has been destroyed, and the destruction time of the thread is recorded; the analyzer traverses all threads in the current thread set slice. If a thread does not exist in the previous thread set slice, it is considered that the thread is a newly created thread, the thread name is obtained, and the thread creation time is recorded.
6. The method according to claim 4, characterized in that Said step 7.3 comprises: (1) Hot thread identification method: Enumerate the instantaneous code stack method list of the thread. If any stack method contains a state that does not consume CPU, mark the thread as a non-hot thread. After the enumeration is completed, if the thread is not marked as a non-hot thread, it is considered to be a hot thread in the current time slot; (2) Hotspot method identification method: obtain the top method of the instantaneous code stack method list and determine whether the method is in the hotspot thread. In each timing loop, accumulate the counters of the methods in the hotspot thread and sort them according to the counter counts. The method with the most counts is the hotspot method. (3) Hot stack identification method: Compare the continuous stack fragments in the thread stack method list. If there are multiple threads containing the same continuous stack fragment, the continuous stack fragment is judged to be a hot stack and sorted according to the cumulative duration of the hot stack. The stack fragment with the longest duration is the hot stack.
7. A device for hotspot analysis of .NET applications in a cloud native container, characterized in that: The device consists of two parts: an analyzer and an appender; The appender is an auxiliary program. When started, the appender process uses the ICLRProfiling::AttachProfiler interface to load the analyzer's dll file into the analyzed application process. After the analyzer is successfully loaded, the appender process exits. The analyzer collects hot code data of the application process through the .Net interface, including the following: (1) Use the ICorProfilerInfo4::EnumThreads interface to enumerate all managed threads in the process, record the current thread set slice, record the thread ID and name in the thread set slice, compare it with the previous thread set slice, construct a thread life cycle diagram, and record the thread ID, thread name, creation time and destruction time; (2) Traverse all threads in this thread collection slice, use the ICorProfilerInfo2::DoStackSnapshot interface to obtain the thread's instantaneous code stack method list, and obtain hot code data, including the hot thread graph, hot method graph, and hot stack graph; among them, the hot thread graph records the hot thread id, name, running time, and running status; the hot method graph records the function name, assembly name, method class name, and running time of the hot method; the hot stack graph records the size of the hot fragment, the fragment entry method function name, the fragment assembly name, the fragment method class name, and the running time; The device is deployed on each Node of Kubernetes and has root permissions.
8. The device according to claim 7, characterized in that After successful deployment, the device starts a scanning process, obtains a list of all processes on the Node node, traverses each process, accesses a file with the path / proc / [PID] / maps to obtain a list of modules loaded by the process, and checks the module list to determine whether the process belongs to a .Net application; for each identified .Net application process, the process attributes are recorded, and copies of the analyzer and the appender are copied to the path / proc / [PID] / root of the corresponding .Net application process in the container; the device enters the namespace of the .Net application process, obtains the user identity UID and group identity GID of the .Net application process when it is running in the container, and the process PID in the container, marks the process PID in the container as a, uses the obtained user identity UID and GID of the .NET application process to run the appender, and the appender dynamically attaches the analyzer to the .NET application process with PID a; the analyzer regularly collects hot code data and sends it to a collection and analysis center; after the analyzer completes the analysis task, the analyzer module is uninstalled in process a, and the copies of the appender and the analyzer in the container are deleted.
9. The device according to claim 7 or 8, characterized in that The method for identifying hot threads, hot methods, and hot stacks in the analyzer of the device is as follows: (1) Hot thread identification method: Enumerate the instantaneous code stack method list of the thread. If any stack method contains a state that does not consume CPU, mark the thread as a non-hot thread. After the enumeration is completed, if the thread is not marked as a non-hot thread, it is considered to be a hot thread in the current time slot; (2) Hotspot method identification method: obtain the top method of the instantaneous code stack method list and determine whether the method is in the hotspot thread. In each timing loop, accumulate the counters of the methods in the hotspot thread and sort them according to the counter counts. The method with the most counts is the hotspot method. (3) Hot stack identification method: Compare the continuous stack fragments in the thread stack method list. If there are multiple threads containing the same continuous stack fragment, the continuous stack fragment is judged to be a hot stack and sorted according to the cumulative duration of the hot stack. The stack fragment with the longest duration is the hot stack.
