Data collection method, database server and storage medium
By deploying the extended event module and data download service on the database server, the collection strategy and the number of processes are dynamically adjusted, which solves the problems of insufficient data collection and large impact on database performance in the existing technology, and achieves efficient full-volume SQL data collection. .
Patent Information
- Application Number
- CN202411060426.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-05
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-08-05
AI Technical Summary
When the existing technology collects a full amount of SQL data, the data collection indicators are not comprehensive enough and have a great impact on the performance of the database system.
Using the data collection method, by deploying the extended event module and data download service on the database server, the task coordination module and file collection module are used to dynamically adjust the collection strategy and the number of processes according to the number of requests and resource usage of the database instance to ensure the accuracy of data collection. Comprehensiveness and efficiency.
It improves the comprehensiveness and efficiency of data collection under high load on CPU resources and database, and reduces the impact on database performance.
Smart Images

Figure CN118585404B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a data collection method, a database server and a storage medium. Background Art
[0002] The full amount of SQL (Structured Query Language) data in the database can be used for scenarios such as database performance analysis, SQL execution monitoring, table traffic analysis, CPU (Central Processing Unit) capacity analysis, and security auditing.
[0003] When collecting full SQL data, there are three common methods in the prior art: the first is to collect SQL statements by capturing tracking events through tools; the second is to capture protocol packets using packet capture tools and perform data analysis on the protocol packets to obtain SQL data; the third is to record SQL data at the data access layer.
[0004] However, the existing methods have the problem that the data collection indicators are not comprehensive enough and have a great impact on the performance of the database system. Summary of the invention
[0005] The purpose of this application is to provide a data collection method, a database server and a storage medium to address the deficiencies in the above-mentioned prior art, so as to solve the problem that data collection in the prior art is not comprehensive enough and has a great impact on the performance of the database system.
[0006] To achieve the above objectives, the technical solutions adopted in this application are as follows:
[0007] In a first aspect, the present application provides a data collection method, which is applied to a database server, wherein a database instance and a data download service are deployed on the database server, an extended event module is deployed on the database instance, and the data download service includes: a task coordination module and a file collection module, wherein the file collection module includes multiple processes, and the method includes:
[0008] The task coordination module determines the target collection strategy of the extended event module according to the number of requests for the database instance and the resource utilization rate of the database server within a preset period of time;
[0009] The extended event module collects the indicator data of the database instance according to the target collection strategy and the predefined event, and stores the collected indicator data in the file library to be downloaded;
[0010] The task coordination module determines the number of concurrent processes of the file acquisition module based on the current amount of data in the file library to be downloaded and the resource utilization rate of the database server, and starts one or more target processes, through which the data in the file library to be downloaded is downloaded to the parsing server for parsing.
[0011] Optionally, the task coordination module determines the target collection strategy of the extended event module according to the number of requests for the database instance and the resource usage rate of the database server within a preset period of time, including:
[0012] If the number of requests is less than or equal to a preset request threshold, and the resource usage rate is less than or equal to a first preset resource threshold, determining that the target collection strategy of the extended event module is a first collection strategy, in which data loss is not allowed;
[0013] If the number of requests is greater than a preset request threshold, and the resource usage rate is greater than a first preset resource threshold, the target collection strategy of the extended event module is determined to be a second collection strategy, in which data loss is allowed.
[0014] Optionally, before the extended event module collects the indicator data of the database instance according to the target collection strategy and the predefined event, it also includes:
[0015] According to the configuration instruction of the user, determining the at least one predefined event corresponding to the extended event module and the identification of the target indicator to be collected, wherein the at least one predefined event includes: a remote procedure call completion event, a batch completion event, and a statement completion event in a stored procedure;
[0016] The extended event module collects the indicator data of the database instance according to the target collection strategy and the predefined event, including:
[0017] The extended event module collects the indicator data of each target indicator in the database instance based on the predefined event according to the target collection strategy.
[0018] Optionally, the task coordination module determines the number of concurrent processes of the file acquisition module according to the current amount of data in the to-be-downloaded file library and the resource usage rate of the database server, including:
[0019] If the resource usage rate is less than a first preset resource threshold, the number of concurrent processes is determined according to the current data volume and the resource usage rate.
[0020] Optionally, the data in the to-be-downloaded file library is stored in the form of data files;
[0021] The step of transmitting the data in the to-be-transmitted file library to the parsing server for parsing through each of the target processes includes:
[0022] The target process obtains a target data file from the to-be-downloaded file library, and compresses the target data file to obtain a compressed file;
[0023] The target process transmits the compressed file to the parsing server for parsing.
[0024] Optionally, the target process obtains a target data file from the to-be-downloaded file library, and compresses the target data file to obtain a compressed file, including:
[0025] The target process obtains a target data file in a first preset format according to the file creation time;
[0026] The target process modifies the target data file into a second preset format, compresses the modified file to obtain a compressed file, and deletes the target data file.
[0027] Optionally, the target process transmits the compressed file to the parsing server for parsing, including:
[0028] The target process determines whether the current number of tokens is greater than the number of tokens required for the compressed file. If so, the compressed file is downloaded to the parsing server. If not, tokens are continuously requested until the current number of tokens is greater than the number of tokens required for the compressed file, and the compressed file is then downloaded to the parsing server.
[0029] Optionally, the method further comprises:
[0030] The task coordination module obtains the memory usage of the data download service based on a preset period;
[0031] If the memory usage is greater than a preset memory threshold, the data download service is restarted by restarting the process.
[0032] Optionally, the process of restarting the data download service by restarting the process includes:
[0033] The restart process creates a first marking file in the to-be-downloaded file library;
[0034] When the task coordination module detects the first marking file, the currently running task is regarded as the last task, and after the currently running task is completed, the first marking file is modified to the second marking file;
[0035] When the restart process detects the second marker file, the data download service is restarted.
[0036] Optionally, the method further comprises:
[0037] The task coordination module obtains the disk usage rate of the file library to be downloaded;
[0038] If the disk usage rate is greater than a preset disk threshold, the task coordination module determines the file capacity of the data file in the to-be-downloaded file library;
[0039] If the file capacity is greater than a preset capacity threshold, the task coordination module determines and deletes at least one target data file.
[0040] In a second aspect, an embodiment of the present application further provides a database server, comprising: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the storage medium via the bus, and the processor executes the machine-readable instructions to perform the steps of a data collection method as described in any one of the first aspects.
[0041] In a third aspect, an embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of a data acquisition method as described in any one of the first aspects are executed.
[0042] The beneficial effects of the present application are: the extended event module can respond to predefined events, collect indicator data of database instances, and ensure the comprehensiveness of data collection. By monitoring the number of requests and resource utilization, and adjusting the collection strategy of the extended event module, it is possible to reduce the resource consumption of the extended event module under high CPU resource load and high database load conditions. By monitoring the current data volume and resource utilization, the number of processes opened can be dynamically adjusted, and the download speed of the file can be adjusted in time based on the CPU usage, thereby improving the efficiency of data download. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A schematic diagram of the architecture of a database server provided in an embodiment of the present application is shown;
[0045] Figure 2 A flow chart of a data collection method provided by an embodiment of the present application is shown;
[0046] Figure 3 A flow chart of determining a target acquisition strategy provided by an embodiment of the present application is shown;
[0047] Figure 4 A flowchart of compressing and downloading a data file provided by an embodiment of the present application is shown;
[0048] Figure 5 A flowchart of compression processing provided by an embodiment of the present application is shown;
[0049] Figure 6 A flowchart of restarting a data download service according to memory usage provided by an embodiment of the present application is shown;
[0050] Figure 7 A flowchart of a restart data download service provided by an embodiment of the present application is shown;
[0051] Figure 8 A flowchart of deleting data files according to disk usage provided by an embodiment of the present application is shown;
[0052] Fig. 9 A schematic diagram of the structure of a database server provided in an embodiment of the present application is shown. DETAILED DESCRIPTION
[0053] To make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all of the embodiments. The components of the embodiments of the present application generally described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0054] It should be noted that the term "comprising" will be used in the embodiments of the present application to indicate the existence of the features declared thereafter, but does not exclude the addition of other features.
[0055] Full SQL data can be used for database performance analysis, SQL execution monitoring, table traffic analysis, CPU capacity analysis, security auditing, etc. When collecting full SQL data, full SQL collection for SQL SERVER database is different from that for open source databases. SQL cannot be recorded by modifying the database kernel.
[0056] The first collection method is to use SQL SERVER database engine tracing tools such as SQL Profiler to capture tracing events to collect SQL statements, and obtain SQL indicator data based on SQL statement analysis. However, opening SQL Profiler has a large overhead on the database system and will affect the performance of the database system.
[0057] The second method is to use a network packet capture tool to capture the TCP protocol packets of the database server and client, and then parse the captured packet data to extract SQL indicator data. However, in the process of network packet capture, there are many packets that do not contain valid SQL and data packets containing large SQL statements brought by the three-way handshake and four-way handshake during the database connection establishment process, which may have a certain impact on the performance of the database. Especially in the case of high load and large traffic, packet capture may increase network delay and processing time, resulting in longer database response time.
[0058] The third method is to obtain SQL indicator data by recording the SQL statements executed by the database in the DAL layer (Data Access Layer). This method has high requirements for applications and requires applications to access the database through a unified DAL layer. In addition, the execution indicators of SQL statements are not rich enough, and usually only limited indicators such as SQL statements, SQL execution time, and access sources can be obtained.
[0059] It can be seen that the existing data collection methods have the problem that the data collection indicators are not comprehensive and have a great impact on the performance of the database system.
[0060] Based on this, this application proposes a data collection method, which is applied to Figure 1 First, let's introduce the architecture of the database server. Figure 1, a database instance and a data download service, namely, an Agent collection program, are deployed on the database server. An extended event module, namely, XEvent (ExtendedEvents, an extended event module for full SQL statement collection), is deployed in the database instance. There is a communication relationship between the Agent collection program and the parsing server. The file data generated by XEvent collection can be downloaded from the file library to be downloaded to the parsing server. The file library to be downloaded can be a local file library, which includes multiple data files. XEvent can generate data files from the collected data and store the data files in the local file library. The Agent collection program can obtain the data files from the local file library and download the data files to the parsing server. In this process, the Agent collection program can monitor the collection status of the extended event module, database load, server CPU, memory, disk space and other information in real time, and dynamically adjust the data collection status of the extended event module and the file download work status of the Agent collection program itself based on the monitored information. When multiple database instances are deployed in the database server, an extended event module can be deployed in each database instance to collect data of each database instance respectively. The data download service can download the data collected by each extended event module to the parsing server.
[0061] Among them, the data download service includes a task coordination module and a file collection module. The file collection module includes multiple processes. The process is used to read data files from the file library to be downloaded and download the data to the parsing server. The task coordination module is used to monitor the extended event module collection files, database load, server CPU, memory, disk space and other information in real time, and dynamically adjust the process working status of the file collection module.
[0062] Continue to refer to Figure 1 The extended event module is used to collect data from the database instance where it is located. The data collected by the extended event module can be stored in Figure 1 In the file library to be downloaded shown, the data download service deployed on the database server can obtain data from the file library to be downloaded, and dynamically adjust the collection method of the extended event module and the working process of the data download service based on the load and resource usage of the database server, so as to balance the data processing speed and resource consumption and realize efficient full SQL data collection.
[0063] Next, the data collection method of the present application is described. This method can be applied to Figure 1 The database server shown, such as Figure 2 As shown, the method includes:
[0064] S201. The task coordination module determines a target collection strategy of the extended event module according to the number of requests for the database instance and the resource usage rate of the database server within a preset period of time.
[0065] The task coordination module monitors the number of collected files, database load, server CPU usage of the data download service, memory usage of the data download service, and disk resource usage of the data in real time.
[0066] The task coordination module can also monitor the number of requests for the database instance. The number of requests can be the average number of batch requests per second for the database instance. The requests for the database instance include requests received by the server for adding, deleting, modifying, and querying data in the database instance. When multiple database instances are deployed on the database server, the number of requests for each database instance can be monitored separately.
[0067] The task coordination module can monitor the CPU resource usage of the database server, for example, obtaining the CPU resource usage at a preset interval. As an example, the value of Batch Requests / sec in the sys.dm_os_performance_counters system view can be collected at an interval of ten seconds, and the average number of batch requests per second for 10 seconds can be calculated. The CPU usage can be collected at an interval of ten seconds, and the target collection strategy of the extended event module can be determined based on the average number of batch requests per second and the CPU usage.
[0068] Among them, the extended event module can be XEvent, which can capture various events on the database server, occupy very few system resources, and has significantly lower performance consumption than SQL Profiler, and also significantly reduces the impact on application performance.
[0069] The target collection strategy can be the event processing method when the extended event module collects data, such as collecting all data and not allowing loss, or giving priority to ensuring database performance during the collection process and allowing data loss.
[0070] S202: The extended event module collects indicator data of the database instance according to the target strategy and the predefined event, and stores the collected indicator data in the file library to be downloaded.
[0071] The indicator data may be SQL indicator data.
[0072] Multiple predefined events can be preconfigured in the extended event module. When a predefined event occurs, the indicator data of the database instance will be collected according to the target collection strategy. Taking XEvent as an example, when a predefined event is triggered, the SQL statement corresponding to the event and the performance indicator data of the SQL statement will be recorded and saved in a file in a specific format.
[0073] Predefined events can be events pre-configured by users. The extended event module can also pre-configure the indicators that need to be collected, such as SQL statements, execution time, CPU time consumed, duration, logical reads, physical reads, physical writes, number of affected rows, SQL statement hash values, etc.
[0074] As a possible implementation method, the extended event module can directly store the full amount of SQL data in the data file in the file library to be downloaded. After the data file is downloaded to the parsing server, the parsing server parses the data file to obtain the SQL statement and the corresponding indicator data.
[0075] The extended event module can store data in the file library to be downloaded, and the storage form of the data in the file library to be downloaded can be a data file. When there are multiple database instances, the data of different database instances can be stored in different file libraries to be downloaded, or stored in the same file library to be downloaded and the data of each database instance has the identifier of the database instance.
[0076] It is worth noting that after the extended event module collects the indicator data, the indicator data can be recorded in the event buffer first. When the amount of data in the event buffer reaches a preset value, the data in the event buffer is output to a data file. When the size of the data file reaches a preset size, the data file is stored in the file library to be downloaded. Exemplarily, the size of the buffer area can be 16M, and the size of the data file can be 500M. After the data in the buffer area is full, it can be output to the data file. When the size of the data file reaches 500M, the data file can be stored in the file library to be downloaded.
[0077] S203, the task coordination module determines the number of concurrent processes of the file acquisition module according to the current amount of data in the file library to be downloaded and the resource utilization rate of the database server, and starts one or more target processes, and transmits the data in the file library to be downloaded to the parsing server for parsing through each target process.
[0078] The current amount of data in the file library to be downloaded may be the number of files in the file library to be downloaded. The number of concurrent processes may be the number of processes that need to be started, and each process may be executed concurrently.
[0079] The task coordination module can monitor the amount of data in the file library to be downloaded, and dynamically adjust the number of processes to be started according to the amount of data in the file library to be downloaded and the CPU usage of the server. It should be understood that when the amount of data is large and the CPU usage is low, more processes can be started to improve the efficiency of data downloading. When the amount of data is large but the CPU usage is high, the number of started processes should be reduced to avoid excessive server load.
[0080] The file collection module includes multiple processes, which can be used to download the data in the file library to be downloaded to the parsing server. As a possible implementation method, when multiple database instances are deployed in the database server, the processes can be grouped, each database instance corresponds to a process group, and the processes in the process group are used to download the data of the database instance corresponding to the process group.
[0081] In an embodiment of the present application, the task coordination module dynamically adjusts the target collection strategy of the extended event module according to the number of requests for the database instance within a preset time period and the resource utilization rate of the database server. The extended event module collects SQL indicator data of the database instance according to predefined events, and stores the collected indicator data in the file library to be downloaded. The task coordination module determines the number of concurrent processes of the file collection module according to the current amount of data in the file library to be downloaded and the resource utilization rate of the database server, and starts one or more target processes. Through each target process, the data in the file library to be downloaded is downloaded to the parsing server for parsing.
[0082] The extended event module can respond to predefined events and collect indicator data of database instances, ensuring the comprehensiveness of data collection. By monitoring the number of requests and resource usage, and adjusting the collection strategy of the extended event module, it is possible to reduce the resource consumption of the extended event module when the CPU resources are highly loaded and the database is highly loaded. By monitoring the current data volume and resource usage, the number of processes opened can be dynamically adjusted, and the file download speed can be adjusted in time based on the CPU usage, thereby improving the efficiency of data download.
[0083] The following is a further description of the task coordination module determining the target collection strategy of the extended event module according to the number of requests for the database instance and the resource utilization rate of the database server within a preset period of time. Figure 3 As shown, the above step S201 includes:
[0084] S301: If the number of requests is less than or equal to a preset request threshold, and the resource usage rate is less than or equal to a first preset resource threshold, determine that the target collection strategy of the extended event module is a first collection strategy, in which data loss is not allowed.
[0085] S302: If the number of requests is greater than a preset request threshold, and the resource usage rate is greater than a first preset resource threshold, determine that the target collection strategy of the extended event module is a second collection strategy, in which data loss is allowed.
[0086] The number of requests may be an average number of batch requests per second. As an example, when the number of batch requests per second is less than or equal to 5000 and the CPU usage is less than or equal to 50%, the extended event module may adopt the first collection strategy to collect data.
[0087] Optionally, the first collection strategy may be to configure the event processing mode of XEvent as "NO_EVENT_LOSS", that is, data loss is not allowed during the data collection process.
[0088] When the number of batch requests per second is greater than 5000 and the CPU usage is greater than 50%, the extended event module can use the second collection strategy to collect data.
[0089] Optionally, the second collection strategy may be to configure the event processing mode of XEvent as "ALLOW_MULTIPLE_EVENT_LOSS", that is, data loss is allowed during the data collection process.
[0090] It is worth noting that when modifying the target collection strategy, the memory size of the event buffer mentioned in the above step 201 may also be modified, for example, from 16M to 4M, thereby reducing the resource consumption of the server by data collection.
[0091] In an embodiment of the present application, by monitoring the number of requests and the CPU usage rate, and switching the collection mode of the extended event module according to the number of requests and the CPU usage rate, the performance impact of the extended event module on the server can be reduced when the database is highly loaded and the CPU is highly loaded.
[0092] Before the above extended event module collects SQL indicator data in the database instance, the user can configure the collection method of the extended event module, including:
[0093] According to the user's configuration instructions, at least one predefined event corresponding to the extended event module and the identification of the target indicator to be collected are determined. The predefined events include: remote procedure call completion event, batch completion event, and stored procedure statement completion event.
[0094] Optionally, the processing module in the database server receives the user's configuration instructions. By inputting the configuration instructions, the user can configure which events trigger the kernel program when the execution is completed, and record the full SQL data of the database instance. Taking XEvent as an example, the configured predefined events may include: the event rpc_completed triggered when the remote procedure call is completed, the event sql_batch_completed triggered when the Transact-SQL batch execution is completed, and the event sp_statement_completed triggered when the statement in the stored procedure is completed. When the predefined event occurs, the extended event module can respond to the predefined event and collect data.
[0095] The process of the above-mentioned extended event module collecting SQL indicator data in the database instance specifically includes:
[0096] The extended event module collects indicator data of each target indicator in the database instance based on predefined events according to the target collection strategy.
[0097] When a predefined event occurs, the kernel program in the extended event module can be triggered to record data and collect indicator data of each target indicator in the database instance.
[0098] The target indicator can be pre-configured by the user in the extended event module. For example, the user can pre-define the collected SQL indicator content, including SQL statements, execution time, consumed CPU time, duration, logical reads, physical reads, physical writes, number of affected rows, SQL statement hash value, etc.
[0099] Optionally, when there are multiple databases, the user can also predefine filtering conditions to determine the databases that need to be collected and the data that needs to be collected in the databases. Exemplarily, assuming that there are a system database and multiple business databases, when the data in the business database needs to be analyzed, the filtering conditions can be defined to exclude the system database.
[0100] It is worth noting that when the extended event module is initialized, the target collection strategy can be set to the first collection strategy. During the operation of the database server, the task coordination module in the data download service can switch the target collection strategy according to the number of requests and CPU usage monitored in real time.
[0101] In the embodiment of the present application, by pre-configuring the extended event module, the kernel program can be triggered to automatically complete the full SQL data collection when the specified event is completed, thereby improving the efficiency of data collection. Moreover, since XEvent has the advantage of being lightweight, it also reduces the consumption of server resources by data collection and reduces the impact on server performance.
[0102] Next, the process of determining the number of concurrent processes of the file acquisition module and starting one or more target processes according to the current amount of data in the database to be downloaded and the resource usage rate of the database server by the task coordination module is described. The step S203 includes:
[0103] If the resource usage rate is less than the first preset resource threshold, at least one target process is determined according to the current data volume and the resource usage rate.
[0104] If the resource usage rate is greater than or equal to the first preset resource threshold, the process is not started.
[0105] If the resource usage rate is less than the first preset resource threshold, the number of target processes to be started can be determined based on the current data volume in the file library to be downloaded and the resource usage rate. Specifically, the current data volume can be compared with the preset data volume interval, and the current resource usage rate can be compared with the preset resource usage rate interval. Different combinations of data volume intervals and resource usage rate intervals correspond to different numbers of processes.
[0106] As an example, when the CPU usage is less than 90%, the number of processes to be started can be determined based on the current data volume in the file library to be downloaded and the resource usage. If the current data volume is less than 10 and the CPU usage is less than 90%, start one process; if the current data volume is greater than or equal to 10 and the CPU usage is less than 50%, start three processes for parallel processing. When the CPU usage is greater than or equal to 90%, pause file collection until it is detected that the CPU is less than 90% and resume.
[0107] In an embodiment of the present application, by monitoring the current amount of data and CPU usage in the file library to be downloaded, and starting the process based on the current amount of data and CPU usage, the data collection speed can be increased when the CPU is relatively idle, and the performance impact on the server can be reduced when the CPU is relatively busy.
[0108] Optionally, the data in the file library to be downloaded is stored in the form of a data file. When the event buffer is full, the data in the event buffer can be saved as a data file, and the data file is stored in the file library to be downloaded.
[0109] The above data download service downloads the data in the to-be-downloaded file library to the parsing server for parsing through each target process, such as Figure 4 As shown, including:
[0110] S401, the target process obtains the target data file from the to-be-downloaded file library, and compresses the target data file to obtain a compressed file.
[0111] The target data file may be the data file with the earliest file generation time in the file library to be downloaded. When the event buffer is full, the extended event module may save the data in the event buffer as a data file and add a timestamp to the data file, which may be included in the name of the data file. The data file containing the timestamp is then stored in the file library to be downloaded, and the data files in the file library to be downloaded may be arranged in chronological order.
[0112] The target process can obtain the data file with the earliest file time from the file library to be downloaded as the target data file, and compress the target data file to reduce the resource consumption of data download.
[0113] S402: The target process transmits the compressed file to the parsing server for parsing.
[0114] After the target process compresses the target data file, the target data file can be downloaded to the parsing server. During the download process, the download speed can be limited by a speed limiter to reduce the consumption of network IO during the download process.
[0115] Furthermore, in the above S401, the target process obtains the target data file from the to-be-downloaded file library, compresses the target data file, and obtains the compressed file, such as Figure 5 As shown, including:
[0116] S501. A target process obtains a target data file in a first preset format according to a file creation time.
[0117] Optionally, the file creation time may be a timestamp added when the data file is generated.
[0118] As a possible implementation, the format of the target data file can be determined by a file extension, i.e., a file suffix. For example, the first preset format can be a file extension of ".xel". When the target process obtains the target data file, it can obtain the data file with the earliest file creation time among the data files with the file extension of ".xel" as the target data file.
[0119] It is worth noting that in the present application, data files with earlier generation time can be prioritized according to the file creation time, and the target data file can also be determined according to the current network conditions for downloading. For example, among the first n files with the earliest file time, the data file with the smallest data volume can be used as the target data file, or the data file with the largest data volume that can be downloaded under the current network conditions can be used as the target data file. The present application does not impose any restrictions on this.
[0120] S502: The target process modifies the target data file into a second preset format, compresses the modified file to obtain a compressed file, and deletes the target data file.
[0121] It should be noted that when there are multiple target processes downloading data files in parallel, there may be a problem of the target process repeatedly downloading the same data file. In order to solve this problem, after the target process in the present application obtains the target data file, it can first modify the file extension of the target data file and modify the target data file in the first preset format to the second preset format. Since the target process obtains the target data file in the first preset format when obtaining the target data file, after modifying the target data file in the first preset format to the second preset format, the problem of the target data file being repeatedly processed by multiple parallel processing processes can be solved.
[0122] After modifying the format of the target data file, the process may compress the modified file to obtain a compressed file, delete the modified file, and transmit the compressed file to the parsing server.
[0123] Exemplarily, after the target process obtains the earliest target data file "SQLGeneral_0_1300.xel" in the first preset format according to the file creation time, the target data file can be first modified to the second preset format to obtain the modified file "SQLGeneral_0_1300.pending", and then the modified file "SQLGeneral_0_1300.pending" is compressed to generate a "SQLGeneral_0_1300.zip" file, and finally "SQLGeneral_0_1300.pending" is deleted and "SQLGeneral_0_1300.zip" is downloaded to the parsing server.
[0124] It is worth noting that when downloading compressed files, you can delete the compressed files after the download is successful. If the download fails due to network problems or other reasons, you can keep the compressed files intact and let the target process try to download the files again.
[0125] Since a large amount of file transfer will occupy a lot of network bandwidth, thus affecting the performance of the database, the data download service can also limit the network transmission bandwidth during the download process. Specifically, the process of the target process downloading the compressed file to the parsing server for parsing includes:
[0126] The target process determines whether the current number of tokens is greater than the number of tokens required for the compressed file. If so, the compressed file is downloaded to the parsing server. If not, it continues to request tokens until the current number of tokens is greater than the number of tokens required for the compressed file, and then the compressed file is downloaded to the parsing server.
[0127] Optionally, the data download service may include a rate limiter. As a possible implementation, the data download service may be written in GO language, and the rate limiter may be created by limiting the speed of network transmission through the Limiter object in GO language. The rate limiter may limit the amount of data transmitted per second. For example, when a speed limit of 1MB per second is set, a token of up to 1MB may be requested at a time to limit the rate of data transmission.
[0128] The data download service may first write the compressed file into a buffer, and then download the compressed file in the buffer to the parsing server. The amount of data represented by the token may be the same as the size of the pre-set buffer.
[0129] When the data download service downloads the compressed file in the buffer to the parsing server, it can first determine whether the current number of tokens is greater than the number of tokens required by the compressed file in the buffer. If so, the compressed file in the buffer is downloaded to the parsing server. If not, it can continue to wait for enough tokens until the current number of tokens is greater than the number of tokens required by the compressed file in the buffer, so as to ensure that the transmitted data does not exceed the upper limit of the rate limiter.
[0130] After receiving the compressed file, the parsing server can decompress the file, parse and extract SQL statements and related performance indicator data, and store the parsing results to a specified location so that users can query and perform data analysis in real time.
[0131] Optionally, the task coordination module in the data downlink service can also make dynamic adjustments when the data downlink service occupies too much memory and affects the server, such as Figure 6 As shown, specifically including:
[0132] S601. The task coordination module obtains the memory usage of the data download service based on a preset period.
[0133] S602: If the memory usage is greater than a preset memory threshold, restart the data download service by restarting the process.
[0134] To prevent the data download service from occupying too much memory and thus affecting server performance, the task coordination module can obtain the memory usage of the data download service at preset intervals. If the memory usage is greater than the preset memory threshold, the data download service can be restarted to release memory resources.
[0135] Exemplarily, the task coordination module may monitor the memory usage every ten seconds, and when the memory usage exceeds 500M, restart the data download service by restarting the process.
[0136] Further, such as Figure 7 As shown, the process of restarting the data download service by restarting the process includes:
[0137] S701: The restart process creates a first marking file in a library of files to be downloaded.
[0138] S702: When the task coordination module detects the first marker file, the currently running task is taken as the last task, and after the currently running task is completed, the first marker file is modified to a second marker file.
[0139] S703: When the restart process detects the second marker file, the data download service is restarted.
[0140] The currently running task may be a task being executed by the process of the file acquisition module.
[0141] When it is necessary to restart the data download service, the restart process can first create a first marker file in the file library to be downloaded, and the task coordination module can continuously detect the file library to be downloaded to determine whether the file library to be downloaded contains the first marker file. When the task coordination module detects the first marker file, the task executed by the process in the ongoing file acquisition module can be used as the last task, and when the currently running task ends, the first marker file is modified to the second marker file. When the restart process detects the second marker file, the data download service can be started after stopping the data download service to complete the service restart.
[0142] Optionally, modifying the first marking file to the second marking file may be modifying an identifier of the marking file, for example, modifying a stop1 tag of the marking file to a stop2 tag.
[0143] In the embodiment of the present application, restarting the data download service through the above-mentioned restart strategy can ensure that no file loss occurs during the restart process, and restarting the service when it occupies too much memory can also release memory resources in time and reduce the impact on server performance.
[0144] As a possible implementation method, the present application can also monitor the disk usage of the to-be-downloaded file library and dynamically adjust the files in the to-be-downloaded file library, such as Figure 8 As shown, specifically including:
[0145] S801. The task coordination module obtains the disk usage of the file library to be downloaded.
[0146] The disk usage rate of the to-be-downloaded file library may be the usage rate of the disk where the extended event module file directory is located.
[0147] S802: If the disk usage is greater than a preset disk threshold, the task coordination module determines the file capacity of the data file in the file library to be downloaded.
[0148] S803: If the file capacity is greater than a preset capacity threshold, the task coordination module determines and deletes at least one target data file.
[0149] Optionally, the file capacity of the data files in the file library to be downloaded may be the capacity of the related files under the extended event module directory.
[0150] If the disk usage is greater than a preset disk threshold, the task coordination module may further count the capacity of the data file and the number of data files. When the file capacity is greater than the preset capacity threshold, at least one target data file may be deleted.
[0151] The target data file may be the data file with the earliest creation time in the to-be-downloaded file library.
[0152] Exemplarily, the task coordination module can monitor the usage rate of the disk where the extended event module file directory is located. When the disk usage rate is greater than 90%, the capacity and number of files related to the extended event module in the directory are counted. When the file capacity is greater than 100G, the 20 historical files with the earliest creation time are deleted and cleaned up.
[0153] Fig. 9 A schematic diagram of the structure of a database server 90 provided in an embodiment of the present application is shown, comprising: a processor 901, a storage medium 902 and a bus 903, wherein the storage medium 902 stores machine-readable instructions executable by the processor 901, and when the electronic device runs the data collection method in the embodiment, the processor 901 communicates with the storage medium 902 via the bus 903, and the processor 901 executes the machine-readable instructions, and the processor 901 executes the preamble of the method item to execute the steps of the above-mentioned data collection method.
[0154] An embodiment of the present application further provides a computer-readable storage medium, on which a computer program is stored. The computer program is executed when a processor is running, and the processor executes the steps of the above-mentioned data acquisition method.
[0155] In the embodiment of the present application, the computer program can also execute other machine-readable instructions when run by the processor to execute other methods described in the embodiment. For the specific execution method steps and principles, please refer to the description of the embodiment, which will not be repeated here.
[0156] In the embodiments provided in the present application, it should be understood that the disclosed method can be implemented in other ways. The database server embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some communication interface, device or unit, which may be electrical, mechanical or other forms.
[0157] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0158] In addition, each functional unit in the embodiments provided in the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0159] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0160] It should be noted that similar numbers and letters represent similar items in the following figures. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. In addition, the terms "first", "second", "third", etc. are only used to distinguish the description and are not to be understood as indicating or implying relative importance.
[0161] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present application, which are used to illustrate the technical solutions of the present application, rather than to limit them. The protection scope of the present application is not limited thereto. Although the present application is described in detail with reference to the above-mentioned embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-mentioned embodiments within the technical scope disclosed in the present application, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application. They should all be included in the protection scope of the present application. Therefore, the protection scope of the present application shall be based on the protection scope of the claims.
Claims
1. A data collection method, characterized in that: Applied to a database server, a database instance and a data download service are deployed on the database server, an extended event module is deployed on the database instance, the data download service includes: a task coordination module and a file acquisition module, the file acquisition module includes multiple processes, and the method includes: The task coordination module determines the target collection strategy of the extended event module according to the number of requests for the database instance and the resource utilization rate of the database server within a preset period of time; The extended event module collects the indicator data of the database instance according to the target collection strategy and the predefined event, and stores the collected indicator data in the file library to be downloaded; The task coordination module determines the number of concurrent processes of the file acquisition module according to the current amount of data in the file library to be downloaded and the resource utilization rate of the database server, and starts one or more target processes, and downloads the data in the file library to be downloaded to the parsing server for parsing through each of the target processes; Before the extended event module collects the indicator data of the database instance according to the target collection strategy and the predefined event, the extended event module further includes: According to the configuration instruction of the user, determining at least one predefined event corresponding to the extended event module and the identification of the target indicator to be collected, wherein the at least one predefined event includes: a remote procedure call completion event, a batch completion event, and a statement completion event in a stored procedure; The extended event module collects the indicator data of the database instance according to the target collection strategy and the predefined event, including: The extended event module collects the indicator data of each target indicator in the database instance based on the predefined event according to the target collection strategy.
2. The method according to claim 1, characterized in that The task coordination module determines the target collection strategy of the extended event module according to the number of requests for the database instance and the resource utilization rate of the database server within a preset period of time, including: If the number of requests is less than or equal to a preset request threshold, and the resource usage rate is less than or equal to a first preset resource threshold, determining that the target collection strategy of the extended event module is a first collection strategy, in which data loss is not allowed; If the number of requests is greater than a preset request threshold, and the resource usage rate is greater than a first preset resource threshold, the target collection strategy of the extended event module is determined to be a second collection strategy, in which data loss is allowed.
3. The method according to claim 1, characterized in that: The task coordination module determines the number of concurrent processes of the file acquisition module according to the current amount of data in the to-be-downloaded file library and the resource usage rate of the database server, including: If the resource usage rate is less than a first preset resource threshold, the number of concurrent processes is determined according to the current data volume and the resource usage rate.
4. The method according to claim 1, characterized in that: The data in the to-be-downloaded file library is stored in the form of data files; The step of transmitting the data in the to-be-downloaded file library to the parsing server for parsing through each of the target processes includes: The target process obtains a target data file from the to-be-downloaded file library, and compresses the target data file to obtain a compressed file; The target process transmits the compressed file to the parsing server for parsing.
5. The method according to claim 4, characterized in that The target process obtains a target data file from the to-be-downloaded file library, and compresses the target data file to obtain a compressed file, including: The target process obtains a target data file in a first preset format according to the file creation time; The target process modifies the target data file into a second preset format, compresses the modified file to obtain a compressed file, and deletes the target data file.
6. The method according to claim 4, characterized in that The target process transmits the compressed file to the parsing server for parsing, including: The target process determines whether the current number of tokens is greater than the number of tokens required for the compressed file. If so, the compressed file is downloaded to the parsing server. If not, tokens are continuously requested until the current number of tokens is greater than the number of tokens required for the compressed file, and the compressed file is then downloaded to the parsing server.
7. The method according to any one of claims 1 to 6, characterized in that: The method further comprises: The task coordination module obtains the memory usage of the data download service based on a preset period; If the memory usage is greater than a preset memory threshold, the data download service is restarted by restarting the process.
8. The method according to claim 7, characterized in that The process of restarting the data download service by restarting the process includes: The restart process creates a first marking file in the to-be-downloaded file library; When the task coordination module detects the first marking file, the currently running task is regarded as the last task, and after the currently running task is completed, the first marking file is modified to the second marking file; When the restart process detects the second marker file, the data download service is restarted.
9. The method according to claim 1, characterized in that: The method further comprises: The task coordination module obtains the disk usage rate of the file library to be downloaded; If the disk usage rate is greater than a preset disk threshold, the task coordination module determines the file capacity of the data file in the to-be-downloaded file library; If the file capacity is greater than a preset capacity threshold, the task coordination module determines and deletes at least one target data file.
10. A database server, characterized in that: include: A processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the storage medium communicate via the bus, and the processor executes the machine-readable instructions to perform the steps of the data acquisition method as described in any one of claims 1 to 9.
11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data acquisition method according to any one of claims 1 to 9 are executed.
