Method and apparatus for optimizing batch writing of database logs
By adaptively adjusting the delay time of database log writing, the performance bottleneck problem caused by the fixed delay time in the existing technology is solved, and the database performance is maximized under high concurrent business.
Patent Information
- Application Number
- PCT/CN2023/085166
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-10
- Filing Date
- 2023-03-30
- Publication Date
- 2024-09-19
AI Technical Summary
In the existing technology, the writing delay time of the database REDO log is a preset fixed time and cannot be adjusted according to the disk performance, resulting in poor performance under high-concurrency services and the inability to maximize disk performance.
By generating multiple different reference delay times, calculate the writing speed under each delay time, iteratively select the optimal delay time, and adaptively adjust the delay time to maximize the writing speed of the database log.
It realizes dynamic adjustment of delay time based on disk performance, maximizes the writing speed of database logs, optimizes database performance, and adapts to different business load conditions.
Smart Images

Figure CN2023085166_19092024_PF_FP_ABST
Abstract
Description
Method and device for optimizing database log batch writing Technical Field
[0001] The present invention mainly relates to the field of data processing, and in particular to a method for optimizing batch writing of database logs. Background Art
[0002] REDO logs, commonly referred to as redo logs, are a mechanism for recovering data after a database failure and restart. Typically, transactions are committed after the REDO log is written to a storage device, and modified pages are asynchronously persisted by a background thread. If the database crashes, the REDO logs are replayed upon restart to restore the modified pages to their pre-crash state, ensuring that transactions are not lost. REDO logs are typically written sequentially. Before the previous REDO log is persisted, the next REDO log entry is blocked, and subsequent transaction submissions are also blocked. Therefore, writing REDO logs is often a performance bottleneck for databases. In highly concurrent workloads, if a REDO write is performed for each transaction submission, the I / O (input and output) frequency will be high, resulting in poor performance. Therefore, most databases implement an optimization: while REDO logs are being written to storage, the transaction logs submitted during this period are merged in memory. Once the current REDO write is complete, the merged transaction logs are written to the REDO logs at once, achieving batch writes. Once the write is complete, the batch of transactions can be committed simultaneously. This batch log write method reduces the number of REDO writes and improves performance. However, this method of passively accumulating transaction logs doesn't maximize REDO write performance. If you delay writing the next batch of REDOs after the current REDO write completes to allow more transaction logs to accumulate, you can further reduce the number of REDO write I / Os. This delayed REDO write method can further improve performance when the delay time is appropriate.
[0003] However, if the delay is too long, more transaction logs can be written at once, but the commit of these transactions will take longer, which will actually degrade performance. If the delay is too short, the number of IO operations will increase and performance will not be optimal, especially on devices with high IO latency. Existing technologies implement delays at a fixed, pre-set time and cannot adjust based on disk performance to maximize the performance of REDO disks.
[0004] Summary of the Invention
[0005] In view of the above problems, the present application is proposed to provide a method and apparatus for optimizing database log batch writing that overcomes the above problems or at least partially solves the above problems, including:
[0006] A method for optimizing database log batch writing, comprising:
[0007] When writing a database log, generating at least three first reference delay times with different values; and calculating a first writing speed of the database log at each of the first reference delay times;
[0008] setting the first reference delay time with the fastest first writing speed as the current optimal reference delay time;
[0009] generating at least two second reference delay times with different values according to the current optimal reference delay time and the first reference delay time, and calculating a second writing speed of the database log under the second reference delay time;
[0010] Setting the second reference delay time with the fastest second writing speed as the current optimal reference delay time;
[0011] The current optimal delay time is set as the delay time for writing into the database log, and the current optimal reference delay time is continuously iterated.
[0012] Furthermore, when writing a database log, generating at least three first reference delay times with different values; and calculating a first writing speed of the database log at each of the first reference delay times, includes:
[0013] When writing a database log, randomly generating at least three first reference delay times with different values;
[0014] Writing the database log according to the first reference delay time;
[0015] Waiting for at least 1 second at each of the first reference delay times and obtaining the size of the database log;
[0016] The first writing speed is calculated according to the size of the database log and the waiting time.
[0017] Furthermore, the step of generating at least two second reference delay times having different values based on the current optimal reference delay time and the first reference delay time and continuing to calculate a second write speed of the database log under the second reference delay time includes:
[0018] Generating at least two second reference delay times with different values based on the current optimal reference delay time, ensuring that all reference delay time values are different;
[0019] The writing speed of the database log under the second reference delay time is calculated.
[0020] Furthermore, the step of generating at least two second reference delay times with different values based on the current optimal reference delay time to ensure that all reference delay time values are different includes:
[0021] Second reference delay times with different values are generated so that the value of the current optimal delay time is at a middle position among all the second reference delay times.
[0022] Furthermore, the writing speed is an average writing speed.
[0023] Furthermore, the minimum reference delay time interval is 100 nanoseconds.
[0024] Furthermore, the minimum reference delay time is 0.
[0025] A device for optimizing database log batch writing, wherein the device for optimizing database log batch writing implements the steps of any of the above-mentioned methods for optimizing database log batch writing, including:
[0026] A first reference delay time determination module is configured to generate at least three first reference delay times with different values when writing a database log; and calculate a first writing speed of the database log at each of the first reference delay times;
[0027] A first reference delay time optimal selection module, configured to set the first reference delay time having the fastest first writing speed as the current optimal reference delay time;
[0028] a second reference delay time determination module, which generates at least two second reference delay times with different values according to the current optimal reference delay time and the first reference delay time, and calculates a second write speed of the database log under the second reference delay time;
[0029] A second reference delay time optimal selection module, configured to set the second reference delay time having the fastest second writing speed as the current optimal reference delay time;
[0030] The iteration module is configured to set the current optimal delay time as the delay time for writing into the database log, and to continue iterating the current optimal reference delay time.
[0031] An electronic device comprises a processor, a memory, and a computer program stored in the memory and capable of running on the processor, wherein the computer program, when executed by the processor, implements the steps of any one of the above-mentioned methods for optimizing database log batch writing.
[0032] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of any one of the above-mentioned methods for optimizing database log batch writing.
[0033] This application has the following advantages:
[0034] In an embodiment of the present application, in response to the shortcoming in the prior art that database writing can only be performed through a preset delay time, the present application provides a database log writing method that adaptively adjusts the delay time to maximize disk performance, specifically: when writing a database log, generate at least 3 first reference delay times with different values; and calculate the first writing speed of the database log at each first reference delay time; set the first reference delay time with the fastest first writing speed as the current optimal reference delay time; generate at least 2 second reference delay times with different values based on the current optimal reference delay time and the first reference delay time, and calculate the second writing speed of the database log at the second reference delay time; set the second reference delay time with the fastest second writing speed as the current optimal reference delay time; set the current optimal delay time as the delay time to write the database log, and continue to iterate the current optimal reference delay time. The present application optimizes the writing of the database log by adaptively adjusting the delay time to maximize the disk performance and maximize the database log writing speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] In order to more clearly illustrate the technical solution of the present application, the following is a brief introduction to the drawings required for the description of the present application. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0036] FIG1 is a flowchart of a method for optimizing batch writing of database logs provided by an embodiment of the present application;
[0037] FIG2 is a schematic diagram of the module structure of an apparatus for optimizing batch writing of database logs provided in one embodiment of the present application;
[0038] FIG3 is a flowchart of a method for optimizing batch writing of database logs provided in an embodiment of the present application;
[0039] FIG4 is a schematic structural diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0040] To make the objectives, features, and advantages of this application more readily apparent, the present application is further described below in conjunction with the accompanying drawings and specific embodiments. It is apparent that the embodiments described are only a portion of the embodiments of this application, not all of them. All other embodiments derived by persons of ordinary skill in the art based on the embodiments in this application without inventive effort are also within the scope of protection of this application.
[0041] By analyzing the existing technology, the inventors found that delaying for a period of time before writing REDO to the storage device can accumulate more transaction logs and reduce the number of IO times. By adjusting the delay time, the optimal number of single transaction log accumulation and IO times can be found to achieve the best overall write rate.
[0042] It should be noted that, referring to the flowchart in Figure 3, after the database is started, m reference delay times T1, T2, ..., Tm are initialized, where m is at least 3, and each reference delay time is initialized to a different value, which can be randomly initialized or arithmetic initialization. The iterative execution begins, and the specific steps of each round are:
[0043] Set the current REDO delay time to T1, and record the total REDO size at this time, wait for a while, get the current REDO total size, calculate the average REDO write speed during this period and record it as S1. Then set the current REDO delay to T2, and record the total REDO size at this time, wait for a while, get the current REDO total size, calculate the average REDO write speed during this period and record it as S2. Repeat this cycle until the delay time is set to Tm and Sm is calculated. Sort the counted REDO write speeds S1, S2, ..., Sm and find the largest Sk, whose corresponding delay time is Tk. Tk is the optimal value among these m reference delay times. Keep this delay time and adjust other reference delay times according to Tk.
[0044] After adjusting the reference delay, proceed to the next iteration. After multiple iterations, T1, T2, ..., Tm will stabilize with minimal differences, and each reference delay will approach the optimal delay. In each iteration, the actual REDO delay traverses T1, T2, ..., Tm, so when reaching a steady state, the REDO write speed approaches the optimal value.
[0045] The iterative process approaches the optimal delay time and applies the optimal delay time at the same time. When the business changes, the optimal delay time can also change rapidly accordingly. The application and calculation of the delay time are performed synchronously. Therefore, in theory, the iteration will not stop, but will only stabilize. When it stabilizes, all reference delay times will be close to the optimal delay time.
[0046] 1 , a method for optimizing database log batch writing provided by an embodiment of the present application is shown;
[0047] The method comprises:
[0048] S110: When writing a database log, generating at least three first reference delay times with different values; and calculating a first writing speed of the database log at each of the first reference delay times;
[0049] S120: setting the first reference delay time with the fastest first writing speed as the current optimal reference delay time;
[0050] S130: Generate at least two second reference delay times with different values based on the current optimal reference delay time and the first reference delay time, and calculate a second write speed of the database log under the second reference delay time;
[0051] S140, setting the second reference delay time with the fastest second writing speed as the current optimal reference delay time;
[0052] S150: Set the current optimal delay time as the delay time to write into the database log, and continue to iterate the current optimal reference delay time.
[0053] In an embodiment of the present application, in response to the shortcoming in the prior art that database writing can only be performed through a preset delay time, the present application provides a database log writing method that adaptively adjusts the delay time to maximize disk performance, specifically: when writing a database log, generate at least 3 first reference delay times with different values; and calculate the first writing speed of the database log at each first reference delay time; set the first reference delay time with the fastest first writing speed as the current optimal reference delay time; generate at least 2 second reference delay times with different values based on the current optimal reference delay time and the first reference delay time, and calculate the second writing speed of the database log at the second reference delay time; set the second reference delay time with the fastest second writing speed as the current optimal reference delay time; set the current optimal delay time as the delay time to write the database log, and continue to iterate the current optimal reference delay time. The present application optimizes the writing of the database log by adaptively adjusting the delay time to maximize the disk performance and maximize the database log writing speed.
[0054] Next, a method and apparatus for optimizing database log batch writing in this exemplary embodiment will be further described.
[0055] As described in step S110 above, referring to the flow chart of FIG3 , when writing a database log, at least three first reference delay times with different values are generated; and a first writing speed of the database log at each of the first reference delay times is calculated.
[0056] It should be noted that the first reference delay time can be an arithmetic initial value or a random initial value. It is necessary to ensure that the first reference delay times are different to reduce the number of adaptive delay time tests and facilitate the judgment of the final delay time.
[0057] In one embodiment of the present invention, the specific process of step S110 of "generating at least three first reference delay times with different values when writing a database log; and calculating the first writing speed of the database log at each of the first reference delay times" can be further explained in combination with the following description.
[0058] As described in the following steps, when writing a database log, randomly generate at least three first reference delay times with different values. Random generation can be completely random or arithmetic generation. The first reference delay time cannot exceed 1 second.
[0059] As described in the following steps, the database log is written according to the first reference delay time. All generated first reference delay times are tested in sequence.
[0060] As described in the following steps, at least one second is waited at each first reference delay time, and the size of the database log is obtained. Waiting for a period of time allows the database log to be written to a size sufficient to calculate an average speed at each first reference delay time. The average speed is used for comparison to reduce the possibility of special cases.
[0061] As described in the following steps, the first write speed is calculated based on the size of the database log and the waiting time. The average write speed can be calculated based on the waiting time and the size of the database log, which more intuitively expresses the suitability of the first reference delay time.
[0062] As described in step S120 , the first reference delay time at which the first writing speed is the fastest is set as the current optimal reference delay time.
[0063] In an embodiment of the present invention, the specific process of "setting the first reference delay time having the fastest first writing speed as the current optimal reference delay time" in step S120 may be further explained in combination with the following description.
[0064] It should be noted that the current optimal reference delay time is the one with the fastest writing speed among all current reference delay times. When the next round of iteration is carried out, the current optimal reference delay time can change as other reference delay times are generated. As the number of iterations increases, the fluctuation of the current optimal reference delay time should become smoother.
[0065] As described in step S130 , at least two second reference delay times with different values are generated according to the current optimal reference delay time and the first reference delay time, and a second writing speed of the database log under the second reference delay time is calculated.
[0066] It should be noted that the second reference delay time is generated according to the current optimal reference delay time, and the value of the current optimal reference delay time is kept in the middle as much as possible, and the gap between the maximum value and the minimum value is continuously reduced during iteration.
[0067] In one embodiment of the present invention, the specific process of "generating at least two second reference delay times with different values based on the current optimal reference delay time and the first reference delay time, and calculating the second writing speed of the database log under the second reference delay time" in step S130 can be further explained in combination with the following description.
[0068] As described in the following steps, at least two second reference delay times with different values are generated according to the current optimal reference delay time, ensuring that all reference delay time values are different.
[0069] It should be noted that the different values mean that the values of all reference times are different, the value of the second reference delay time is different from the value of the first reference delay time, and the same value does not appear to improve test efficiency.
[0070] As described in the following steps, the writing speed of the database log under the second reference delay time is calculated.
[0071] It should be noted that after the write speed calculation is completed, the current optimal reference delay time is updated according to the write speed, and the reference delay time with the fastest write speed is set as the current optimal reference delay time.
[0072] In an embodiment of the present invention, the specific process of "generating a second reference delay time with different values according to the current optimal reference delay time to ensure that all reference delay time values are different" can be further explained in combination with the following description.
[0073] As described in the following steps, a second reference delay time with a different value is generated so that the value of the current optimal delay time is in the middle of the second reference delay time.
[0074] In a specific implementation, m reference delay times are set, and the current optimal reference delay time Tk is found. All reference delay times are sorted. In the ascending order of T1, T2, ..., Tk, ..., Tm, if Tk is positioned to the left, several larger delay times are removed and several smaller delay times are added; if Tk is positioned to the right, several smaller delay times are removed and several larger delay times are added; if Tk is positioned in the middle, the reference delay times on both sides are brought closer to Tk, but it is necessary to ensure that each reference delay has a minimum difference, and the reference delay times cannot have the same value.
[0075] As described in the above step S140, when the deviation between the current optimal reference delay time and the previous round of optimal reference delay time is greater than..., continue to obtain the current optimal reference delay time and generate a new reference delay time; when the deviation between the current optimal reference delay time and the previous round of optimal reference delay time is less than or equal to..., set the current optimal reference delay time as the delay time, and the writing speed of the database log is the optimal value.
[0076] In one embodiment of the present invention, the specific process of step S140, "when the deviation between the current optimal reference delay time and the previous optimal reference delay time is greater than ..., continuing to obtain the current optimal reference delay time and generating a new reference delay time; when the deviation between the current optimal reference delay time and the previous optimal reference delay time is less than or equal to ..., setting the current optimal reference delay time as the delay time, and the database log writing speed as the optimal value" can be further explained in combination with the following description.
[0077] In one specific implementation, three first reference delay times are selected and recorded: T1, T2, and T3, initialized to 0 nanoseconds, 100 nanoseconds, and 200 nanoseconds, respectively. Three average REDO write speeds: S1, S2, and S3 are also recorded and initialized to 0. The REDO delay time is initialized to T1. After the database is started, a background thread begins running. At regular intervals, the average REDO write speed for that period is calculated based on the total amount of REDO logs written during that period. In each iteration, the average speed calculation is performed three times, and the reference delay time is adjusted once. Here, N is a natural number representing the iteration number, and its initial value is 0. After the 3N+1th calculation of the average REDO write speed, the average write speed is assigned to S1, and the REDO delay time is set to T2. After the 3N+2th calculation of the average REDO write speed, the average write speed is assigned to S2, and the REDO delay time is set to T3. After calculating the average REDO write speed for the 3N+3th time, assign the average write speed to S3 and make a delay adjustment. The specific adjustment method is:
[0078] If S2 is the largest, then T1 N+1 Update to (T1 N +T2 N ) / 2, T3 N+1 Updated to (T3 N +T2 N ) / 2, T2 N+1 Keep it as T2 N .
[0079] If S1 is the largest, then T2 N+1 Updated to T1 N , T3 N+1 Updated to T2 N , T1 N+1 Updated to T1 N -2*(T2 N -T1 N ).
[0080] If S3 is the largest, then T2 N+1 Updated to T3 N , T1 N+1 Updated to T2 N , T3 N+1 Updated to T3 N +2*(T3 N -T2 N ).
[0081] After the above adjustments, T1 may be negative, in which case you need to change T1 to 0. In addition, after each adjustment, the difference between T1, T2, and T3 should be at least 100 nanoseconds. If this is not the case, increase T2 or T3 appropriately to make the difference 100 nanoseconds.
[0082] After T1, T2, and T3 are adjusted, the REDO delay time is set to the new T1 and the next cycle is carried out. In each cycle, T2 is set to the delay time with the highest average REDO write speed. When T2 tends to be stable, T2 is the optimal delay time. When T2 is at the optimal delay time, T1 and T3 will move closer to T2, and the final difference is 100 nanoseconds. Since the delay time of 100 nanoseconds is small enough, the gap between S1, S2, and S3 is very small. It can be approximately considered that S1, S2, and S3 have reached the maximum REDO write speed. Therefore, this adaptive adjustment method can eventually converge to the optimal solution, and the convergence speed of this adjustment is very fast, because each adjustment is exponentially adjusted by a multiple of 2. After less than 10 cycles, it can converge to maximize the REDO write speed.
[0083] In an embodiment of the present application, the write speed is an average write speed.
[0084] In one embodiment of the present application, the minimum reference delay time interval is 100 nanoseconds.
[0085] In an embodiment of the present application, the minimum reference delay time is 0.
[0086] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0087] 2 , a device for optimizing database log batch writing provided by an embodiment of the present application is shown;
[0088] Specifically include:
[0089] A first reference delay time determination module 210 is configured to generate at least three first reference delay times with different values when writing a database log; and calculate a first writing speed of the database log at each of the first reference delay times;
[0090] A first reference delay time optimal selection module 220, configured to set the first reference delay time having the fastest first writing speed as the current optimal reference delay time;
[0091] a second reference delay time determination module 230 that generates at least two second reference delay times with different values based on the current optimal reference delay time and the first reference delay time, and calculates a second write speed of the database log under the second reference delay time;
[0092] A second reference delay time optimal selection module 240 is configured to set the second reference delay time having the fastest second writing speed as the current optimal reference delay time;
[0093] The iteration module 250 is configured to set the current optimal delay time as the delay time for writing into the database log, and to continue iterating the current optimal reference delay time.
[0094] In one embodiment of the present invention, the first reference delay time determining module 210 includes:
[0095] A generating submodule, configured to randomly generate at least three first reference delay times with different values when writing a database log;
[0096] a writing submodule, configured to write the database log according to the first reference delay time;
[0097] an acquisition submodule, configured to wait for at least 1 second at each of the first reference delay times and acquire the size of the database log;
[0098] The write speed calculation submodule is used to calculate the write speed according to the size of the database log and the waiting time.
[0099] In one embodiment of the present invention, the second reference delay time determination module 230 includes:
[0100] A second reference delay time generating submodule, configured to generate at least two second reference delay times with different values based on the current optimal reference delay time, to ensure that all reference delay time values are different;
[0101] The writing speed calculation submodule is used to calculate the writing speed of the database log under the second reference delay time.
[0102] In one embodiment of the present invention, the second reference delay time generating submodule includes:
[0103] The current optimal reference delay time median submodule is used to generate a second reference delay time with a different value, so that the value of the current optimal delay time is in the middle position of the second reference delay time.
[0104] In one embodiment of the present invention, the method further includes: a writing speed calculation module, configured to set the writing speed as an average writing speed.
[0105] In one embodiment of the present invention, the method further includes: a reference delay time interval setting module, configured to set the reference delay time interval to a minimum of 100 nanoseconds.
[0106] In one embodiment of the present invention, the system further comprises: a reference delay time minimum value setting module, configured to set the reference delay time to a minimum of 0.
[0107] 4 , a computer device for optimizing a method for batch writing database logs according to the present invention is shown, which may specifically include the following:
[0108] The computer device 12 is a general-purpose computing device. The components of the computer device 12 may include but are not limited to: one or more processors or processing units 16, a system memory 28, and a bus 18 connecting different system components (including the system memory 28 and the processing unit 16).
[0109] The bus 18 represents one or more of several types of bus 18 structures, including a memory bus 18 or memory controller, a peripheral bus 18, an accelerated graphics port, a processor, or a local bus 18 that utilizes any of a variety of bus 18 architectures. Examples of such architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus 18, a Micro Channel Architecture (MAC) bus 18, an Enhanced ISA bus 18, an Audio Video Electronics Standards Association (VESA) local bus 18, and a Peripheral Component Interconnect (PCI) bus 18.
[0110] The computer device 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the computer device 12, including volatile and non-volatile media, removable and non-removable media.
[0111] System memory 28 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 30 and / or cache memory 32. Computer device 12 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 34 may be configured to read and write to non-removable, non-volatile magnetic media (commonly referred to as a "hard drive"). Although not shown in FIG. 4 , a magnetic disk drive may be provided for reading and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), as well as an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media). In these cases, each drive may be connected to bus 18 via one or more data media interfaces. The memory may include at least one program product having a set (e.g., at least one) of program modules 42 configured to perform the functions of various embodiments of the present invention.
[0112] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in a memory. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules 42, and program data, each of which, or some combination thereof, may include an implementation of a network environment. The program modules 42 generally perform the functions and / or methods of the embodiments described herein.
[0113] The computer device 12 can also communicate with one or more external devices 14 (e.g., a keyboard, pointing device, display 24, camera, etc.), one or more devices that enable medical personnel to interact with the computer device 12, and / or any device that enables the computer device 12 to communicate with one or more other computing devices (e.g., a network card, modem, etc.). Such communication can occur via an input / output (I / O) interface 22. Furthermore, the computer device 12 can communicate with one or more networks (e.g., a local area network (LAN)), a wide area network (WAN), and / or a public network (e.g., the Internet) via a network adapter 20. As shown, the network adapter 20 communicates with the other modules of the computer device 12 via a bus 18. It should be understood that, although not shown in FIG. 4 , other hardware and / or software modules can be used in conjunction with the computer device 12, including, but not limited to, microcode, device drivers, redundant processing units 16, external disk drive arrays, RAID systems, tape drives, and data backup storage systems 34.
[0114] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing a method for optimizing database log batch writing provided by an embodiment of the present invention.
[0115] That is, when the processing unit 16 executes the program, it is implemented as follows: when writing a database log, it generates at least three first reference delay times with different values; and calculates a first writing speed of the database log at each of the first reference delay times;
[0116] setting the first reference delay time with the fastest first writing speed as the current optimal reference delay time;
[0117] generating at least two second reference delay times with different values according to the current optimal reference delay time and the first reference delay time, and calculating a second writing speed of the database log under the second reference delay time;
[0118] Setting the second reference delay time with the fastest second writing speed as the current optimal reference delay time;
[0119] The current optimal delay time is set as the delay time for writing into the database log, and the current optimal reference delay time is continuously iterated.
[0120] In an embodiment of the present invention, the present invention further provides a computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, the method for optimizing database log batch writing provided in all embodiments of the present application is implemented:
[0121] That is, when the program is executed by the processor, it is implemented to: generate at least three first reference delay times with different values when writing to the database log; and calculate the first writing speed of the database log under each of the first reference delay times;
[0122] setting the first reference delay time with the fastest first writing speed as the current optimal reference delay time;
[0123] generating at least two second reference delay times with different values according to the current optimal reference delay time and the first reference delay time, and calculating a second writing speed of the database log under the second reference delay time;
[0124] Setting the second reference delay time with the fastest second writing speed as the current optimal reference delay time;
[0125] The current optimal delay time is set as the delay time for writing into the database log, and the current optimal reference delay time is continuously iterated.
[0126] Any combination of one or more computer-readable media may be used. A computer-readable medium may be a computer signal medium or a computer-readable storage medium. A computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of computer-readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0127] A computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal may take a variety of forms, including, but not limited to, electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can transmit, propagate, or transport a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0128] The computer program code for performing the operations of the present invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the medical staff computer, partially on the medical staff computer, as a separate software package, partially on the medical staff computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer can be connected to the medical staff computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, through the Internet using an Internet service provider). The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can be referenced to each other.
[0129] Although preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they become aware of the basic inventive concepts. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present invention.
[0130] Finally, it should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or terminal device. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or terminal device that includes the element.
[0131] The above is a detailed introduction to a method and device for optimizing batch writing of database logs provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A method for optimizing database log batch writing, characterized in that: include: When writing a database log, generating at least three first reference delay times with different values; and calculating a first writing speed of the database log at each of the first reference delay times; Setting the first reference delay time with the fastest first writing speed as the current optimal reference delay time; generating at least two second reference delay times with different values according to the current optimal reference delay time and the first reference delay time, and calculating a second writing speed of the database log under the second reference delay time; Setting the second reference delay time with the fastest second writing speed as the current optimal reference delay time; The current optimal delay time is set as the delay time to write the database log, and the current optimal reference delay time is continuously iterated.
2. The method according to claim 1, characterized in that When writing a database log, generating at least three first reference delay times with different values; and calculating a first writing speed of the database log at each of the first reference delay times, comprises: When writing a database log, randomly generating at least three first reference delay times with different values; Writing the database log according to the first reference delay time; Waiting for at least 1 second at each of the first reference delay times, and obtaining the size of the database log; The first writing speed is calculated according to the size of the database log and the waiting time.
3. The method according to claim 1, characterized in that The step of generating at least two second reference delay times with different values according to the current optimal reference delay time and the first reference delay time and continuing to calculate the second writing speed of the database log under the second reference delay time includes: Generating at least two second reference delay times with different values according to the current optimal reference delay time, so as to ensure that all reference delay time values are different; The writing speed of the database log under the second reference delay time is calculated.
4. The method according to claim 3, characterized in that The step of generating at least two second reference delay times with different values according to the current optimal reference delay time to ensure that all reference delay time values are different includes: Second reference delay times with different values are generated so that the value of the current optimal delay time is at a middle position among all the second reference delay times.
5. The method according to claim 1, characterized in that The writing speed is an average writing speed.
6. The method according to claim 1, characterized in that The minimum reference delay time interval is 100 nanoseconds.
7. The method according to claim 1, characterized in that The minimum reference delay time is 0.
8. A device for optimizing batch writing of database logs, characterized in that: The optimized database log batch writing device implements the steps of the method for optimizing database log batch writing according to any one of claims 1 to 7, including: A first reference delay time determination module is used to generate at least three first reference delay times with different values when writing a database log; and calculate a first writing speed of the database log at each of the first reference delay times; A first reference delay time optimal selection module, used for setting the first reference delay time with the fastest first writing speed as the current optimal reference delay time; a second reference delay time determination module, which generates at least two second reference delay times with different values according to the current optimal reference delay time and the first reference delay time, and calculates a second writing speed of the database log under the second reference delay time; A second reference delay time optimal selection module, used for setting the second reference delay time with the fastest second writing speed as the current optimal reference delay time; The iteration module is used to set the current optimal delay time as the delay time to write the database log, and continue to iterate the current optimal reference delay time.
9. An electronic device, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and capable of running on the processor, wherein when the computer program is executed by the processor, the steps of the method for optimizing batch writing of database logs as described in any one of claims 1 to 7 are implemented.
10. 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 method for optimizing batch writing of database logs according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Log data writing method and log system
CN102810050A
Data transmitting method and time delay module
CN102890663A
Method and system for optimizing transaction data storage in non-volatile memory
CN104778126A
Automatically changing a database system's redo transport mode to dynamically adapt to changing workload and network conditions
US20080086516A1
Adaptive high-performance database redo log synchronization
US20140258223A1
