Function memory allocation methods, devices, computer equipment, storage media and products
By determining and allocating the optimal memory size, the resource consumption and performance issues of function computation in serverless architecture are resolved, achieving reasonable allocation of memory resources and optimization of function performance.
Patent Information
- Application Number
- CN202210584553.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-27
- Publication Date
- 2025-10-31
- Estimated Expiration
- 2042-05-27
AI Technical Summary
In serverless architectures, the pre-specified memory size during function computation may not be optimal, leading to excessive resource consumption or low performance.
By obtaining the running time of the objective function in multiple memory locations, the optimal memory size is determined based on the memory size and running time, and allocation is performed based on the optimal memory size. The optimal memory size is calculated using memory usage cost, running time, and a balance factor.
This avoids the problem of excessive resource consumption or low performance when the target function runs under inappropriate memory conditions, and achieves reasonable allocation of memory resources and optimization of function performance.
Smart Images

Figure CN114780250B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of cloud computing technology, and in particular to a function memory allocation method, apparatus, computer equipment, storage medium and product. Background Technology
[0002] With the advent of the cloud-native era, serverless architecture has become increasingly popular. Enterprises and developers alike are exploring serverless architectures, hoping to replace traditional backend service architectures in suitable scenarios to reduce costs and increase efficiency. Function Compute is one of the most commonly used serverless architectures. Function Compute is an event-driven, fully managed computing service. Functions are simply deployed on the Function Compute platform, and are activated when the corresponding event is triggered. Therefore, when implementing events using Function Compute, enterprises can focus solely on application-layer development of business logic, significantly reducing costs and increasing efficiency.
[0003] In traditional serverless function computing, the memory size for a function needs to be pre-specified before the computing platform runs it. However, the pre-specified memory size is not necessarily the optimal size for performance. Therefore, running a function within the pre-specified memory size may result in excessive platform resource consumption or poor function performance. Summary of the Invention
[0004] Therefore, it is necessary to provide a method, apparatus, computer device, storage medium, and product for allocating function memory that can determine the optimal memory size of a function, in response to the above-mentioned technical problems.
[0005] Firstly, this application provides a method for allocating memory for a function. The method includes:
[0006] Obtain the runtime of the target function across multiple memory locations, each with a different size.
[0007] Based on the size of each memory location and the running time of the objective function in each memory location, determine the optimal memory size for running the objective function;
[0008] Allocate memory resources for the objective function based on the optimal memory size.
[0009] In one embodiment, determining the optimal memory size for running the objective function based on the size of each memory location and the execution time of the objective function in each memory location includes:
[0010] Determine the memory usage cost for each memory segment based on runtime and memory size.
[0011] The optimal memory size for the objective function is determined based on the memory usage cost, size, and running time of each memory location.
[0012] In one embodiment, the optimal memory size for the objective function is determined based on the memory usage cost, size, and runtime of each memory location, including:
[0013] For each memory, the cost quantification value corresponding to the memory is determined based on the minimum value of the memory usage cost and the usage costs of multiple memory units;
[0014] For each memory location, the time quantization value corresponding to that memory location is determined based on the minimum of the runtime and multiple runtime values.
[0015] The optimal memory size is determined based on a preset balance factor, cost quantification value, and time quantification value; the balance factor is used to balance memory usage cost and runtime.
[0016] In one embodiment, determining the optimal memory size based on a preset balance factor, a cost quantization value, and a time quantization value includes:
[0017] For each memory unit, the total quantized value of the memory unit is determined based on the balance factor, cost quantization value, and time quantization value.
[0018] The optimal memory size is determined based on the total quantization value of multiple memory locations.
[0019] In one embodiment, obtaining the runtime of the target function across multiple memory locations includes:
[0020] Obtain the preset parameters corresponding to the target function; the preset parameters include at least one of the following: memory size, user-level CPU time, system-level CPU time, file system read / write count, network bandwidth, and runtime;
[0021] Based on preset parameters and the target prediction model, the running time of the objective function in each memory location is determined.
[0022] In one embodiment, the target prediction model includes a linear regression function, and the runtime of the target function in various memory locations is determined based on preset parameters and the target prediction model, including:
[0023] Substituting the preset parameters into the linear regression function yields the running time of the objective function in various memory locations; the linear regression function is configured with weights corresponding to the preset parameters.
[0024] In one embodiment, before determining the running time of the objective function in each memory location based on preset parameters and the target prediction model, the method further includes:
[0025] Multiple test functions are established, and the preset parameters of the test functions are monitored to obtain the monitoring dataset;
[0026] Regression calculations are performed based on the monitoring dataset and the initial prediction model to obtain the first running time predicted by the initial prediction model; the initial prediction model is set with weights corresponding to each preset parameter.
[0027] Based on the actual second and first running times of the test function, adjust the weights corresponding to each preset parameter;
[0028] The target prediction model is determined based on the adjusted weights and preset parameters.
[0029] In one embodiment, the weights corresponding to each preset parameter are adjusted based on the actual second runtime and first runtime of the test function, including:
[0030] Determine the target weights corresponding to the preset parameters when the root mean square error of the second running time and the first running time is minimized, and adjust the weights corresponding to each preset parameter according to the target weights.
[0031] Secondly, this application also provides a function memory allocation apparatus. The apparatus includes:
[0032] The first-time acquisition module is used to obtain the running time of the target function in multiple memory locations, each with a different size.
[0033] The memory determination module is used to determine the optimal memory size for running the objective function based on the size of each memory location and the running time of the objective function in each memory location.
[0034] The memory allocation module is used to allocate memory resources for the objective function based on the optimal memory size.
[0035] Thirdly, this application also provides a computer device. The computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program to perform the following steps:
[0036] Obtain the runtime of the target function across multiple memory locations, each with a different size.
[0037] Based on the size of each memory location and the running time of the objective function in each memory location, determine the optimal memory size for running the objective function;
[0038] Allocate memory resources for the objective function based on the optimal memory size.
[0039] Fourthly, this application also provides a computer-readable storage medium. The computer-readable storage medium stores a computer program thereon, which, when executed by a processor, performs the following steps:
[0040] Obtain the runtime of the target function across multiple memory locations, each with a different size.
[0041] Based on the size of each memory location and the running time of the objective function in each memory location, determine the optimal memory size for running the objective function;
[0042] Allocate memory resources for the objective function based on the optimal memory size.
[0043] Fifthly, this application also provides a computer program product. The computer program product includes a computer program that, when executed by a processor, performs the following steps:
[0044] Obtain the runtime of the target function across multiple memory locations, each with a different size.
[0045] Based on the size of each memory location and the running time of the objective function in each memory location, determine the optimal memory size for running the objective function;
[0046] Allocate memory resources for the objective function based on the optimal memory size.
[0047] The aforementioned function memory allocation method, apparatus, computer device, storage medium, and product first obtain the runtime of the target function across multiple memory locations, where each memory location has a different size. Then, based on the size of each memory location and the runtime of the target function across each memory location, the optimal memory size for running the target function is determined. Finally, memory resources are allocated to the target function based on the optimal memory size. Because this function memory allocation method can calculate the corresponding runtimes of the target function across multiple memory locations, and then calculate the optimal memory size based on the multiple memory locations and their runtimes, it can allocate memory for the target function based on the optimal memory size. Since this memory allocation size is optimal, it avoids the problems of excessive platform resource consumption or low function performance when the target function runs under inappropriate memory locations. Attached Figure Description
[0048] Figure 1 This is a diagram illustrating the application environment of a function memory allocation method in one embodiment;
[0049] Figure 2 This is a flowchart illustrating a function memory allocation method in one embodiment;
[0050] Figure 3 This is a flowchart illustrating a method for determining the optimal memory size for running an objective function based on the size of each memory location and the running time of the objective function in each memory location, as described in one embodiment.
[0051] Figure 4This is a flowchart illustrating a method for determining the optimal memory size for an objective function based on the memory usage cost, size, and runtime of each memory location in one embodiment.
[0052] Figure 5 This is a flowchart illustrating a method for determining the optimal memory size based on a preset balance factor, a cost quantization value, and a time quantization value in one embodiment.
[0053] Figure 6 This is a flowchart illustrating a method for obtaining the runtime of an objective function across multiple memory locations in one embodiment.
[0054] Figure 7 This is a flowchart illustrating the function memory allocation method in another embodiment;
[0055] Figure 8 This is a flowchart illustrating a function memory allocation method in one embodiment;
[0056] Figure 9 This is a flowchart illustrating a function memory allocation method in one embodiment;
[0057] Figure 10 This is a structural block diagram of a function memory allocation device in one embodiment;
[0058] Figure 11 This is a block diagram of the function memory allocation device in another embodiment;
[0059] Figure 12 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0060] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0061] With the advent of the cloud-native era, serverless architecture has become increasingly popular. Enterprises and developers alike are exploring serverless architectures, hoping to replace traditional backend service architectures in suitable scenarios to reduce costs and increase efficiency. Function Compute is one of the most commonly used serverless architectures. Function Compute is an event-driven, fully managed computing service. Functions are simply deployed on the Function Compute platform, and are activated when the corresponding event is triggered. Therefore, when implementing events using Function Compute, enterprises can focus solely on application-layer development of business logic, significantly reducing costs and increasing efficiency.
[0062] In traditional serverless function computing, the memory size for a function needs to be pre-specified before the computing platform runs it. However, the pre-specified memory size is not necessarily the optimal size for performance. Therefore, running a function within the pre-specified memory size may result in excessive platform resource consumption or poor function performance.
[0063] The function memory allocation method provided in this application embodiment can be applied to, for example, Figure 1 The application environment shown above illustrates the method for allocating function memory. This method can be applied to a computing platform 102, which can be a function computing platform, computer equipment, server, cloud computing platform, or other similar device. When the computing platform is a server, it can be a standalone server or a server cluster composed of multiple servers. This application does not limit the specific form of the computing platform 102. The computing platform 102 can obtain the running time of the target function in multiple memory locations; determine the optimal memory size for running the target function based on the size of each memory location and the running time of the target function in each memory location; and allocate memory resources to the target function based on the optimal memory size.
[0064] In one embodiment, such as Figure 2 As shown, a function memory allocation method is provided, which can be applied to... Figure 1 Taking the application environment in [the document] as an example, the following steps are included:
[0065] S220, obtains the running time of the objective function in multiple memory locations.
[0066] The memory size of each objective function varies. Objective functions can be used for batch file processing, business data merging, business report generation, market investment withdrawal, and other business operations. When an objective function is needed to achieve a business requirement, it can be started directly through a network interface. Alternatively, startup conditions for the objective function can be preset, and the function will start when these conditions are met. The runtime is the time required for the objective function to complete tasks such as batch file processing, business data merging, business report generation, and market investment withdrawal. Furthermore, the memory size of the objective function can be 128MB, 256MB, 512MB, 1024MB, or 2048MB. In practical applications, the memory size of the objective function can also be other values; this embodiment does not limit this.
[0067] A target prediction model for the running time of the objective function under multiple memory locations can be set in advance in the computing platform 102. Then, the running time of the objective function under multiple memory locations can be predicted according to the target prediction model. Alternatively, a calculation formula for the running time can be set in advance in the computing platform 102, and the running time of the objective function under multiple memory locations can be obtained through the formula. This embodiment of the application does not impose any limitations on this.
[0068] S240 determines the optimal memory size for running the objective function based on the size of each memory location and the running time of the objective function in each memory location.
[0069] The optimal memory size is the memory size that maximizes the performance of the objective function. When the objective function is run with the optimal memory size, the memory resources used by the objective function are reasonable and the function performance is good.
[0070] The method for determining the optimal memory size of the objective function can be pre-set in the computing platform 102. For example, a series of optimal memory size calculation formulas can be set, or a prediction model of the optimal memory size can be established through multiple test functions. When the function computing platform starts the function, the computing platform 102 automatically determines the optimal memory size for running the objective function through the optimal memory size calculation formula or prediction model.
[0071] S260 allocates memory resources for the objective function based on the optimal memory size.
[0072] In the above steps, the optimal memory size of the objective function has been determined. The computing platform 102 can reallocate memory resources for the objective function according to the optimal memory size. Of course, the developers can also reallocate memory resources for the objective function according to the optimal memory size.
[0073] The above-mentioned memory allocation method can calculate the running time of the target function under each memory location. Then, based on the running time under each memory location, the optimal memory size can be calculated. Therefore, the memory of the target function can be conveniently allocated based on the optimal memory size. Because this memory allocation size is the optimal memory size, it avoids the problem of the target function consuming too many platform resources or having poor function performance when running under an inappropriate memory size.
[0074] In one embodiment, such as Figure 3 As shown, the process of determining the optimal memory size for running the objective function based on the size of each memory location and the running time of the objective function in each memory location can include the following steps:
[0075] S242 determines the memory usage cost of each memory based on the running time and the size of each memory.
[0076] The memory usage cost of the objective function varies depending on the available memory. Besides the memory size, the memory usage cost is also related to the runtime of the objective function under different memory conditions. The specific determination of the memory usage cost can be achieved using the following formula:
[0077] Cost mem =exe_times·mem_size formula (1-1)
[0078] Where exe_times is the runtime and mem_size is the memory size. For example, for the same objective function, assuming the memory size is 128MB, the memory usage cost is the product of the 128MB memory size and the runtime of the objective function with 128MB of memory. The same method can be used to calculate the memory usage cost of the same objective function with 256MB, 512MB, etc.
[0079] S244 determines the optimal memory size for the objective function based on the memory usage cost, size, and running time of each memory location.
[0080] In the steps above, the memory usage cost corresponding to each memory segment has been determined, and the memory size and running time are known data. At this point, the computing platform 102 can determine the optimal memory size based on the above known data and the preset function memory allocation method.
[0081] In the above embodiments, since the memory usage cost can be obtained from the memory size and the running time of the objective function under different memory sizes, and the method for determining the memory usage cost can be pre-stored or set in the computing platform 102, the memory usage cost corresponding to each memory can be obtained relatively easily and quickly. Furthermore, since the memory usage cost, size, and running time corresponding to each memory are all known data, the optimal memory size for the objective function can also be determined efficiently and quickly.
[0082] In one embodiment, such as Figure 4 As shown, the process of determining the optimal memory size for the objective function based on the memory usage cost, size, and running time of each memory location can include the following steps:
[0083] S402, for each memory, determine the corresponding cost quantification value of the memory based on the minimum value of the memory usage cost and the multiple memory usage costs.
[0084] Taking memory sizes of 128MB, 256MB, 512MB, 1024MB, and 2048MB as examples, the corresponding cost of memory can be determined by the ratio of the memory usage cost to the minimum of multiple memory usage costs. The specific formula is as follows:
[0085]
[0086] Where, m x The memory size can be any one of 128MB, 256MB, 512MB, 1024MB, or 2048MB. cost (m x Cost is a quantified value of cost. mem (m x ) represents the cost of memory usage, m i This represents the memory size that minimizes memory usage cost. Understandably, each memory unit corresponds to a memory usage cost. By comparing each memory usage cost with the minimum of multiple memory usage costs, we can obtain a quantified cost value for different memory units.
[0087] S404 determines the time quantization value corresponding to each memory based on the minimum of the runtime and multiple runtimes for each memory.
[0088] The time quantization value corresponding to memory can be determined by the ratio of the runtime to the minimum of multiple runtimes, as shown in the following formula:
[0089]
[0090] Where, m x The memory size can be any one of 128MB, 256MB, 512MB, 1024MB, or 2048MB. perf (m x ) represents the time quantization value, exe_times(m x ) represents the runtime, m i This represents the memory size corresponding to the minimum runtime. Understandably, each memory unit corresponds to a runtime. By comparing each runtime with the minimum of multiple runtime units, we can obtain the quantized time value corresponding to different memory units.
[0091] S406 determines the optimal memory size based on preset balance factors, cost quantization values, and time quantization values.
[0092] The balancing factor is used to balance memory usage cost and runtime. The value of the balancing factor ranges from 0 to 1, and can be set according to the actual situation. For example, if a longer runtime is expected for the objective function, the balancing factor can be set to 0.5 or higher; if a lower memory usage is expected, the balancing factor can be set to 0.5 or lower.
[0093] The balance factor can be set according to the actual expectation when the function is running. The cost quantification value and the time quantification value can be determined through the above steps. Based on the above known data, the optimal memory size can be determined. The method for determining the optimal memory size can be preset in the computing platform 102. When the optimal memory size needs to be determined, the corresponding method can be directly called to determine it.
[0094] In the above embodiments, the cost quantification value and the time quantification value can be calculated by the size of the memory and the running time corresponding to the memory. Since the amount of data involved is relatively small and the calculation method is simple, the speed of determining the cost quantification value and the time quantification value can be greatly improved.
[0095] In one embodiment, such as Figure 5 As shown, the process of determining the optimal memory size based on the preset balance factor, cost quantization value, and time quantization value can include the following steps:
[0096] S502 determines the total quantized value of each memory unit based on the balance factor, cost quantization value, and time quantization value.
[0097] The total quantized value corresponding to memory can be obtained using the following formula:
[0098] S total (m x )=t·S cost (m x )+(1-t)·S perf (m x ) Formula (1-4)
[0099] Among them, S total (m x ) represents the total quantized value corresponding to memory, and t represents the balancing factor. For multiple memory units, the total quantized value corresponding to multiple memory units can be determined based on the cost quantization value, time quantization value, and balancing factor corresponding to that memory unit.
[0100] S504 determines the optimal memory size based on the total quantization value of multiple memory locations.
[0101] Since the total quantized value of memory is determined by the balance factor, cost quantized value, and time quantized value, the minimum value among the calculated total quantized values is the optimal memory size. The specific formula is as follows:
[0102]
[0103] Where, optisize(m x ) represents the optimal memory size, argminS total (m x ) represents returning Stotal (m x The minimum value in ).
[0104] In the above embodiments, since the balancing factor can be set according to actual conditions, it can balance memory usage costs and runtime, thus better matching actual business needs. Furthermore, since the overall score is calculated for each memory size, and then the smallest overall score is selected as the optimal memory size, the runtime and memory usage costs for each memory size are taken into account, resulting in a more accurate final optimal memory cost.
[0105] In one embodiment, such as Figure 6 As shown, the process of obtaining the running time of the objective function in multiple memory locations can include the following steps:
[0106] S602, obtain the preset parameters corresponding to the objective function.
[0107] The preset parameters include at least one of the following: memory size, user-level CPU time, system-level CPU time, file system read / write counts, network bandwidth, and runtime. User-level CPU time refers to the execution time in user mode when the target function completes the business logic, while system-level CPU time refers to the execution time in kernel mode.
[0108] The objective function is hosted in a cloud computing platform. The computing platform 102 can read the objective function and obtain the preset parameters of the function. Of course, the preset parameters corresponding to the objective function can also be set in the computing platform 102 in advance. This embodiment of the application does not impose any restrictions here.
[0109] S604 determines the running time of the objective function in each memory location based on preset parameters and the target prediction model.
[0110] Optionally, the target prediction model includes a linear regression function. Based on preset parameters and the target prediction model, the running time of the target function in each memory location is determined. This can include: substituting the preset parameters into the linear regression function to obtain the running time of the target function in each memory location; the linear regression function is set with weights corresponding to the preset parameters.
[0111] Specifically, the target prediction model can be used to predict the running time of the objective function in various memory locations. The target prediction model is a linear regression function related to the running time of the objective function in various memory locations, preset parameters, and the weights corresponding to the preset parameters. The linear regression function in the above target prediction model is as follows:
[0112] Y = β0 + β1X1 + β2X2 + ... + β P X P Formula (1-6)
[0113] Where Y is the running time, X1, X2...X p These are preset parameters, where β0 is memory, β1, β2...β p The weights are the preset parameters.
[0114] The preset parameters of the objective function can be obtained in advance, and the weights corresponding to the preset parameters can also be set in advance. Then, by substituting the preset parameters into the linear regression function, the running time of the objective function under various memory conditions can be calculated.
[0115] In this embodiment, the preset parameters of the objective function and the weights corresponding to the preset parameters can be set in advance when setting the objective function. Therefore, the above-mentioned objective prediction model can be used to conveniently calculate the running time of the objective function in each memory location.
[0116] In one embodiment, such as Figure 7 As shown, before determining the running time of the objective function in different memory locations based on preset parameters and the target prediction model, the method further includes:
[0117] S702, establish multiple test functions, monitor the preset parameters of the test functions, and obtain the monitoring dataset.
[0118] The test function and the target function have the same purpose: to implement batch file processing, business data merging, business report generation, market investment withdrawal, and other business operations. The test function can include multiple different target functions, or it can be composed of various target functions or other functions that have been executed in the past.
[0119] For each test function, the preset parameters may be different due to the different specific scenarios and business requirements. The computing platform 102 can monitor the preset parameters of the test function and store the monitored preset parameters of the test function into a monitoring dataset.
[0120] S704 performs regression calculations based on the monitoring dataset and the initial prediction model to obtain the first running time predicted by the initial prediction model.
[0121] The initial prediction model is configured with weights corresponding to each preset parameter. It is a linear regression function related to the runtime of the test function in different memory locations, the preset parameters, and their corresponding weights. The initial prediction model is identical to formula (1-6). Since the memory size and preset parameters of the test function can be obtained in advance, and the initial prediction model has weights corresponding to each preset parameter, the first runtime of the test function can be predicted based on the initial prediction model.
[0122] S706, adjust the weights corresponding to each preset parameter according to the actual second and first running times of the test function.
[0123] The second running time is the actual running time of the test function. Fitting analysis can be performed based on the first and second running times to determine the weights corresponding to each preset parameter of the test function. Alternatively, other methods can be used to obtain the weights corresponding to each preset parameter.
[0124] Optionally, the method for adjusting the weights corresponding to each preset parameter can be to determine the target weights corresponding to the preset parameters when the root mean square error of the second running time and the first running time is minimized, and then adjust the weights corresponding to each preset parameter according to the target weights.
[0125] When the root mean square error of the second running time and the first running time is minimized, it indicates that the first running time predicted by the initial prediction model is closest to the actual second running time of the test function. In this case, the weights corresponding to each preset parameter are also the most accurate. The weights corresponding to each preset parameter can be determined by the following formula:
[0126]
[0127] Where RSS is the root mean square error, y i To test the actual second running time of the function, This is the first running time.
[0128] S708, determine the target prediction model based on the adjusted weights and preset parameters.
[0129] By inputting the target weights corresponding to the preset parameters that minimize the root mean square error into the initial prediction model, the target prediction model can be obtained.
[0130] In the above embodiments, a monitoring dataset can be obtained through multiple test functions. An initial prediction model is then accurately established based on this dataset. The weights corresponding to each preset parameter in the initial prediction model are accurately adjusted using the first runtime predicted by the initial prediction model and the actual second runtime of the test functions. Finally, the target prediction model is obtained based on the adjusted weights of the preset parameters, thus enabling accurate prediction of the runtime of both the target function and the test functions. The root mean square error (RMSE) represents the degree of fit between the predicted first runtime and the second runtime. A smaller RMSE indicates a closer fit, and the weights corresponding to the preset parameters can be determined more intuitively and conveniently using the RMSE.
[0131] In one embodiment, such as Figure 8 As shown, the above function memory allocation method may include the following steps:
[0132] S802: Establish multiple test functions, monitor the preset parameters of the test functions, and obtain the monitoring dataset.
[0133] S804 performs regression calculations based on the monitoring dataset and the initial prediction model to obtain the first running time predicted by the initial prediction model.
[0134] The initial prediction model is set with weights corresponding to each preset parameter.
[0135] S806, determine the target weights corresponding to the preset parameters when the root mean square error of the second running time and the first running time is minimized, and adjust the weights corresponding to each preset parameter according to the target weights.
[0136] S808 determines the target prediction model based on the adjusted weights and preset parameters.
[0137] S810, obtain the preset parameters corresponding to the objective function.
[0138] The preset parameters include at least one of the following: memory size, user-level CPU time, system-level CPU time, file system read / write count, network bandwidth, and runtime.
[0139] S812 substitutes the preset parameters into the linear regression function to obtain the running time of the objective function in each memory location.
[0140] The target prediction model includes a linear regression function; the linear regression function has weights corresponding to preset parameters.
[0141] S814 determines the memory usage cost of each memory based on the runtime and the size of each memory.
[0142] S816 determines the cost quantization value corresponding to each memory based on the minimum of the memory usage cost and the cost of multiple memory usages.
[0143] S818 determines the time quantization value corresponding to each memory based on the minimum of the runtime and multiple runtimes for each memory.
[0144] S820 determines the total quantized value of each memory unit based on the balance factor, cost quantization value, and time quantization value.
[0145] S822 determines the optimal memory size based on the total quantization value of multiple memory locations.
[0146] S824 allocates memory resources for the objective function based on the optimal memory size.
[0147] For ease of understanding, Figure 9The flowchart briefly introduces the function memory allocation method. First, the computing platform 102 initiates the function memory allocation method, then monitors multiple test functions to obtain a monitoring dataset, and trains and determines the target prediction model using the monitoring dataset. Next, the computing platform 102 monitors the target function, obtains the preset parameters corresponding to the target function, inputs the prediction parameters into the target prediction model, and predicts the running time of the function under different memory sizes using the target prediction model. Finally, function memory optimization is performed to determine the optimal memory size, and then the computing platform 102 allocates function memory based on the determined optimal memory size.
[0148] The function memory allocation method in the above embodiments can calculate the running time of the target function under each memory location, and then calculate the optimal memory size based on the running time under each memory location. Therefore, memory allocation for the target function can be based on the optimal memory size. Because this memory allocation size is the optimal size, it avoids the problem of excessive platform resource consumption or low function performance when the target function runs under an inappropriate memory size. Furthermore, since memory usage cost, cost quantification value, and time quantification value can be calculated from the memory size and the corresponding running time, the data involved is relatively small and the calculation method is simple, thus greatly improving the speed of determining memory usage cost, cost quantification value, and time quantification value. When determining the optimal memory size, a balancing factor can balance memory usage cost and running time. Therefore, the optimal memory size determined based on the balancing factor can ensure that when the target function runs under this optimal memory size, the memory usage cost and running time of the target function are relatively balanced, resulting in better performance of the target function. Therefore, the above memory allocation method can efficiently and accurately determine the optimal memory size, avoiding the problems of excessive memory consumption or low function performance when running functions with an inappropriate memory size.
[0149] It should be understood that although the steps in the flowcharts of the embodiments described above are shown sequentially according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless explicitly stated herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some steps in the flowcharts of the embodiments described above may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be performed alternately or in turn with other steps or at least some of the steps or stages of other steps.
[0150] Based on the same inventive concept, this application also provides a function memory allocation device for implementing the function memory allocation method described above. The solution provided by this device is similar to the implementation described in the above method; therefore, the specific limitations in one or more function memory allocation device embodiments provided below can be found in the limitations of the function memory allocation method described above, and will not be repeated here.
[0151] In one embodiment, such as Figure 10 As shown, a function memory allocation device 1000 is provided, including: a first-time acquisition module 1100, a memory determination module 1200, and a memory allocation module 1300, wherein:
[0152] The first-time acquisition module 1100 is used to obtain the running time of the target function in multiple memory locations; where the size of each memory location is different.
[0153] The memory determination module 1200 is used to determine the optimal memory size for running the objective function based on the size of each memory location and the running time of the objective function in each memory location.
[0154] The memory allocation module 1300 is used to allocate memory resources for the objective function based on the optimal memory size.
[0155] In another embodiment of the function memory allocation apparatus, the memory determination module 1200 further includes:
[0156] The memory usage cost determination unit is used to determine the memory usage cost of each memory based on the running time and the size of each memory.
[0157] The optimal memory size determination unit is used to determine the optimal memory size for the objective function based on the memory usage cost, size, and running time of each memory location.
[0158] In another embodiment of the function memory allocation apparatus, the optimal memory size determination unit includes:
[0159] The cost quantification value determination sub-unit is used to determine the cost quantification value corresponding to each memory based on the memory usage cost and the minimum value of multiple memory usage costs;
[0160] The time quantization value determination sub-unit is used to determine the time quantization value corresponding to each memory based on the minimum of the runtime and multiple runtimes.
[0161] The optimal memory size determination subunit is used to determine the optimal memory size based on a preset balance factor, cost quantization value, and time quantization value; the balance factor is used to balance memory usage cost and running time.
[0162] Optionally, the optimal memory size determination sub-unit is also used to determine the total quantized value of each memory based on the balance factor, cost quantization value, and time quantization value; and to determine the optimal memory size based on the total quantization value of multiple memories.
[0163] In another embodiment of the function memory allocation apparatus, the first-time acquisition module 1100 includes:
[0164] The preset parameter acquisition unit is used to acquire the preset parameters corresponding to the target function; the preset parameters include at least one of the following: memory size, user-level CPU time, system-level CPU time, file system read / write count, network bandwidth, and runtime;
[0165] The runtime determination unit determines the runtime of the objective function in each memory location based on preset parameters and the target prediction model.
[0166] Optionally, the target prediction model includes a linear regression function. The aforementioned runtime determination unit is specifically used to substitute preset parameters into the linear regression function to obtain the runtime of the target function in each memory location. The linear regression function is set with weights corresponding to the preset parameters.
[0167] In another embodiment of the function memory allocation device, such as Figure 11 As shown, the function memory allocation device 1000 also includes:
[0168] The parameter monitoring module 1400 is used to establish multiple test functions, monitor the preset parameters of the test functions, and obtain a monitoring dataset.
[0169] The second time acquisition module 1500 is used to perform regression calculations based on the monitoring dataset and the initial prediction model to obtain the first running time predicted by the initial prediction model; the initial prediction model is set with weights corresponding to each preset parameter.
[0170] Optionally, the second time acquisition module 1500 is specifically used to determine the target weight corresponding to the preset parameters when the root mean square error of the second running time and the first running time is minimized, and to adjust the weights corresponding to each preset parameter according to the target weight.
[0171] The weight adjustment module 1600 adjusts the weights corresponding to each preset parameter based on the actual second and first running times of the test function.
[0172] The model determination module 1700 determines the target prediction model based on the adjusted weights and preset parameters.
[0173] Each module in the aforementioned function memory allocation device can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device, or stored in the computer device's memory as software, so that the processor can call and execute the operations corresponding to each module.
[0174] In one embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be as follows: Figure 12 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The database stores data related to function memory allocation methods and the optimal memory size for functions. The network interface communicates with external terminals via a network connection. When the computer program is executed by the processor, it implements a function memory allocation method.
[0175] Those skilled in the art will understand that Figure 12 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0176] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the function memory allocation method provided in the above method embodiment.
[0177] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored, which, when executed by a processor, implements the function memory allocation method provided in the above method embodiment.
[0178] In one embodiment, a computer program product is provided, including a computer program that, when executed by a processor, implements the function memory allocation method provided in the above method embodiments.
[0179] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. Any references to memory, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM). The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0180] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0181] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of this patent application. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A method for allocating memory for a function, characterized in that, The method includes: Obtain the runtime of the target function in multiple memory locations; wherein the size of each memory location is different; The memory usage cost corresponding to each memory is determined based on the running time and the size of each memory. For each memory, a cost quantification value corresponding to the memory is determined based on the memory usage cost and the minimum of multiple memory usage costs; For each memory location, a time quantization value corresponding to that memory location is determined based on the minimum of the runtime and multiple runtime values. The optimal memory size is determined based on a preset balance factor, the cost quantization value, and the time quantization value; the balance factor is used to balance the memory usage cost and the running time. Allocate memory resources for the objective function based on the optimal memory size.
2. The method according to claim 1, characterized in that, Determining the optimal memory size based on a preset balance factor, the cost quantization value, and the time quantization value includes: For each memory unit, a total quantized value corresponding to that memory unit is determined based on the balance factor, the cost quantization value, and the time quantization value. The optimal memory size is determined based on the total quantization value of the multiple memory units.
3. The method according to claim 1, characterized in that, The process of obtaining the runtime of the target function across multiple memory locations includes: Obtain the preset parameters corresponding to the objective function; the preset parameters include at least one of multiple memory sizes, user-level CPU time, system-level CPU time, file system read / write counts, network bandwidth, and runtime; Based on the preset parameters and the target prediction model, the running time of the objective function in each memory location is determined.
4. The method according to claim 3, characterized in that, The target prediction model includes a linear regression function. Determining the runtime of the target function in each memory location based on the preset parameters and the target prediction model includes: The preset parameters are substituted into the linear regression function to obtain the running time of the objective function in each memory location; the linear regression function is configured with weights corresponding to the preset parameters.
5. The method according to claim 3, characterized in that, Before determining the running time of the objective function in each memory location based on the preset parameters and the target prediction model, the method further includes: Multiple test functions are established, and the preset parameters of the test functions are monitored to obtain a monitoring dataset; Regression calculations are performed based on the monitoring dataset and the initial prediction model to obtain the first running time predicted by the initial prediction model; the initial prediction model is set with weights corresponding to each of the preset parameters. The weights corresponding to each preset parameter are adjusted based on the actual second running time and the first running time of the test function. The target prediction model is determined based on the adjusted weights and the preset parameters.
6. The method according to claim 5, characterized in that, The step of adjusting the weights corresponding to each preset parameter based on the actual second runtime and the first runtime of the test function includes: Determine the target weight corresponding to the preset parameter when the second running time and the root mean square error of the first running time are minimized, and adjust the weights corresponding to each preset parameter according to the target weight.
7. A function memory allocation device, characterized in that, The device includes: The first-time acquisition module is used to acquire the running time of the target function in multiple memory locations; wherein the size of each memory location is different. A memory determination module is used to determine the memory usage cost corresponding to each memory based on the running time and the size of each memory; for each memory, to determine a cost quantization value corresponding to the memory based on the memory usage cost and the minimum of multiple memory usage costs; for each memory, to determine a time quantization value corresponding to the memory based on the running time and the minimum of multiple running times; and to determine an optimal memory size based on a preset balance factor, the cost quantization value, and the time quantization value; the balance factor is used to balance the memory usage cost and the running time. The memory allocation module is used to allocate memory resources to the objective function according to the optimal memory size.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Memory management method and device
CN101329655A
Periodicity Optimization in an Automated Tracing System
US20130283241A1