Memory adjustment method and device under pressure test, terminal and storage medium
By applying memory pressure to child processes managed by the main control process, the memory size is dynamically adjusted to simulate memory shrinkage, sudden loads, and steady-state fluctuations. This solves the problem that existing technologies cannot simulate dynamic changes in memory demand, and achieves more accurate system memory assessment.
Patent Information
- Application Number
- CN202611496260.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-24
- Publication Date
- 2026-11-27
AI Technical Summary
Existing memory stress testing tools cannot simulate the dynamic changes in memory demand in real-world applications, resulting in significant discrepancies between test results and actual application scenarios. This makes it difficult to effectively assess the system's responsiveness and stability under varying memory loads.
The main process creates independent child processes to apply memory pressure. Each child process has its own memory space and responds to the memory adjustment signals from the main process to dynamically adjust the memory size to simulate test scenarios such as memory shrinkage, sudden load, and steady-state fluctuations.
It enables testing under near-real business load conditions, significantly shortens the testing cycle, and allows for a more comprehensive and accurate evaluation of the system's memory reclamation mechanism's response efficiency and stability, while avoiding restart overhead caused by test process interruptions.
Smart Images

Figure CN123178183A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of memory testing technology, and in particular to a method, apparatus, terminal, and storage medium for adjusting memory under stress testing. Background Technology
[0002] Memory stress testing is an important method for evaluating the reliability of operating systems and applications under conditions of limited memory resources. Currently, the mainstream memory stress testing tools in the industry are stress-ng and memtester. stress-ng allocates memory blocks all at once at the start of the test by specifying the number of worker processes and the amount of memory allocated to each worker process based on command-line parameters. It can also use parameters such as -vm-keep to keep the allocated memory resident and prevent it from being released, thereby maintaining a constant level of memory usage throughout the test.
[0003] memtester allocates a fixed-size memory region at once according to a specified capacity, and then performs read and write checks on this fixed region in a loop to detect memory errors. In developing this invention, the inventors discovered the following problem: Regardless of the access method used, the aforementioned tools share the common characteristic that the memory allocation size and overall load intensity are determined at the start of the test and remain unchanged throughout the entire test cycle. This fails to simulate typical scenarios of dynamically changing memory requirements in real-world applications. In real business systems, memory requirements often exhibit various dynamic forms, while fixed-intensity tests can only provide a constant load. The test results deviate significantly from actual application scenarios, making it difficult to effectively assess the system's responsiveness and stability under varying memory load conditions. Summary of the Invention
[0004] This invention provides a method, apparatus, terminal, and storage medium for adjusting memory under stress testing, in order to solve the technical problem in the prior art that memory testing cannot simulate the dynamic changes in memory demand in actual applications.
[0005] In a first aspect, embodiments of the present invention provide a method for adjusting memory under stress testing, including: The main control process is instantiated and started based on the incoming test command. The main control process is used to create memory pressure application subprocesses and manage the life cycle of the memory pressure application subprocesses. Each subprocess is an independent memory pressure application unit and each subprocess has an independent memory space. The child process allocates an initial memory block in its own memory space according to the initially set memory size, and applies memory pressure to the system using the initial memory block; Each child process responds to the memory adjustment trigger signal sent by the main process and reads its current memory space size; Each subprocess adjusts its own memory space size based on the current memory space size and the adjustment parameters in the signal to obtain the target memory size; Each child process releases the current memory block in its own memory space and then reallocates a new memory block according to the target memory size to continue applying memory pressure to the system, in order to simulate test scenarios of memory shrinkage, sudden load and steady-state fluctuation.
[0006] Secondly, embodiments of the present invention also provide a memory adjustment device under stress testing, comprising: The instantiation module is used to instantiate and start the main control process based on the incoming test command, use the main control process to create memory pressure application subprocesses, and manage the life cycle of the memory pressure application subprocesses. Each subprocess is an independent memory pressure application unit and each subprocess has an independent memory space. The allocation module is used to allocate an initial memory block in the child process's own memory space according to the initially set memory size, and to apply memory pressure to the system with the initial memory block; The read module is used to read the current memory space size of each child process in response to the memory adjustment trigger signal sent by the main process; The adjustment module is used to adjust the size of each subprocess's memory space according to the current memory space size and the adjustment parameters in the signal, so as to obtain the target memory size; The continuation module is used to utilize each child process to release the current memory block in its own memory space, and then reallocate a new memory block according to the target memory size to continue to apply memory pressure to the system, so as to simulate test scenarios of memory shrinkage, sudden load and steady-state fluctuation.
[0007] Thirdly, embodiments of the present invention also provide a terminal, including: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the memory tuning method under stress test as described in any of the above embodiments.
[0008] Fourthly, embodiments of the present invention also provide a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the memory adjustment method under stress testing as provided in the above embodiments.
[0009] The memory adjustment method, apparatus, terminal, and storage medium under stress testing provided in this invention instantiate and start a main control process based on an incoming test command. The main control process creates memory pressure application subprocesses and manages their lifecycles. Each subprocess acts as an independent memory pressure application unit and has its own independent memory space. Within its own memory space, each subprocess allocates an initial memory block according to a pre-set memory size and applies memory pressure to the system using this initial memory block. Each subprocess responds to a memory adjustment trigger signal sent by the main control process and reads its current memory space size. Each subprocess adjusts its own memory space size according to the current memory space size and adjustment parameters in the signal to obtain a target memory size. After releasing the current memory block within its own memory space, each subprocess reallocates a new memory block according to the target memory size to continue applying memory pressure to the system, simulating test scenarios such as memory shrinkage, sudden load, and steady-state fluctuations. The main control process sends memory adjustment trigger signals to each child process. Each child process responds to the signal, reads its current memory space size, calculates the target memory size based on the adjustment parameters carried in the signal, and then releases the current memory block in its own memory space and reallocates a new memory block according to the target memory size. This ensures the continuity of the testing process, avoids the restart overhead caused by test interruption, and allows a single continuous test to cover the complete performance of the system memory usage from low to high, from high to low, or repeated changes, significantly shortening the test cycle. When adjusting memory space, the child process first releases the currently held memory block and then reallocates it according to the target memory size. By configuring different adjustment parameters, multiple dynamic load scenarios can be derived, allowing for testing under conditions close to real business load. This effectively overcomes the shortcomings of existing fixed-intensity tests, which can only provide constant loads and whose test results deviate significantly from actual application scenarios. It can provide a more comprehensive and accurate evaluation of indicators such as the response efficiency of the system memory reclamation mechanism, page replacement behavior, and stability under load changes. By using the main control process to uniformly create and manage the lifecycle of memory pressure application subprocesses, testers can use the main control process as a single entry point to uniformly trigger and adjust multiple pressure application units. They can also independently construct differentiated memory loads for each unit, thereby building refined memory pressure scenarios under multi-unit concurrency conditions and comprehensively evaluating the system's scheduling and reclamation capabilities under multi-process concurrent memory operations. Attached Figure Description
[0010] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings: Figure 1 This is a flowchart illustrating the memory adjustment method under stress testing provided in Embodiment 1 of the present invention; Figure 2 This is a flowchart illustrating the memory adjustment method under stress testing provided in Embodiment 2 of the present invention; Figure 3 This is a schematic diagram of the memory adjustment device under stress testing provided in Embodiment 3 of the present invention; Figure 4 This is a schematic diagram of the terminal provided in Embodiment 4 of the present invention. Detailed Implementation
[0011] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and not intended to limit it. Furthermore, it should be noted that, for ease of description, the accompanying drawings show only the parts relevant to the present invention, and not all of the structures.
[0012] Example 1 Figure 1 This is a flowchart of a memory adjustment method under stress testing provided in Embodiment 1 of the present invention. This embodiment is applicable to flexibly adjusting memory under system stress testing to adapt to various testing conditions. This method can be executed by a memory adjustment device under stress testing, and specifically includes the following steps: Step 110: Instantiate and start the main control process based on the incoming test command, use the main control process to create memory pressure application subprocesses, and manage the life cycle of the memory pressure application subprocesses. Each subprocess is an independent memory pressure application unit and each subprocess has an independent memory space.
[0013] In this embodiment, the test command can be input by the tester through the command line interface. The test command carries test parameters, which include at least the number of working units, the initial memory size, and the test duration. Optionally, it may also include a dynamic memory adjustment switch and adjustment strategy parameters, such as adjustment multiplier, adjustment interval, memory access mode, and memory access interval.
[0014] The main control process is instantiated as an independent system process, performing lexical and syntactic parsing on the test commands to extract the test parameters. In one optional implementation, the parsing process identifies each field in the command line in the form of parameter name=parameter value and matches it against a preset default parameter table; for parameters not explicitly specified in the test command, preset default values are used. The main control process initializes the runtime environment based on the parsed test parameters. For example, this may include: initializing a logger for recording key data during subsequent testing; initializing a system resource monitoring interface for subsequent load assessment; and pre-building a subprocess management list based on the number of work units, which registers the process handles and running status of each subsequently created subprocess.
[0015] After initialization, the main control process enters the scheduling state and begins performing its main control responsibilities, such as child process creation, signal adjustment, and status collection. Based on the number of work units N in the test parameters, N memory pressure application child processes are created. In one optional implementation, child process creation is achieved through process derivation; that is, the main control process calls the operating system's process creation interface to derive child processes. Each derived child process inherits the execution context of the main control process and then executes the preset pressure application logic.
[0016] The main control process iterates through the work unit indices (from 1 to N), instantiating a child process object for each work unit. During instantiation, a pressure application function is bound to the child process as its entry point logic, and the child process's unique initial configuration, such as initial memory size, memory access mode, access interval, and adjustment interval, is passed in as parameters. The main control process performs a startup operation on each child process object. The operating system allocates an independent process control block and process identifier (PID) for this purpose and adds the child process to the system scheduling queue. After startup, each child process participates in system scheduling as an independent scheduling entity.
[0017] Optionally, the controlling process registers the process handle and PID of each started child process in the previously constructed child process management list, forming a mapping relationship of working unit index - process handle - PID, for subsequent lifecycle management phases to query and call. Since each child process is created through operating system-level process derivation, each child process and the controlling process have independent memory spaces that are mutually isolated. Memory allocation, access, and release operations performed by any child process within its own memory space will not interfere with the memory state of other child processes or the controlling process. This characteristic allows each child process to exist as an independent unit for applying memory pressure, providing an architectural foundation for it to independently perform memory adjustments according to its own adjustment strategies.
[0018] Furthermore, the lifecycle management of child processes is uniformly implemented by the main control process, including three stages: maintaining and monitoring the running state, normal recycling upon test completion, and forced termination under abnormal conditions. During the test, the main control process continuously monitors the running state of each child process through previously registered process handles, including whether the child process is alive and has completed execution. The main control process also maintains a running flag or implements it through inter-process synchronization primitives, such as shared event objects. The running flag is used to indicate to each child process whether the test should continue. When the test duration reaches the preset test termination condition, the main control process sets the running flag to the terminated state. After each child process detects that the running flag is in the terminated state in its own execution loop, it performs resource cleanup, such as releasing the memory blocks it holds and triggering memory reclamation, and then exits on its own. The main control process performs a blocking wait operation on each child process one by one, that is, the main control process suspends its own execution until the corresponding child process completely terminates and the operating system completes the reclamation of the child process's resources, ensuring that no zombie processes are generated. When a child process encounters an exception or the main process receives an external interrupt signal, the main process can forcibly terminate the child process by sending a termination signal to end its execution. Subsequently, the main process will still block and wait on the child process to ensure its resources are completely reclaimed by the operating system, preventing residual processes from consuming system resources. In one optional implementation, the main control process also registers interrupt signal handling logic. When the main control process receives a keyboard interrupt or termination signal, it first performs termination and recycling operations on all child processes, and then performs its own cleanup and exit, ensuring that no surviving child processes are left in any exit path of the entire testing tool.
[0019] Step 120: The child process allocates an initial memory block in its own memory space according to the initially set memory size, and applies memory pressure to the system using the initial memory block.
[0020] Once the child process is started, it enters the execution pressure application logic. The memory block allocated to the child process is a live memory object that actually occupies the system's physical memory. By continuously holding and periodically accessing this memory block, the system's memory resources are actually occupied, thereby applying memory pressure to the system.
[0021] After the child process enters the stress application logic, it first allocates an initial memory block according to the initially set memory size. For example, the process reads the initial configuration of its unit passed by the main control process and extracts the initial memory size from it. In an optional implementation, the initial memory size is expressed in capacity units, which are derived from the parsing result of the test command or are preset default values when the test command is not specified. Within its own memory space, the child process initiates a memory allocation request to the runtime environment according to the initial memory size, constructing a contiguous memory block corresponding to the initial memory size, which is randomly readable and writable and has variable content, as the stress carrier. In an optional implementation, this memory block is implemented using a dynamic byte array data structure, such as a bytearray object in Python. When a bytearray object is constructed, it requests the corresponding size of actual memory from the runtime environment. The requested memory is actually mapped to physical memory pages, rather than a delayed virtual placeholder. Choosing a variable-length byte array as the implementation form of the memory block allows the memory block to be directly written to and read from after allocation, entering the stress application state without additional initialization steps, and its memory usage is strictly consistent with the initial memory size, providing an accurate statistical basis for subsequent memory tracking.
[0022] After memory block allocation, the child process registers the allocated memory size in the memory usage tracking mechanism, keeping the memory statistics on the main control process side synchronized with the actual allocation behavior of the child process. The child process keeps the initial memory block alive in its own memory space; that is, the memory block is not released or reclaimed by the runtime environment throughout the entire stress-bearing phase. This ensures that the child process always maintains the actual memory usage corresponding to the initial memory size in its resident memory set, forming a stable memory stress load. To prevent the physical pages occupied by the memory block from being swapped out of memory by the operating system and losing the stress-bearing effect, the child process periodically performs access operations on the memory block, including reading and writing.
[0023] Step 130: Each child process responds to the memory adjustment trigger signal sent by the main control process, reads its current memory space size, and adjusts its own memory space size according to the current memory space size and the adjustment parameters in the signal to obtain the target memory size.
[0024] For example, the adjustment parameter is an adjustment factor. Accordingly, each subprocess adjusts its own memory space size according to the current memory space size and the adjustment parameters in the signal to obtain the target memory size, which may include: taking the product of the current memory block size and the adjustment factor as the target memory size, wherein the adjustment factor is a positive rational number not equal to 1.
[0025] Accordingly, the method can also include the following steps: The main control thread creates an Event object for each memory pressure-applying subprocess using `multiprocessing.Manager()` according to a preset time interval; when the preset time interval is reached, the main control process simultaneously sets all Event objects, so that each memory pressure-applying subprocess receives a trigger signal simultaneously. Through this method, multiple pressure-applying units can synchronously begin memory adjustment at the same time. Utilizing a centralized and simultaneous triggering method ensures that the memory adjustment rounds of each subprocess are strictly aligned, guaranteeing consistency and predictability of the multi-unit pressure scenario in the time dimension.
[0026] Accordingly, each subprocess adjusts its own memory space size according to the current memory space size and the adjustment parameters in the signal to obtain the target memory size. This may further include: each subprocess individually acquiring a global lock; after acquiring the global lock, adjusting its own memory space size according to the current memory space size and the adjustment parameters in the signal; writing the adjusted memory space size into a global shared variable for memory usage; and releasing the global lock. Correspondingly, the method also includes: the main control process creating a shared dictionary using `multiprocessing.Manager().dict()`; each subprocess applying memory pressure storing its current memory allocation in the shared dictionary using its process identifier as the key; and the main control process reading the shared dictionary to obtain the memory allocation of each subprocess applying memory pressure and summing them to obtain the global memory usage.
[0027] For example, during the test initialization phase, the main control process creates an event object for each child process applying memory pressure through a cross-process sharing manager. In an optional implementation, the cross-process sharing manager is instantiated through a process sharing management interface. The event objects (Manager().Event()) created by this manager are hosted in an independent management process. The event object handles held by each child process are actually proxied to the same hosted object, thereby ensuring that modifications to the event state by the main control process can be perceived by all child processes in real time. Each created event object is initially in an unset state.
[0028] The main control process maintains an adjustment interval timer, the interval of which is configured by the test command (e.g., a default of 20 seconds). During test execution, the main control process cyclically checks whether the timer has reached the preset time interval. When the preset time interval is reached, the main control process simultaneously performs a setting operation on all event objects it has created, setting each event object to the set state. Since each subprocess corresponds to its own event object, and these event objects are set uniformly at the same time, each subprocess will receive a trigger signal simultaneously, thereby enabling multiple stress application units to synchronously start memory adjustment at the same time.
[0029] In each round of the memory pressure application loop, the child process checks whether its corresponding event object is in a set state. When the event object is detected as set, the child process confirms receipt of the memory adjustment trigger signal from the main control process and then enters the memory adjustment process. During the period when the event object is not set, the child process continues to perform the aforementioned memory pressure application operation. After receiving the trigger signal, the child process reads its current memory space size. In one optional implementation, the child process directly reads the actual size of the memory block it currently holds as the current memory space size; in another optional implementation, the child process reads the most recently registered memory allocation from the memory usage tracking record as the current memory space size. The results obtained by the two reading methods are consistent. Reading the current memory space size based on its own actual state ensures that subsequent adjustment calculations are always based on the actual usage level, avoiding the problem of potential discrepancies between the actual state and the direct specification of absolute target values.
[0030] The subprocess extracts adjustment parameters from the trigger signal. In one optional implementation, the adjustment parameter is an adjustment multiplier, which is a positive rational number not equal to 1. A multiplier greater than 1 indicates a memory expansion direction, and a value less than 1 indicates a memory contraction direction; a value of 1 is excluded because a multiplier of 1 does not change the memory space size and does not constitute a valid adjustment action. The adjustment multiplier is derived from the parsing result of the test command (e.g., the default is 2.0), or it can be dynamically specified by the main control process in each triggering round according to the control strategy.
[0031] The child process uses the product of the current memory block size and the adjustment factor as the target memory size, i.e.: Target memory size = Current memory space size × Adjustment factor. Through this product-based relative adjustment, this implementation can derive multiple dynamic load scenarios with minimal parameter configuration: When the adjustment factor is consistently greater than 1, the memory usage of each child process increases proportionally in each round, simulating a scenario where memory load gradually increases or even suddenly increases; when the adjustment factor is less than 1, the memory usage of each child process decreases proportionally in each round, simulating a scenario where the application gradually releases memory; when the adjustment factor alternates between being greater than 1 and less than 1, the memory usage of each child process fluctuates around the baseline value, simulating a steady-state fluctuation scenario formed by periodic business fluctuations. Furthermore, since the adjustment result is deterministically derived from the current value × the adjustment factor, the same initial configuration and adjustment factor sequence will inevitably produce the same load trajectory, ensuring the reproducibility of the test scenarios.
[0032] When multiple child processes concurrently perform memory adjustments, without mutual exclusion protection, other work units may simultaneously update shared records during the adjustment process, leading to inconsistencies between statistical values and the actual allocation state. To address this, this implementation introduces a global lock mutual exclusion mechanism in the adjustment execution phase. Specifically, this includes: before executing the adjustment action, each child process acquires a global lock individually. The global lock is a mutex lock, allowing only one work unit to hold it at a time; if the global lock is already held by another work unit when the child process initiates an acquisition request, the child process enters a waiting state until the global lock is released. After acquiring the global lock, the child process enters the critical section and performs the following operations: based on the current memory space size obtained in the aforementioned steps and the calculated target memory size, it determines the adjustment of its own memory space; subsequently, it writes the adjusted memory space size into the globally shared variable for memory usage, so that the global tracking record immediately reflects the adjusted memory usage level of this work unit. It should be noted that the global shared variables used in memory can adopt different sharing carriers in different operating modes: In multi-threaded mode, each worker thread shares the global variables within its own process and updates them through mutual exclusion using a global lock; In multi-process mode, the memory spaces of each worker process are isolated from each other, and the global shared variables used in memory are carried by a dictionary data structure shared across processes. The mutual exclusion discipline of the global lock also applies to the update process of the shared dictionary entries, ensuring data consistency when multiple processes update concurrently.
[0033] After the write operation is complete, the child process releases the global lock and exits the critical section, allowing the remaining waiting work units to enter in sequence. Through the critical section procedure of acquiring the lock, adjusting and writing, and releasing the lock, any read, modify, or write operation on a shared variable at any given time is an atomic and complete operation. This eliminates update loss and data corruption caused by concurrent updates from multiple work units, ensuring that the global memory usage aggregated by the main control process is strictly consistent with the actual memory allocation of each child process.
[0034] After the child process completes the above adjustments, it resets its corresponding event object to an unset state, or the main control process resets it uniformly so that it can be triggered again in the next adjustment cycle; then the child process returns to the pressure application process to continue to apply memory pressure to the system with the adjusted memory space.
[0035] Step 140: Each child process releases the current memory block in its own memory space and then reallocates a new memory block according to the target memory size to continue applying memory pressure to the system, in order to simulate test scenarios of memory shrinkage, sudden load and steady-state fluctuation.
[0036] The child process disconnects its reference to the currently held memory block, making the memory block unreachable. In one optional implementation, this disconnection is achieved by deleting the variable reference corresponding to the memory block or setting the reference to null. After the reference is disconnected, the runtime environment reclaims the space occupied by the memory block according to the memory management mechanism. In another optional implementation, the memory block is released immediately by the reference counting mechanism; that is, when the reference count of the memory block drops to zero, the runtime environment immediately reclaims the memory region it occupies. For large memory blocks, memory is usually directly allocated and returned through the system-level allocator, so the release action can effectively reduce the corresponding physical memory usage. This avoids incomplete memory release due to reclamation delays.
[0037] After the child process releases the current memory block, it reconstructs a new memory block in its own memory space according to the target memory size determined in the preceding steps. In one optional implementation, the new memory block uses the same variable-length byte array data structure as the initial memory block, and its memory usage is strictly consistent with the target memory size, ensuring that the adjusted load precisely corresponds to the configuration intent. After the new memory block is allocated, the child process updates the memory usage tracking record, updating the registered allocation amount of this work unit to the new memory block size.
[0038] The pressure is then applied using the new memory block. The child process uses the newly allocated memory block as the new pressure carrier, filling it with content and periodically accessing it according to the aforementioned pressure application process, making it resident in physical memory and forming a continuous and realistic memory pressure load. At this point, the memory pressure applied by the child process has switched from the old memory block before adjustment to the new memory block after adjustment, while the child process itself and the test process remain uninterrupted, maintaining the continuity of the test. After completing this round of adjustment, the child process resets its corresponding event object to an unset state, so that the main control process can send a trigger signal again by setting the event object in the next adjustment cycle. Subsequently, the child process returns to the pressure application loop, continuing to apply pressure with the current memory block until the event object is detected to be set again.
[0039] Through the aforementioned release-reallocation-continued pressure adjustment mechanism, combined with different configurations of adjustment multipliers and trigger timings, this implementation can simulate various dynamic memory load scenarios. In one optional implementation, the adjustment multiplier can be pre-configured uniformly by the test command; in another optional implementation, the adjustment multiplier is dynamically specified by the main control process in each triggering round according to a preset control strategy, thereby supporting more complex load timing orchestration. When the adjustment multiplier is a positive rational number less than 1, the memory usage of the child process after each round of adjustment decreases proportionally compared to the previous round, and the system experiences a gradual decline in memory usage. For example, if the child process is initially allocated 500MB of memory, the adjustment multiplier is 0.8, and the adjustment interval is 15 seconds, then the memory usage of the child process after each round of adjustment will be 400MB, 320MB, 256MB, etc., simulating the real behavior of the application gradually releasing memory. This scenario can be used to evaluate the response efficiency of the system's memory reclamation mechanism, i.e., the growth of available memory after memory release, the timeliness of page reclamation, and the stability of the system during the memory reduction process. When the adjustment factor is a large value greater than 1 and the adjustment interval is set short, the memory usage of the child process jumps sharply between adjacent trigger cycles, simulating the sudden surge in memory usage caused by a surge in instantaneous business requests. For example, if the child process is initially allocated 50MB of memory, the adjustment factor is 2.0, and the adjustment interval is 5 seconds, then the memory usage of the child process will climb from 50MB to 1600MB within 30 seconds, forming a steep memory load ramp-up curve in a short period of time. This scenario can be used to evaluate the system's emergency response capability under sudden increases in memory demand, including the timeliness of memory allocation, the performance of paging behavior, and the stability of the system under load surges. When the adjustment factor is alternately set between greater than 1 and less than 1 in each trigger cycle, the memory usage of the child process changes repeatedly around a certain baseline level, simulating the steady-state load pattern formed by periodic fluctuations in business. For example, if the main control process specifies an adjustment multiplier of 1.5 when triggered in even-numbered rounds and 0.7 when triggered in odd-numbered rounds, the memory usage of the child processes will exhibit a fluctuating trajectory of rising, falling, rising again, and falling again, generally remaining within a range near the baseline value. This scenario can be used to evaluate the long-term operational stability of the system under periodic memory loads, as well as the efficiency degradation of memory allocation and reclamation mechanisms under continuous repetitive operations. In the above scenarios, each rise and fall in child process memory usage is achieved through actual memory release and reallocation actions. The system-level memory reclamation mechanism and page replacement mechanism are actually triggered and participate in the response. Therefore, the system performance reflected in the test has a significantly higher degree of consistency with the system behavior under real business loads than simulation methods that only describe load changes numerically. At the same time, since the load level after each round of adjustment is deterministically derived from the current value multiplied by the adjustment multiplier, the test load trajectory is completely reproducible under the same initial configuration and multiplier sequence, providing a reliable basis for comparative testing between different system configurations.
[0040] This embodiment instantiates and starts a main control process based on an incoming test command. The main control process then creates memory pressure application subprocesses and manages their lifecycles. Each subprocess acts as an independent memory pressure application unit and has its own independent memory space. Within its own memory space, each subprocess allocates an initial memory block according to a pre-set memory size and applies memory pressure to the system using this initial memory block. Each subprocess responds to a memory adjustment trigger signal sent by the main control process by reading its current memory space size. Based on the current memory space size and the adjustment parameters in the signal, each subprocess adjusts its own memory space size to obtain a target memory size. After releasing the current memory block within its own memory space, each subprocess reallocates a new memory block according to the target memory size to continue applying memory pressure to the system, simulating test scenarios of memory shrinkage, sudden load, and steady-state fluctuations. The main control process sends memory adjustment trigger signals to each child process. Each child process responds to the signal, reads its current memory space size, calculates the target memory size based on the adjustment parameters carried in the signal, and then releases the current memory block in its own memory space and reallocates a new memory block according to the target memory size. This ensures the continuity of the testing process, avoids the restart overhead caused by test interruption, and allows a single continuous test to cover the complete performance of the system memory usage from low to high, from high to low, or repeated changes, significantly shortening the test cycle. When adjusting memory space, the child process first releases the currently held memory block and then reallocates it according to the target memory size. By configuring different adjustment parameters, multiple dynamic load scenarios can be derived, allowing for testing under conditions close to real business load. This effectively overcomes the shortcomings of existing fixed-intensity tests, which can only provide constant loads and whose test results deviate significantly from actual application scenarios. It can provide a more comprehensive and accurate evaluation of indicators such as the response efficiency of the system memory reclamation mechanism, page replacement behavior, and stability under load changes. By using the main control process to uniformly create and manage the lifecycle of memory pressure application subprocesses, testers can use the main control process as a single entry point to uniformly trigger and adjust multiple pressure application units. They can also independently construct differentiated memory loads for each unit, thereby building refined memory pressure scenarios under multi-unit concurrency conditions and comprehensively evaluating the system's scheduling and reclamation capabilities under multi-process concurrent memory operations.
[0041] Example 2 Figure 2This is a flowchart illustrating the memory adjustment method under stress testing provided in Embodiment 2 of the present invention. This embodiment is an optimization based on the above embodiment, and the method may further include the following steps: periodically collecting multi-dimensional load indicators of the system using the main control process, including: CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization; calculating the overall system load based on the dynamic weight corresponding to each load indicator; and adjusting the process priority of each subprocess using the main control process based on the overall system load and memory utilization, so as to ensure that critical processes of the system obtain resources first under high load, and restore the original priority after the high load drops to maintain the test effect.
[0042] See Figure 2 The memory adjustment method under stress testing includes: Step 210: Instantiate and start the main control process based on the incoming test command, use the main control process to create a memory pressure application subprocess, and manage the lifecycle of the memory pressure application subprocess.
[0043] Step 220: The main control process periodically collects multi-dimensional load indicators of the system, including: CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization.
[0044] After starting the test and creating child processes, the main control process initiates the system load monitoring mechanism. This mechanism, driven by the main control process, is implemented through an independent monitoring thread or a monitoring loop within the main control process, periodically collecting multi-dimensional operating system status indicators at preset time intervals. The main control process sets the load indicator collection cycle according to the test command configuration or default strategy. The selection of the cycle needs to balance real-time monitoring with system overhead, ensuring timely capture of drastic load fluctuations while avoiding excessively frequent system calls that could interfere with the test itself. The main control process then initiates the load monitoring task. In one optional implementation, the main control process spawns an independent monitoring thread specifically responsible for indicator collection, while the main thread focuses on sending trigger signals to child processes and summarizing global memory usage; the monitoring thread writes the latest collected indicators to a storage area accessible to the main control process via shared variables. Alternatively, the monitoring task can be directly embedded in the main control process's main loop, performing indicator collection during the intervals between each round of trigger signal issuance.
[0045] During each data collection cycle, the monitoring task obtains the following five core load metrics by calling the system information interface provided by the operating system or a third-party system monitoring library: CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization.
[0046] The monitoring task collects the overall CPU utilization at the current moment, that is, the percentage of time the CPU is in a non-idle state. This metric reflects the busyness of computing resources. When the CPU utilization is close to 100% for a long period, it indicates that the system's computing resources are saturated, and there may be intense competition among processes. Optionally, the average CPU utilization over the past sampling interval can be obtained by calling the cpu_percent interface through the system monitoring library.
[0047] The monitoring task collects the current system's physical memory usage rate, which is the ratio of allocated physical memory to the total physical memory of the system. This metric directly reflects the level of memory resource consumption; a high memory usage rate often indicates increased page swapping activity and higher memory allocation latency. Optionally, the monitoring task obtains the system's total memory and used memory by accessing the virtual memory information interface, and calculates the percentage value of memory usage.
[0048] The monitoring task collects the percentage of CPU time spent waiting for I / O operations to complete, i.e., I / O wait time. This metric reflects the degree of system congestion on storage I / O or network I / O. High I / O wait time usually indicates that disk or network I / O has become a system bottleneck, forcing processes to suspend while waiting for data read / write, thus reducing overall throughput. For example, the monitoring task obtains the I / O wait time percentage by reading CPU time statistics and converts it into a percentage of total CPU time.
[0049] The monitoring task collects network interface traffic statistics and calculates network bandwidth usage. This metric reflects the system's network interaction load; high network utilization may lead to network buffer overflows or request packet loss, impacting the performance of critical network processes. Optionally, the monitoring task reads the number of bytes received and sent from the network interface card (NIC) and calculates the rate of traffic change since the last collection, using this as the raw data for network utilization; or it calculates the percentage of bandwidth used based on the NIC's theoretical bandwidth as the network utilization rate.
[0050] The monitoring task collects the storage space utilization rate of storage devices, which is the ratio of used storage space to total storage space. This metric reflects the remaining disk capacity. Although it does not directly reflect disk I / O performance, excessively high disk utilization may lead to anomalies such as disk write blockage (due to insufficient space) or log recording failures. Optionally, the monitoring task obtains the utilization rate of the root partition or related test partitions by querying the file system usage interface to obtain the percentage value of disk utilization.
[0051] After collecting the above five types of indicators, the currently collected values are updated to the load indicator cache area. In an optional implementation, to smooth out occasional instantaneous fluctuations, the monitoring task can perform a moving average calculation on the most recent N collected values, and write the smoothed result as the final current system load indicator into the cache. The cache area provides a read-only access interface for the priority adjustment logic of the master process, ensuring that the data state on which the decision-making process is based remains consistent within a single decision cycle.
[0052] Step 230: Calculate the overall system load based on the dynamic weights corresponding to each load index.
[0053] In this implementation, after acquiring multi-dimensional load metrics such as CPU utilization, memory utilization, I / O wait time, network utilization, and disk utilization, the main control process calculates the overall system load using a weighted summation method. Unlike fixed-weighting methods, the weights for each load metric in this implementation are dynamic weights; that is, the weights are not preset fixed values but are dynamically adjusted based on the real-time status of the metrics or changes in the testing strategy. By assigning higher weights to metrics that are bottlenecked or under high load, the calculated overall system load can more accurately reflect the factors that have the greatest impact on system performance, thus providing a more accurate quantitative basis for subsequent priority adjustment decisions.
[0054] Load metric acquisition and preprocessing. The main control process reads the raw values of five types of load metrics for the current period from the load metric cache area. Since the units and ranges of each metric may differ, the main control process first performs normalization on the raw values, mapping them to a uniform numerical range. Normalization can be performed using a linear mapping method.
[0055] The main control process calculates the dynamic weights of five metrics—CPU, memory, I / O, network, and disk—at the current moment based on a preset dynamic weight adjustment strategy. In one optional implementation, the dynamic weights are determined adaptively based on the saturation or deviation of the metrics. Specifically, the main control process sets a baseline weight for each metric, reflecting its default importance in a typical testing scenario. Then, it calculates the deviation of the current metric value from a target threshold or historical average and generates a weight correction coefficient based on this deviation. In another optional implementation, the dynamic weights are switched according to the testing phase. The main control process activates different weight configuration tables in different testing phases based on the test type specified in the test command, such as I / O-intensive testing, compute-intensive testing, or end-to-end stress testing. For example, in a test simulating high-concurrency read / write operations, the dynamic weights for I / O wait time and network utilization are set to high values, while the weight for CPU utilization is reduced; in a test simulating large-scale computation, the opposite is true. Using this method, the calculated overall load can be kept consistent with the current test focus. A weighted summation is then performed to calculate the overall system load. The main control process uses the preprocessed index values and the dynamic weights determined above to perform a weighted summation operation to obtain the overall system load.
[0056] Step 240: Based on the overall system load and memory usage, adjust the process priority of each child process using the main control process to ensure that critical system processes have priority in obtaining resources under high load, and restore the original priority after the high load drops to maintain the test effect.
[0057] For example, adjusting the process priority of each child process based on the overall system load and memory usage using the main control process may include: when the memory usage exceeds a preset memory usage threshold, writing all child processes into a resource control group so that the memory usage of each child process is constrained by the maximum memory usage parameter set in the resource control group; when the overall load exceeds a preset maximum load threshold, adjusting the CPU scheduling priority of the main control process through a process priority adjustment interface, thereby adjusting the priority of each child process; and when the overall load recovers to a preset load range, adjusting the CPU scheduling priority of the main control process through a process priority adjustment interface to restore the priority of each child process to normal.
[0058] The master process first determines the system's memory pressure level. For example, it reads the current memory usage and compares it to a preset memory usage threshold. This threshold is set based on the safety margin of the test environment and represents the warning line when system memory resources enter a scarce state. Child processes are then added to resource control groups. When the current memory usage exceeds the preset threshold, the master process triggers a memory management mechanism, using the resource control group interface provided by the Linux kernel to apply memory pressure to all child processes and add them to specific resource control groups. In an optional implementation, the master process adds child processes to the control group by writing their process IDs (PIDs) to the cgroup.procs file in the corresponding cgroup directory.
[0059] After a child process joins a resource control group, the master process sets a maximum memory usage parameter (e.g., memory.max or memory.limit_in_bytes) in the group's configuration parameters. This parameter defines the upper limit of the total physical memory that all processes within the control group can use. Through this constraint, the memory usage behavior of each child process is subject to strict control by the operating system. For example, when the total memory usage within the group approaches this limit, the kernel's memory reclamation mechanism will prioritize reclaiming memory pages within the group or triggering an OutOfMemoryError (OOM). The killer process will terminate within the group, ensuring that the operation of critical system processes outside the control group is never threatened. This achieves the goal of prioritizing memory resources for critical system processes under high memory pressure.
[0060] In addition, it is necessary to determine whether the overall load exceeds the maximum load threshold. The master process obtains the currently calculated overall system load and compares it with the preset maximum load threshold. The preset maximum load threshold is a quantitative indicator reflecting the bottleneck of the overall system processing capacity. When the overall load exceeds this value, it indicates that the system is overloaded and the response latency has increased significantly. The CPU scheduling priority of the master process is adjusted under high load. When it is determined that the overall system load exceeds the preset maximum load threshold, the master process performs a de-priority operation through the process priority adjustment interface. The master process calls the process scheduling interface provided by the operating system to lower its own CPU scheduling priority. Based on the process scheduling hierarchy and specific implementation, adjusting the CPU scheduling priority of the master process will further adjust the priority of each child process. While adjusting its own priority, the master process also propagates this priority setting to child processes within the same scheduling domain, or the child processes themselves inherit the scheduling attributes of the master process, thus placing all child processes at a lower position when acquiring CPU time slices. By lowering the priority of the test process, the operating system's CPU scheduler will prioritize scheduling higher-priority critical business processes, thereby ensuring that critical system processes can obtain CPU computing resources first under high load scenarios, and avoiding interference from test load on normal business operations.
[0061] To prevent the test process from remaining in a low-priority state for an extended period after system load fluctuations, thus affecting test results, the main control process is also responsible for monitoring the load decline and performing recovery operations. This may include: after performing a weight reduction operation, the main control process continues to monitor changes in the overall system load. When it is determined that the overall system load has fallen back to a preset load range, it indicates that the system has escaped the overload state and has a certain degree of resource redundancy. The preset load range is typically a safe range below the maximum load threshold. When it is confirmed that the overall load has recovered to the preset range, the main control process again restores its CPU scheduling priority to the original priority at test startup through the process priority adjustment interface. Correspondingly, the priority of each child process also returns to normal. At this time, the child processes can compete for CPU resources with normal scheduling weights and continue to apply memory pressure to the system at the original intensity, thereby maintaining test results and completing the predetermined test tasks.
[0062] Step 250: The child process allocates an initial memory block in its own memory space according to the initially set memory size, and applies memory pressure to the system using the initial memory block.
[0063] Step 260: In response to the memory adjustment trigger signal sent by the main control process, each child process reads its current memory space size. Each child process adjusts its own memory space size according to the current memory space size and the adjustment parameters in the signal to obtain the target memory size.
[0064] Step 270: Each child process releases the current memory block in its own memory space and then reallocates a new memory block according to the target memory size to continue applying memory pressure to the system, in order to simulate test scenarios of memory shrinkage, sudden load and steady-state fluctuation.
[0065] This embodiment adds the following steps: The main control process periodically collects multi-dimensional system load metrics, including CPU utilization, memory utilization, I / O wait time, network utilization, and disk utilization; the overall system load is calculated based on the dynamic weights corresponding to each load metric; and the main control process adjusts the process priority of each child process based on the overall system load and memory utilization to ensure that critical system processes receive priority resources under high load and restore the original priority after the high load subsides to maintain test effectiveness. cgroups are used to define inviolable resource limits for child processes at the memory level, ensuring the memory safety of critical system processes; dynamic priority adjustment at the CPU level achieves peak smoothing and valley filling of test load and critical processes, proactively yielding when the system is overloaded and restoring full speed when the system is idle. This intelligent resource control strategy enables memory stress testing to run safely and stably in production or mixed load environments, achieving both the detection of system limits and maximizing the continuity and responsiveness of critical services.
[0066] In a preferred embodiment of this example, the method may further include the following steps: defining a state space, wherein the state space is represented by a state vector composed of system load indicators, the system load indicators including at least one of CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization; defining an action space, wherein the action space is represented by a candidate action set composed of executable scheduling and control actions, the scheduling and control actions including at least one of adjusting scheduling parameters, adjusting process priority, and adjusting resource reservation; and defining a reward function, wherein the reward function evaluates the control effect based on at least one of system stability, test efficiency, and resource utilization, and outputs... The system first provides an immediate reward; then inputs the current state vector into a reinforcement learning algorithm, which performs learning and policy updates based on the candidate action set and the immediate reward. It then determines whether a preset training termination condition is met. If not, the updated system load metric is used as the current state vector, and the process returns to the step of inputting the current state vector into the reinforcement learning algorithm to continue training. If yes, an optimized policy is output. The preset training termination condition includes: the policy update magnitude of the reinforcement learning algorithm being less than a preset convergence threshold, or the training epochs reaching a preset epoch threshold. The optimized policy is input into the master process, which adjusts the process priority of each subprocess according to the optimized policy. To further improve the accuracy and adaptability of subprocess priority adjustment under different load scenarios, a reinforcement learning algorithm is introduced to dynamically generate the optimal control policy. The master process, as an agent, interacts with the system environment, constructing a reinforcement learning model by defining a state space, action space, and reward function. The agent learns and optimizes the policy by continuously trying to control actions and observing system feedback. Once the training meets the termination condition, the output optimization strategy is loaded into the main control process, guiding it to adjust the process priorities of child processes in real time, thereby maximizing testing efficiency and resource utilization while ensuring system stability. The collected system load metrics are preprocessed and combined into a state vector, which can be a five-dimensional vector. The action space is represented by a set of candidate actions consisting of executable scheduling and control actions. These scheduling and control actions include at least adjusting scheduling parameters, adjusting process priorities, and adjusting resource reservations, such as memory or CPU quotas in cgroups. The action space can be designed as a discrete action set; in each decision step, an action is selected from this set for execution. To quantify the control effect, a reward function is defined to guide the agent's learning direction. After executing an action, the system state transitions to the next time step, and the main control process evaluates the control effect based on at least one of system stability, testing efficiency, and resource utilization. For example, the current state vector is input. The reinforcement learning algorithm receives the current state vector as input.In one optional implementation, a Deep Q-Network (DQN) algorithm is employed. The state vector is input into the neural network, and the network outputs a value estimate (Q-value) for each action in the candidate action set. An action is then selected and executed. The reinforcement learning algorithm selects an action from the candidate action set according to the current policy and issues it to the main control process for execution. After the action is executed, the system enters the next state and generates an immediate reward. In the DQN algorithm, the weight parameters of the neural network are updated by minimizing the loss function. Through continuous backpropagation, the algorithm gradually optimizes the policy, maximizing the expected long-term cumulative reward for the action selected in a given state. This enables the memory stress testing tool to possess self-learning and self-optimization capabilities, significantly improving the security and effectiveness of operation in complex testing environments.
[0067] Example 3 Figure 3 This is a schematic diagram of the memory adjustment device under stress testing provided in Embodiment 3 of the present invention. See also... Figure 3 The memory adjustment device under stress testing includes: The instantiation module 310 is used to instantiate and start the main control process based on the incoming test command, use the main control process to create memory pressure application subprocesses, and manage the life cycle of the memory pressure application subprocesses. Each subprocess is an independent memory pressure application unit and each subprocess has an independent memory space. The allocation module 320 is used to allocate an initial memory block in the child process's own memory space according to the initially set memory size, and to apply memory pressure to the system with the initial memory block; The reading module 330 is used to read the current memory space size of each child process in response to the memory adjustment trigger signal sent by the main control process; The adjustment module 340 is used to adjust the size of its own memory space by each subprocess according to the current memory space size and the adjustment parameters in the signal, so as to obtain the target memory size; The continuation module 350 is used to utilize each child process to release the current memory block in its own memory space, and then reallocate a new memory block according to the target memory size to continue to apply memory pressure to the system, so as to simulate test scenarios of memory shrinkage, sudden load and steady-state fluctuation.
[0068] The memory adjustment device under stress testing provided in this embodiment instantiates and starts a main control process based on the incoming test command. The main control process creates memory pressure application subprocesses and manages their lifecycles. Each subprocess acts as an independent memory pressure application unit and has its own independent memory space. Within its own memory space, each subprocess allocates an initial memory block according to a pre-set memory size and applies memory pressure to the system using this initial memory block. Each subprocess responds to a memory adjustment trigger signal sent by the main control process and reads its current memory space size. Based on the current memory space size and the adjustment parameters in the signal, each subprocess adjusts its own memory space size to obtain a target memory size. After releasing the current memory block within its own memory space, each subprocess reallocates a new memory block according to the target memory size to continue applying memory pressure to the system, simulating test scenarios such as memory shrinkage, sudden load, and steady-state fluctuations. The main control process sends memory adjustment trigger signals to each child process. Each child process responds to the signal, reads its current memory space size, calculates the target memory size based on the adjustment parameters carried in the signal, and then releases the current memory block in its own memory space and reallocates a new memory block according to the target memory size. This ensures the continuity of the testing process, avoids the restart overhead caused by test interruption, and allows a single continuous test to cover the complete performance of the system memory usage from low to high, from high to low, or repeated changes, significantly shortening the test cycle. When adjusting memory space, the child process first releases the currently held memory block and then reallocates it according to the target memory size. By configuring different adjustment parameters, multiple dynamic load scenarios can be derived, allowing for testing under conditions close to real business load. This effectively overcomes the shortcomings of existing fixed-intensity tests, which can only provide constant loads and whose test results deviate significantly from actual application scenarios. It can provide a more comprehensive and accurate evaluation of indicators such as the response efficiency of the system memory reclamation mechanism, page replacement behavior, and stability under load changes. By using the main control process to uniformly create and manage the lifecycle of memory pressure application subprocesses, testers can use the main control process as a single entry point to uniformly trigger and adjust multiple pressure application units. They can also independently construct differentiated memory loads for each unit, thereby building refined memory pressure scenarios under multi-unit concurrency conditions and comprehensively evaluating the system's scheduling and reclamation capabilities under multi-process concurrent memory operations.
[0069] Based on the above embodiments, the adjustment parameter is an adjustment multiplier, and correspondingly, the adjustment module includes: As a unit, it is used to take the product of the current memory block size and the adjustment factor as the target memory size, wherein the adjustment factor is a positive rational number not equal to 1.
[0070] Based on the above embodiments, the device further includes: The object creation module is used by the main control thread to create an Event object for each child process under memory pressure according to a preset time interval using multiprocessing.Manager(). Simultaneously, a module is configured so that when the preset time interval is reached, the main control process simultaneously sets all the Event objects, so that each memory pressure application subprocess simultaneously receives a trigger signal.
[0071] Based on the above embodiments, the adjustment module includes: The adjustment unit is used to acquire a global lock individually for each child process. After acquiring the global lock, it adjusts its own memory space size according to the current memory space size and the adjustment parameters in the signal, writes the adjusted memory space size into the global shared variable for memory use, and releases the global lock.
[0072] Based on the above embodiments, the device further includes: A shared field creation module is used to create a shared dictionary using the main control process via multiprocessing.Manager().dict(); The storage module is used to store the current memory allocation of each child process applying the memory pressure in the shared dictionary using its own process identifier as the key and global shared variables. The accumulation module is used by the main control process to obtain the memory allocation of each memory pressure-applying child process by reading the shared dictionary, and accumulates it to obtain the global memory usage.
[0073] Based on the above embodiments, the device further includes: The periodic data collection module is used to periodically collect multi-dimensional load indicators of the system using the main control process. These multi-dimensional load indicators include: CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization. The calculation module is used to calculate the overall system load based on the dynamic weights corresponding to each load indicator. The priority adjustment module is used to adjust the process priority of each child process by the main control process based on the overall system load and memory usage, so as to ensure that the critical processes of the system get resources first under high load, and restore the original priority after the high load drops to maintain the test effect.
[0074] Based on the above embodiments, the priority adjustment module includes: The write unit is used to write all child processes into the resource control group when the memory usage rate is greater than the preset memory usage rate threshold, so that the memory usage of each child process is constrained by the maximum memory usage parameter set in the resource control group. The priority adjustment unit is used to adjust the CPU scheduling priority of the main control process through the process priority adjustment interface when the overall load exceeds the preset maximum load threshold, thereby adjusting the priority of each child process.
[0075] The recovery unit is used to adjust the CPU scheduling priority of the main control process through the process priority adjustment interface when the overall load recovers to the preset load range, so as to restore the priority of each child process to normal.
[0076] Based on the above embodiments, the device further includes: Define a state space, which is represented by a state vector composed of system load metrics, including at least one of CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization. The first definition module is used to define the action space, which is represented by a set of candidate actions consisting of executable scheduling and control actions, wherein the scheduling and control actions include at least one of adjusting scheduling parameters, adjusting process priority, and adjusting resource reservation. The second definition module is used to define a reward function, which evaluates the control effect based on at least one of system stability, test efficiency and resource utilization, and outputs an instant reward. The update module is used to input the current state vector into the reinforcement learning algorithm, which then performs learning and policy updates based on the candidate action set and the immediate reward. The judgment module is used to determine whether the preset training termination condition is met. If not, the system load index after policy update is used as the current state vector again, and the step of inputting the current state vector into the reinforcement learning algorithm is returned to continue training. If yes, the optimization policy is output. The preset training termination condition includes: the policy update magnitude of the reinforcement learning algorithm is less than the preset convergence threshold, or the training rounds reach the preset round threshold. An optimization module is used to input the optimization strategy into the main control process, and the main control process adjusts the process priority of each subprocess according to the optimization strategy.
[0077] The memory adjustment device under stress test provided in the embodiments of the present invention can execute the memory adjustment method under stress test provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the method.
[0078] Example 4 Figure 4This is a schematic diagram of the structure of a terminal provided in Embodiment 4 of the present invention. Figure 4 A block diagram is shown of an exemplary terminal 12 suitable for implementing embodiments of the present invention. Figure 4 The terminal 12 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0079] like Figure 4 As shown, terminal 12 is presented in the form of a general-purpose computing terminal. The components of terminal 12 may include, but are not limited to: one or more processors or processing units 16, system memory 28, and bus 18 connecting different system components (including system memory 28 and processing unit 16).
[0080] Bus 18 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.
[0081] Terminal 12 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by terminal 12, including volatile and non-volatile media, removable and non-removable media.
[0082] 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 32. Terminal 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 used to read and write non-removable, non-volatile magnetic media (… Figure 4 Not shown; usually referred to as a "hard drive"). Although Figure 4 Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and 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) may be provided. In these cases, each drive may be connected to bus 18 via one or more data media interfaces. Memory 28 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of the present invention.
[0083] A program / utility 40 having a set (at least one) of program modules 42 may be stored, for example, in memory 28. Such program modules 42 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 42 typically perform the functions and / or methods described in the embodiments of the present invention.
[0084] Terminal 12 can also communicate with one or more external terminals 14 (e.g., keyboard, pointing terminal, display 24, etc.), one or more terminals that enable a user to interact with terminal 12, and / or any terminal (e.g., network card, modem, etc.) that enables terminal 12 to communicate with one or more other computing terminals. This communication can be performed via input / output (I / O) interface 22. Furthermore, terminal 12 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 20. As shown, network adapter 20 communicates with other modules of terminal 12 via bus 18. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with terminal 12, including but not limited to: microcode, terminal drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0085] The processing unit 16 executes various functional applications and data processing by running programs stored in the system memory 28, such as implementing the memory adjustment method under stress test provided in the embodiments of the present invention.
[0086] Example 6 Embodiment 6 of the present invention also provides a storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the memory adjustment method under stress test as described in any of the above embodiments.
[0087] The computer storage medium of this invention can be any combination of one or more computer-readable media. A computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. For example, a computer-readable storage medium can be, but is 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 having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this document, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0088] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, capable of sending, propagating, or transmitting programs for use by or in connection with an instruction execution system, apparatus, or device.
[0089] Program code contained on a computer-readable medium may be transmitted using any suitable medium, including, but not limited to, wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0090] Computer program code for performing the operations of this invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, as well as conventional procedural programming languages such as "C" or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or terminal. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0091] Note that the above description is merely a preferred embodiment of the present invention and the technical principles employed. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and various obvious changes, readjustments, and substitutions can be made without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in detail through the above embodiments, the present invention is not limited to the above embodiments, and may include many other equivalent embodiments without departing from the concept of the present invention, the scope of which is determined by the scope of the appended claims.
Claims
1. A method for adjusting memory under stress testing, characterized in that, include: The main control process is instantiated and started based on the incoming test command. The main control process is used to create memory pressure application subprocesses and manage the life cycle of the memory pressure application subprocesses. Each subprocess is an independent memory pressure application unit and each subprocess has an independent memory space. The child process allocates an initial memory block in its own memory space according to the initially set memory size, and applies memory pressure to the system using the initial memory block; Each child process responds to the memory adjustment trigger signal sent by the main process and reads its current memory space size; Each subprocess adjusts its own memory space size based on the current memory space size and the adjustment parameters in the signal to obtain the target memory size; Each child process releases the current memory block in its own memory space and then reallocates a new memory block according to the target memory size to continue applying memory pressure to the system, in order to simulate test scenarios of memory shrinkage, sudden load and steady-state fluctuation.
2. The method according to claim 1, characterized in that, The adjustment parameter is the adjustment factor. Accordingly, each subprocess adjusts its own memory space size based on the current memory space size and the adjustment parameters in the signal to obtain the target memory size, including: The target memory size is the product of the current memory block size and the adjustment factor, where the adjustment factor is a positive rational number not equal to 1.
3. The method according to claim 1, characterized in that, The method further includes: The main control thread creates an Event object for each child process that experiences memory pressure, based on a preset time interval, using multiprocessing.Manager(). When the preset time interval is reached, the main control process simultaneously sets all the Event objects, so that each memory pressure application subprocess simultaneously receives a trigger signal.
4. The method according to claim 3, characterized in that, Each subprocess adjusts its own memory space size according to the current memory space size and the adjustment parameters in the signal to obtain the target memory size, including: Each child process acquires the global lock independently. After acquiring the global lock, it adjusts its own memory space size according to the current memory space size and the adjustment parameters in the signal, writes the adjusted memory space size into the global shared variable for memory use, and releases the global lock.
5. The method according to claim 1, characterized in that, The method further includes: The main control process creates a shared dictionary using multiprocessing.Manager().dict(); Each child process applying the memory pressure stores its current memory allocation in the shared dictionary using its own process identifier as the key and a globally shared variable. The main control process reads the shared dictionary to obtain the memory allocation of each memory pressure-applying child process and sums them up to obtain the global memory usage.
6. The method according to claim 1, characterized in that, The method further includes: The system uses a master process to periodically collect multi-dimensional load metrics, including CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization. The overall system load is calculated based on the dynamic weight corresponding to each load indicator. Based on the overall system load and memory usage, the process priority of each child process is adjusted by the main control process to ensure that critical system processes have priority in obtaining resources under high load, and to restore the original priority after the high load drops to maintain the test effect.
7. The method according to claim 6, characterized in that, The step of adjusting the process priority of each child process based on the overall system load and memory usage using the main control process includes: When memory usage exceeds a preset memory usage threshold, all child processes are written into the resource control group so that the memory usage of each child process is constrained by the maximum memory usage parameter set in the resource control group. When the overall load exceeds the preset maximum load threshold, the CPU scheduling priority of the main control process is adjusted through the process priority adjustment interface, thereby adjusting the priority of each child process; When the overall load recovers to the preset load range, the CPU scheduling priority of the main control process is adjusted through the process priority adjustment interface to restore the priority of each child process to normal.
8. The method according to claim 7, further comprising: Define a state space, which is represented by a state vector composed of system load metrics, including at least one of CPU utilization, memory utilization, IO wait time, network utilization, and disk utilization. Define an action space, which is represented by a set of candidate actions consisting of executable scheduling and control actions, wherein the scheduling and control actions include at least one of adjusting scheduling parameters, adjusting process priority, and adjusting resource reservation. Define a reward function, which evaluates the control effect based on at least one of system stability, test efficiency, and resource utilization, and outputs an immediate reward; The current state vector is input into the reinforcement learning algorithm, which then performs learning and policy updates based on the candidate action set and the immediate reward. Determine whether the preset training termination condition is met. If not, use the updated system load index as the current state vector and return to the step of inputting the current state vector into the reinforcement learning algorithm to continue training. If so, then the optimization strategy is output. The preset training termination conditions include: the policy update magnitude of the reinforcement learning algorithm is less than the preset convergence threshold, or the training rounds reach the preset round threshold. The optimization strategy is input into the main control process, and the main control process adjusts the process priority of each child process according to the optimization strategy.
9. A memory adjustment device under stress testing, characterized in that, include: The instantiation module is used to instantiate and start the main control process based on the incoming test command, use the main control process to create memory pressure application subprocesses, and manage the life cycle of the memory pressure application subprocesses. Each subprocess is an independent memory pressure application unit and each subprocess has an independent memory space. The allocation module is used to allocate an initial memory block in the child process's own memory space according to the initially set memory size, and to apply memory pressure to the system with the initial memory block; The read module is used to read the current memory space size of each child process in response to the memory adjustment trigger signal sent by the main process; The adjustment module is used to adjust the size of each subprocess's memory space according to the current memory space size and the adjustment parameters in the signal, so as to obtain the target memory size; The continuation module is used to utilize each child process to release the current memory block in its own memory space, and then reallocate a new memory block according to the target memory size to continue to apply memory pressure to the system, so as to simulate test scenarios of memory shrinkage, sudden load and steady-state fluctuation.
10. A terminal, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the memory tuning method under stress as described in any one of claims 1-8.
11. A storage medium containing computer-executable instructions, characterized in that, The computer-executable instructions, when executed by a computer processor, are used to perform the memory tuning method under stress testing as described in any one of claims 1-8.
