A method and apparatus for data buffering
By dynamically adjusting the buffer threshold, the problem of data not being generated in a fixed size is solved, ensuring sufficient data buffering within the data reading cycle, adapting to periodic and random delays, and improving data reading efficiency.
Patent Information
- Application Number
- CN202110258413.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-03-10
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2041-03-10
AI Technical Summary
Existing technologies cannot effectively solve the problem of data not being generated and buffered in a fixed size, which causes the reading module to be unable to read enough data in a timely manner.
By acquiring data reading and generation cycle quantities, setting a dynamic difference set, and dynamically adjusting the buffer threshold to ensure sufficient data buffering within the data reading cycle, including setting the first and second data buffer thresholds, and calculating the maximum dynamic difference as the target buffer threshold during the data reading cycle.
Ensure sufficient data buffering during the data reading cycle to avoid insufficient data reading, adapt to the periodicity and random delays of data generation, and improve data reading efficiency.
Smart Images

Figure CN112788156B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer technology, and in particular to a method and apparatus for data buffering. Background Technology
[0002] In the field of computer science, we often encounter the following problem: due to differences in data generation and reading cycles, phase differences, and random delays in data generation, data generation and reading are often out of sync. To avoid the frequent occurrence of the reading module being unable to read enough data, a common practice is to buffer the data before starting to read it. Most existing models for handling this situation are designed for scenarios where data is generated and read in fixed-size packets, but do not address the scenario where each data generation is of a variable size. Summary of the Invention
[0003] This application provides a data buffering method and apparatus to solve the problem that the prior art cannot solve the problem of data not being generated and buffered in a fixed size.
[0004] Firstly, to achieve the above objectives, this application provides a data buffering method, the method comprising:
[0005] Obtain a data read request, wherein the data read request includes the total amount of data to be read, the data read cycle value, and the data read cycle length;
[0006] Acquire the data generation cycle value and the data generation cycle quantity;
[0007] If the data generation cycle amount can be obtained, then the data is buffered according to the first data buffer threshold, which is the sum of the data generation cycle amount and the data reading cycle amount;
[0008] Data reading begins after the total amount of the first data generated during the data reading cycle is equal to or greater than the first data buffer threshold.
[0009] Furthermore, after obtaining the data buffer cycle value and the data buffer cycle size, the process also includes:
[0010] If the data generation cycle cannot be obtained, the data is buffered according to the second data buffer threshold, which is twice the data reading cycle.
[0011] Data reading begins after the total amount of the second data generated during the data reading cycle is equal to or greater than the first data buffer threshold.
[0012] Furthermore, the data buffering method further includes:
[0013] At each data reading cycle, the total amount of statistical data and the total amount of data read are generated, and a dynamic difference set is obtained.
[0014] Obtain the maximum dynamic difference in the set of dynamic differences.
[0015] Furthermore, after obtaining the maximum dynamic difference in the dynamic difference set, the method further includes:
[0016] When the remaining data volume is less than the data reading cycle volume, data buffering is performed again. The target buffering threshold corresponding to the data buffering is the larger of the maximum dynamic difference and the data reading cycle volume.
[0017] Furthermore, the step of performing data buffering again when the remaining data volume is less than the data reading cycle size also includes:
[0018] Data reading begins when the amount of remaining data counted during the data reading cycle is equal to or greater than the target buffer threshold.
[0019] Secondly, to achieve the above objectives, this application also provides a data buffering apparatus, the apparatus comprising:
[0020] The acquisition unit is used to acquire a data read request, which includes a total amount of data to be read, a data read cycle value, and a data read cycle length; and to acquire a data generation cycle value and a data generation cycle length.
[0021] A data buffer unit is configured to buffer data according to a first data buffer threshold if the data generation cycle amount can be obtained, wherein the first data buffer threshold is the sum of the data generation cycle amount and the data reading cycle amount;
[0022] The data reading unit is used to start reading data after the total amount of the first data generated is equal to or greater than the first data buffer threshold when the data reading cycle value is counted.
[0023] Furthermore, the data buffer unit is also used for:
[0024] If the data generation cycle cannot be obtained, the data is buffered according to the second data buffer threshold, which is twice the data reading cycle.
[0025] Data reading begins after the total amount of the second data generated during the data reading cycle is equal to or greater than the first data buffer threshold.
[0026] Furthermore, the acquisition unit is also used for:
[0027] At each data reading cycle, the total amount of statistical data and the total amount of data read are generated, and a dynamic difference set is obtained.
[0028] Obtain the maximum dynamic difference in the set of dynamic differences.
[0029] Furthermore, the data buffer unit is also used for:
[0030] When the remaining data volume is less than the data reading cycle volume, data buffering is performed again. The target buffering threshold corresponding to the data buffering is the larger of the maximum dynamic difference and the data reading cycle volume.
[0031] Furthermore, the data reading unit is also used for:
[0032] Data reading begins when the amount of remaining data counted at the data reading cycle value is equal to or greater than the target buffer threshold.
[0033] Thirdly, to achieve the above objectives, this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the data buffering methods in the first aspect.
[0034] Fourthly, to achieve the above objectives, this application provides a computer device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of any of the data buffering methods of the first aspect.
[0035] As can be seen from the above technical solutions, the data buffering method and apparatus provided in this application embodiment obtain a data read request, the data read request including a total data read amount, a data read cycle value, and a data read cycle quantity; obtain a data generation cycle value and a data generation cycle quantity; if the data generation cycle quantity can be obtained, buffer data according to a first data buffering threshold, the first data buffering threshold being the sum of the data generation cycle quantity and the data read cycle quantity; start data reading after the total first data generation amount counted at the data read cycle value is equal to or greater than the first data buffering threshold; if the data generation cycle quantity cannot be obtained, buffer data according to a second data buffering threshold, the second data buffering threshold being twice the data read cycle quantity; start data reading after the total second data generation amount counted at the data read cycle value is equal to or greater than the first data buffering threshold.
[0036] This application analyzes and concludes that data reading begins only when the buffered data volume is greater than or equal to the sum of the output D0 within a minimum positive cycle of data generation and the data read request D1 in a single session, thus ensuring that there will be no insufficient data to read. Even without prior knowledge of D0, the same effect can be achieved by statistically analyzing the maximum dynamic difference between the total output and read requests multiple times and using this maximum dynamic difference as the target buffer threshold. Finally, even if data output has random delays in addition to periodicity, this can be estimated by adding the maximum value of the "composite difference" (the maximum dynamic difference between the total output and read requests) to the delay.
[0037] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0038] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0039] Figure 1 A flowchart illustrating the data buffering method provided in the first embodiment of this application;
[0040] Figure 2 A flowchart illustrating a specific scenario provided in the first embodiment of this application;
[0041] Figure 3 A flowchart illustrating the data buffering method provided in the second embodiment of this application;
[0042] Figure 4 This is a schematic diagram of the structure of a data buffering device provided in an embodiment of this application. Detailed Implementation
[0043] The features and advantages of this application will become clearer and more explicit through the following detailed description.
[0044] The term “exemplary” as used herein means “serving as an example, embodiment, or illustration.” Any embodiment illustrated herein as “exemplary” is not necessarily to be construed as superior to or better than other embodiments. Although various aspects of embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless specifically indicated otherwise.
[0045] In the description of this application, it should be noted that the terms "upper," "lower," "inner," "outer," "front," "rear," "left," and "right," etc., indicate the orientation or positional relationship based on the orientation or positional relationship in the working state of this application, and are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation on this application. In addition, the terms "first," "second," "third," and "fourth" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0046] To address the aforementioned problems, this application provides a data buffering method and apparatus. Specific embodiments of this application are described in detail below with reference to the accompanying drawings.
[0047] Figure 1 A flowchart illustrating the data buffering method provided in the first embodiment of this application is shown below. Figure 1 As shown, the method includes steps S101 to S104.
[0048] S101: Obtain a data read request, the data read request including the total amount of data to be read, the data read cycle value, and the data read cycle length;
[0049] S102: Obtain the data generation cycle value and the data generation cycle amount;
[0050] S103: If the data generation cycle amount can be obtained, then buffer the data according to the first data buffer threshold, wherein the first data buffer threshold is the sum of the data generation cycle amount and the data reading cycle amount;
[0051] S104: Data reading begins after the total amount of the first data generated during the data reading cycle is greater than or equal to the first data buffer threshold.
[0052] The existing buffering schemes for generating and reading data packets of fixed size cannot be applied to situations where the size of the data generated each time is not fixed. This application proposes a technical solution that can solve the above problem.
[0053] In practice, it is assumed that data reading is performed at fixed time intervals T1, with a fixed data size D1. The data generation rate generally remains consistent with the reading rate. It is also assumed that data generation is periodic, with a minimum positive period of T0 and a data volume of D0 within one minimum positive period. Therefore, D0 / T0 = D1 / T1. This period refers to a time interval that is either left-open or right-closed, meaning the intervals do not overlap. Starting from a certain time t (excluding t itself), after t... 10 The first read request occurred after time t. 00a data block b is generated at time i ; after t 10 +T1, a second read request occurs, and after t 00 +t i+1 a data block b is generated. i+1 By analogy, starting observation from t 10 and denoting t 10 as t', from this moment onwards, D1 data read requests are generated every T1, with each data read request occurring at t' + j*T1. Let j*T1 = k*T0 + r, where 0 <= r < T0 and k >= 0. The total amount of data generated during the period (t', t' + j*T1) should be greater than or equal to k*D0 and less than or equal to (k+1)*D0, and the total data request amount j*D1 should satisfy: k*D0 <= j*D1 < (k+1)*D0.
[0054] Assume the total amount of data generated during the period (t', t' + j*T1) is d. Since this time duration is less than (k+1)*T0, d should be less than or equal to (k+1)*D0. Also, since this time duration is greater than or equal to k*T0, d should be greater than or equal to k*D0. Because j*D1 / j*T1 = k*D0 / k*T0, it follows that j*D1 = k*D0 * (j*T1 / k*T0). Since j*T1 = k*T0 + r, where 0 <= r < T0, j*T1 >= k*T0, further leading to j*T1 / k*T0 >= 1 and j*D1 >= k*D0. Meanwhile, since j*T1 < (k+1)*T0, we obtain j < (k+1)*(T0 / T1), further leading to j*D1 < (k+1)*(T0 / T1)*D1. And since D0 / T0 = D1 / T1, (T0 / T1)*D1 = D0, so j*D1 < (k+1)*D0.
[0055] Therefore, during the period (t', t' + j*T1), both the total amount of data generated and the total amount of data read requests fall within the range [k*D0, (k+1)*D0], so the difference between the total data read request amount and the total data generated amount should be less than or equal to D0.
[0056] Additionally, during the period (t, t'), the total data request amount is D1. If no data is generated during this period, i.e., the total data generated amount is 0, the maximum difference between the total data read request amount and the total data generated amount is D1. Thus, starting from time t (excluding time t itself), at any time when a data request is generated (i.e., the time point of the data generation cycle value), the difference between the total data read request amount and the total data generated amount should be less than D0 + D1. Due to the arbitrariness of t, at any time when a data request is generated, the difference between the total data read request amount and the total data generated amount should be less than D0 + D1.
[0057] Therefore, if the value of D0 can be determined, the first data buffer threshold can be set to D0+D1, and data reading can begin only after the total amount of data generated at a certain data reading cycle (the moment a data request is generated) is greater than or equal to D0+D1. Figure 1 The first embodiment shown. (First time)
[0058] Additionally, at each time a data request is generated, the remaining data volume is checked to see if it is less than the single output data volume. If it is, the data re-enters the buffer. Output only begins at the next data request when the total remaining data volume again equals or exceeds the first data buffer threshold. For example... Figure 2 As shown, the total amount of data requested is m*D1, the total amount of data generated is n*D0, the difference between the total amount of data requested and the total amount of data generated is recorded as mD1–nD0, the remaining total amount of data is >=D1+D0, and the output begins.
[0059] Figure 3 A flowchart illustrating a data buffering method provided in the second embodiment of this application is shown below. Figure 3 As shown, the method includes steps S101 to S106.
[0060] S101: Obtain a data read request, the data read request including the total amount of data to be read, the data read cycle value, and the data read cycle length;
[0061] S102: Obtain the data generation cycle value and the data generation cycle amount;
[0062] S105: If the data generation cycle cannot be obtained, then buffer the data according to the second data buffer threshold, where the second data buffer threshold is twice the data reading cycle.
[0063] S106: Data reading begins after the total amount of the second data generated during the data reading cycle is equal to or greater than the second data buffer threshold.
[0064] Continuing with the above assumptions, if the value of D0 cannot be determined in practice, since the difference between the total amount of data generated and the total amount of data requested always varies within a certain range at any given moment, and since computer-generated data is in bits and is discrete, according to the "pigeonhole principle," after a finite number of statistical iterations, the maximum value (maximum dynamic difference) of the difference between the total amount of data generated and the total amount of data requested can be reached. Therefore, recording the difference between the total amount of data generated and the total amount of data requested at each moment of a data request, calculating the maximum value of this difference, and using the maximum difference as the data buffer threshold for the next time may ensure that there is always enough cached data to read when a data request is generated in the future.
[0065] Specifically, when the maximum difference is unknown at the beginning, a larger buffer threshold is set first, that is, the second data buffer threshold must be at least larger than D1. Since the size of D0 is unknown, we can first assume that D0 = D1. Then the second data buffer threshold is 2*D1. When the total amount of the second data generated is equal to or greater than the second data buffer threshold at the time of data reading cycle (the moment when a data request is generated), data reading begins.
[0066] In addition, it also includes:
[0067] Starting from the moment the first data request occurs, the total amount of statistical data generated and the total amount of data read are recorded at each data reading cycle value, and a dynamic difference set is obtained;
[0068] Obtain the maximum dynamic difference in the set of dynamic differences.
[0069] When the remaining data volume is less than the data reading cycle volume, data buffering is performed again. The target buffering threshold corresponding to the data buffering is the larger of the maximum dynamic difference and the data reading cycle volume.
[0070] Data reading begins when the amount of remaining data counted during the data reading cycle is equal to or greater than the target buffer threshold.
[0071] In practice, when a data read request occurs but there is insufficient cached data, the data re-enters the buffer. Simultaneously, the larger of the latest statistically calculated maximum difference between the total historical data requests and the total generated data, compared to D1, is used as the new buffer threshold. That is, while calculating the maximum difference between the total historical data requests and the total generated data, data is output. When the amount of data to be read exceeds the remaining amount of data, the data re-enters the buffer. At this point, the larger of the latest statistically calculated maximum difference between the total historical data requests and the total generated data, compared to D1, is used as the target buffer threshold for the next iteration. With a sufficiently large number of statistical iterations, the calculated maximum value is likely to be the maximum difference between the total data requests and the total generated data.
[0072] Furthermore, due to factors such as network conditions, there are random fluctuations in data generation in addition to the periodicity of the data. These random fluctuations may cause data read failures even after buffering according to the aforementioned buffering strategy. However, this can also be observed by statistically analyzing the difference between the total amount of data generated and the total amount of data requested; this observed difference is called the "composite difference." The composite difference arises from two causes: one is the difference in the "period" and "phase" between the data generation period and the data read request period; the other is the random delay in data generation. Therefore, the composite difference can be observed by statistically analyzing the maximum value of the difference between the total amount of data generated and the total amount of data requested. If, in addition to periodicity, there is also random delay in data output, it can be estimated by adding the maximum value of the maximum difference between the total output and the total read request to the maximum value of the resulting "composite difference."
[0073] This application analyzes and concludes that data reading begins only when the buffered data volume is greater than or equal to the sum of the output D0 within a minimum positive cycle of data generation and the data read request D1 in a single session, thus ensuring that there will be no insufficient data to read. Even without prior knowledge of D0, the same effect can be achieved by statistically analyzing the maximum dynamic difference between the total output and read requests multiple times and using this maximum dynamic difference as the target buffer threshold. Finally, even if data output has random delays in addition to periodicity, this can be estimated by adding the maximum value of the "composite difference" (the maximum dynamic difference between the total output and read requests) to the delay.
[0074] Corresponding to the data buffering method embodiment provided in this application, this application also provides an embodiment of a data buffering apparatus. (See reference) Figure 4 This is a schematic diagram of a data buffering device provided in an embodiment of this application. The device includes:
[0075] The acquisition unit 100 is used to acquire a data read request, the data read request including the total amount of data to be read, the data read cycle value and the data read cycle length; and to acquire the data generation cycle value and the data generation cycle length.
[0076] The data buffer unit 200 is used to buffer data according to a first data buffer threshold if the data generation cycle amount can be obtained. The first data buffer threshold is the sum of the data generation cycle amount and the data reading cycle amount.
[0077] The data reading unit 300 is used to start reading data after the total amount of the first data generated is equal to or greater than the first data buffer threshold when the data reading cycle value is counted.
[0078] The data buffer unit 200 is also used for:
[0079] If the data generation cycle cannot be obtained, the data is buffered according to the second data buffer threshold, which is twice the data reading cycle.
[0080] Data reading begins after the total amount of the second data generated during the data reading cycle is equal to or greater than the first data buffer threshold.
[0081] The acquisition unit 100 is further configured to:
[0082] At each data reading cycle, the total amount of statistical data generated and the total amount of data read are recorded, and a dynamic difference set is obtained.
[0083] Obtain the maximum dynamic difference in the set of dynamic differences.
[0084] The data buffer unit 200 is also used for:
[0085] When the remaining data volume is less than the data reading cycle volume, data buffering is performed again. The target buffering threshold corresponding to the data buffering is the larger of the maximum dynamic difference and the data reading cycle volume.
[0086] The data reading unit 300 is also used for:
[0087] Data reading begins when the amount of remaining data counted at the data reading cycle value is equal to or greater than the target buffer threshold.
[0088] This application provides a data buffering method and apparatus, which acquires a data read request, the data read request including a total data read volume, a data read cycle value, and a data read cycle length; acquires a data generation cycle value and a data generation cycle length; if the data generation cycle length can be acquired, buffers data according to a first data buffering threshold, the first data buffering threshold being the sum of the data generation cycle length and the data read cycle length; starts reading data after the total first data generation volume, calculated at the data read cycle value, is equal to or greater than the first data buffering threshold; if the data generation cycle length cannot be acquired, buffers data according to a second data buffering threshold, the second data buffering threshold being twice the data read cycle length; starts reading data after the total second data generation volume, calculated at the data read cycle value, is equal to or greater than the first data buffering threshold.
[0089] This application analyzes and concludes that data reading begins only when the buffered data volume is greater than or equal to the sum of the output D0 within a minimum positive cycle of data generation and the data read request D1 in a single session, thus ensuring that there will be no insufficient data to read. Even without prior knowledge of D0, the same effect can be achieved by statistically analyzing the maximum dynamic difference between the total output and read requests multiple times and using this maximum dynamic difference as the target buffer threshold. Finally, even if data output has random delays in addition to periodicity, this can be estimated by adding the maximum value of the "composite difference" (the maximum dynamic difference between the total output and read requests) to the delay.
[0090] Based on the above-described data buffering method, embodiments of this application also provide a readable storage medium and a computer device. The readable storage medium stores an executable program, which, when executed by a processor, implements the steps of the above-described data buffering method. The computer device includes a memory, a processor, and an executable program stored in the memory and executable on the processor; when the processor executes the program, it implements the steps of the above-described data buffering method.
[0091] The present application has been described in detail above with reference to specific embodiments and exemplary examples; however, these descriptions should not be construed as limiting the present application. Those skilled in the art will understand that various equivalent substitutions, modifications, or improvements can be made to the technical solutions and implementation methods of the present application without departing from the spirit and scope of the present application, and all such modifications and improvements fall within the scope of the present application. The scope of protection of the present application is determined by the appended claims.
Claims
1. A data buffering method, characterized in that, The method includes: Obtain a data read request, wherein the data read request includes the total amount of data to be read, the data read cycle value, and the data read cycle length; Acquire the data generation cycle value and the data generation cycle quantity; If the data generation cycle amount can be obtained, then the data is buffered according to the first data buffer threshold, which is the sum of the data generation cycle amount and the data reading cycle amount; Data reading begins after the total amount of the first data generated during the data reading cycle is equal to or greater than the first data buffer threshold. If the data generation cycle cannot be obtained, the data is buffered according to the second data buffer threshold, which is twice the data reading cycle. Data reading begins after the total amount of the second data generated during the data reading cycle is equal to or greater than the second data buffer threshold.
2. The data buffering method according to claim 1, characterized in that, Also includes: At each data reading cycle, the total amount of statistical data generated and the total amount of data read are recorded, and a dynamic difference set is obtained. Obtain the maximum dynamic difference in the set of dynamic differences; When the remaining data volume is less than the data reading cycle, data buffering is performed again. The target buffering threshold corresponding to the data buffer is the larger of the maximum dynamic difference and the data reading cycle. Data reading begins when the amount of remaining data counted at the data reading cycle value is equal to or greater than the target buffer threshold.
3. A data buffering device, characterized in that, The device includes: The acquisition unit is used to acquire a data read request, which includes a total amount of data to be read, a data read cycle value, and a data read cycle length; and to acquire a data generation cycle value and a data generation cycle length. A data buffer unit is configured to buffer data according to a first data buffer threshold if the data generation cycle amount can be obtained, wherein the first data buffer threshold is the sum of the data generation cycle amount and the data reading cycle amount; The data reading unit is used to start reading data after the total amount of data generated during the data reading cycle is equal to or greater than the first data buffer threshold. The data buffer unit is further configured to: if the data generation cycle cannot be obtained, buffer the data according to a second data buffer threshold, wherein the second data buffer threshold is twice the data reading cycle. Data reading begins after the total amount of the second data generated during the data reading cycle is equal to or greater than the second data buffer threshold.
4. The data buffering apparatus according to claim 3, characterized in that, The acquisition unit is further configured to: generate a total amount of statistical data and a total amount of data read at each data reading cycle value, and acquire a dynamic difference set, and acquire the maximum dynamic difference in the dynamic difference set; The data buffer unit is also used to: perform data buffering again when the remaining data amount is less than the data reading cycle amount, wherein the target buffering threshold corresponding to the data buffering is the larger of the maximum dynamic difference and the data reading cycle amount; The data reading unit is also used to: start reading data when the amount of remaining data counted at the data reading cycle value is equal to or greater than the target buffer threshold.
Citation Information
Patent Citations
Data message forwarding method and device
CN106067865A
