High-concurrency charging pile simulator based on preemptive scheduling algorithm
By using the occupation scheduling algorithm and non -blocking IO model in the charging pile simulator, high -combination and stability are achieved, solving the problem of low efficiency in existing technology and high resource occupation. Realize automatic repeats and resource destruction.
Patent Information
- Application Number
- CN202411338900.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-25
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2044-09-25
AI Technical Summary
The existing charging pile simulator technology is inefficient under high concurrency, has a large overhead of switching between threads, is over-used in system resources, and lacks an effective reconnection mechanism and thread destruction mechanism, which affects the availability and stability of the simulator.
Adopt a high -concurrency charging pile simulator based on the occupied scheduling algorithm, and encapsulate the simulator into a suspension and restoration of execution through the non -blocking IO model and coroutine packaging module. Packed and introduced the heavily connected mechanism and resource destruction mechanism of the simulator.
It improves the concurrent processing capability and stability of the simulator, reduces the overhead of system resources, ensures that the simulator can automatically reconnect and destroys no longer used resources when it is offline, and improves the overall performance and reliability of the system.
Smart Images

Figure CN119335896A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of charging pile simulators, and in particular relates to a high-concurrency charging pile simulator based on a preemptive scheduling algorithm. Background Art
[0002] With the popularity and development of electric vehicles, the demand for charging piles has increased dramatically, and the testing and verification of charging piles has become particularly important. In order to ensure the quality and performance of charging piles, it is usually necessary to develop charging pile simulators for a large number of tests. The existing charging pile simulator technology mainly relies on multi-threading technology to batch create simulators, which interact with the charging platform to simulate the workflow of real charging piles. However, this technology has certain limitations and shortcomings. First, due to the limitations of multi-threading technology itself, three threads need to be generated for each simulator created: simulator instance thread, read instruction thread, and send instruction thread. When the number of simulators reaches a certain scale, the switching overhead between threads becomes very large, resulting in untimely sending and receiving of instructions, greatly reducing the overall efficiency of the system, and the existence of a large number of threads also significantly consumes CPU resources. Secondly, the existing technology lacks an effective reconnection mechanism and thread destruction mechanism when the simulator is off-grid, which means that once the simulator loses connection with the charging platform, it will not be able to automatically re-establish the connection, nor can it effectively release resources that are no longer used. This not only affects the availability and stability of the simulator, but also leads to unnecessary system resource occupation. These problems limit the application scope and scalability of existing charging pile simulator technology, so a new technical solution is needed to overcome these defects in order to improve the concurrent processing capability and stability of the simulator. Summary of the invention
[0003] In order to overcome the shortcomings of the prior art, the purpose of the present invention is to provide a high-concurrency charging pile simulator based on a preemptive scheduling algorithm, aiming to solve the problem of excessive system resource usage such as inefficiency caused by creating too many simulators at the same time and the problem of the simulator being unable to automatically reconnect after being off the network.
[0004] To solve the above problems, the technical solution adopted by the present invention is as follows: a high-concurrency charging pile simulator based on a preemptive scheduling algorithm, comprising: a coroutine encapsulation module under a non-blocking IO model, a preemptive scheduling algorithm module and a simulator creation and destruction management module, wherein: the coroutine encapsulation module is used to encapsulate the charging pile simulator into a coroutine that can be paused and resumed; the preemptive scheduling algorithm module is used to schedule the execution of the coroutine, and when the coroutine encounters a blockage, it automatically pauses and saves the context, and when the blockage is released, the context is reloaded and the execution is resumed; the simulator creation and destruction management module is used to manage the creation, reconnection and destruction of the simulator, and automatically attempts to reconnect when the simulator is off the network, and destroys the simulator resources after the reconnection fails.
[0005] Compared with the prior art, the beneficial effects of the present invention are as follows: the present invention uses a non-blocking IO model, achieves high concurrency through coroutines and preemptive scheduling algorithms, avoids the waiting time caused by blocking operations, enables concurrent execution, and encapsulates the simulator through coroutine technology, so that each simulator can be suspended and resumed, reducing the overhead of system resources, and introduces a simulator reconnection mechanism and simulator scheduling management to ensure that the simulator can automatically reconnect when it is off the network, and can destroy the corresponding resources after reconnection fails. The stability and reliability of the simulator are improved.
[0006] In the above-mentioned charging device simulator, the steps of the preemptive scheduling algorithm include: S1: initializing the scheduler and creating a global double-ended queue to save all coroutines to be executed; S2: starting the scheduler, starting the scheduler in the thread, and entering the dead loop mode; S3: the scheduler obtains the coroutine from the queue through the preemptive algorithm and executes it.
[0007] In the above-mentioned charging device simulator, in step S2, the current system is scanned regularly, and when it is detected that a user has created a simulator, the simulator is added to the queue; when a simulator that needs to be destroyed is detected, the simulator is removed from the queue and marked as destroyed.
[0008] In the above-mentioned charging device simulator, in step S3, if a blockage occurs, the coroutine will automatically pause and give up the CPU control to the scheduler, push the current coroutine into the stack, and rejoin the end of the queue; when the simulator instruction reading and sending is completed and the sleep state stops, the coroutine will be marked as ready and added to the first place in the queue by the scheduler.
[0009] In the above-mentioned charging device simulator, the coroutine encapsulation module adopts a non-blocking IO model when the simulator executes operations such as reading the server communication port, writing back instructions to the server communication port, sending heartbeat packets, sending voltage and status, so as to avoid waiting time caused by blocking operations.
[0010] The above-mentioned charging device simulator, the simulator creation and destruction management module also includes an off-grid reconnection mechanism, when the simulator loses connection with the charging platform communication terminal, it automatically attempts to reconnect.
[0011] The above-mentioned charging device simulator, the simulator creation and destruction management module also includes a simulator resource destruction mechanism, which can destroy the simulator resources and release system resources when the simulator fails to reconnect after being disconnected from the network.
[0012] In the above-mentioned charging device simulator, the preemptive scheduling algorithm module also includes two additional threads, each of which has its own scheduler, which is responsible for the reading and sending operations of the simulator respectively, so as to reduce the delay problem and improve the execution efficiency of the simulator.
[0013] In the above-mentioned charging device simulator, the coroutine encapsulation module uses the coroutine pause and resume mechanism to enable the simulator to release CPU resources for other coroutines to use when encountering a blocking operation.
[0014] The above-mentioned charging device simulator, the simulator creation and destruction management module also includes simulator state management, which can monitor the state changes of the simulator. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a flow chart of the technical solution of an embodiment of the present invention;
[0016] Figure 2 A flowchart of a scheduler scheduling according to an embodiment of the present invention;
[0017] Figure 3 A schematic diagram of the steps of a preemptive scheduling algorithm according to an embodiment of the present invention; DETAILED DESCRIPTION
[0018] The embodiments of the present invention are described in detail below. Figures 1 to 3 , an embodiment of the present invention provides a high-concurrency charging pile simulator based on a preemptive scheduling algorithm, including: a coroutine encapsulation module under a non-blocking IO model, a preemptive scheduling algorithm module, and a simulator creation and destruction management module, wherein: the coroutine encapsulation module is used to encapsulate the charging pile simulator into a coroutine that can be suspended and resumed; the preemptive scheduling algorithm module is used to schedule the execution of the coroutine, and when the coroutine encounters a blockage, it automatically pauses and saves the context, and when the blockage is released, the context is reloaded and the execution is resumed; the simulator creation and destruction management module is used to manage the creation, reconnection and destruction of the simulator, and automatically attempts to reconnect when the simulator is off the network, and destroys the simulator resources after the reconnection fails. The present invention uses a non-blocking IO model, and achieves high concurrency through coroutines and preemptive scheduling algorithms, avoiding the waiting time caused by blocking operations, so that the degree can be executed concurrently, and encapsulates the simulator through coroutine technology, so that each simulator can be suspended and resumed, reducing the overhead of system resources, and at the same time introduces a simulator off-reconnection mechanism and simulator scheduling management to ensure that the simulator can automatically reconnect when off the network, and can destroy the corresponding resources after the reconnection fails. Improve the stability and reliability of the simulator.
[0019] Further, refer to Figure 1 , the flow chart of the technical solution of the present invention is as follows Figure 1As shown, after the simulator of the present invention is created, the system will create asynchronous tasks for receiving and sending instructions. In each task, polling is performed to send and receive instructions. When an instruction fails to be sent, the simulator will automatically try to reconnect. After the reconnection is successful, the polling will continue. After the reconnection fails, it will be marked as off-grid and the simulator resources will be destroyed. Furthermore, the simulator of the present invention has multiple blocking operations during operation, including reading the server communication port in the form of a file descriptor, writing back instructions to the server communication port, sending a heartbeat packet every 6 seconds, sending the voltage and status every 3 seconds during charging, scanning the server communication port every 1 second, etc. The above operations include IO operations, network requests, and sleep, which will block the execution of the code, so that the CPU must wait for the blocking operation to be completed before it can continue to execute. In order to avoid program blocking, a non-blocking IO model is used. Further, referring to Figure 2 , the simulator is encapsulated by means of coroutines. Here, the coroutine represents a subroutine of a single simulator, which can be suspended and resumed. Furthermore, the preemptive scheduling algorithm module starts the scheduler in the thread. The scheduling flowchart is shown in the figure. There are three simulators in the program, namely simulator 1, simulator 2 and simulator 3. When the program starts running, the execution code 1 of simulator 1 will be executed first. When encountering the moment of Socket reading and sending instructions, the operating system will be blocked by network requests and IO reading and writing operations, and the scheduler will automatically switch to the simulator 2 in the next queue to continue execution; when simulator 2 encounters the moment of Socket reading and sending instructions, the operating system will be blocked by network requests and IO reading and writing operations, and the scheduler will automatically switch to the simulator 3 in the next queue to continue execution; when simulator 3 encounters the moment of Socket reading and sending instructions, the operating system will be blocked by network requests and IO reading and writing operations, and the scheduler will automatically switch to the first simulator 1 to obtain the results of IO reading and writing and the results of instruction sending and receiving, and execute code 2; switch to the second simulator 2, obtain the results of IO reading and writing and the results of instruction sending and receiving, and execute code 2; switch to the third simulator 3, obtain the results of IO reading and writing and the results of instruction sending and receiving, and execute code 2. The above operations are performed repeatedly to achieve a concurrent effect.
[0020] Furthermore, refer to Figure 3, the steps of the preemptive scheduling algorithm include: S1: Initialize the scheduler, create a global double-ended queue to save all coroutines to be executed; S2: Start the scheduler, start the scheduler in the thread, and enter the dead loop mode; S3: The scheduler obtains the coroutine from the queue and executes it through the preemptive algorithm. Specifically, in step S1, when the scheduler is initialized, the current state of each coroutine should be marked at the same time; in step S2, the current system is scanned regularly, and when it is detected that the user has created a simulator, the simulator is added to the queue; when the simulator that needs to be destroyed is detected, the simulator is removed from the queue and marked as destroyed; in step S3, if blocked, the coroutine will automatically pause and give up the CPU control to the scheduler, push the current coroutine into the stack, and rejoin the end of the queue; when the simulator instruction reading and sending are completed and the sleep stops, the coroutine will be marked as ready and added to the first place in the queue by the scheduler. Preferably, the time interval for periodically scanning the system is 1 second. Specifically, if a blockage is encountered, the coroutine will automatically pause and give up the control of the CPU to the scheduler, push the current coroutine context into the stack, and rejoin the end of the queue. When the simulator instruction reading and sending are completed and the sleep stops, the coroutine will be marked as ready, added to the first place in the queue by the scheduler, and the resource will be immediately seized. The context of the coroutine is obtained from the stack and resumed. By regularly scanning the system status, the effective management and scheduling of simulator resources are ensured, and the flexibility and response speed of the system are improved. Furthermore, through the cyclic execution of the above steps, in a time segment, the coroutine will be continuously paused and resumed, avoiding the waiting time for blocking, so that the program can be executed concurrently, and the utilization rate of the CPU single core is fully improved. When the number of simulators increases and reaches a certain number, the resource competition between coroutines will intensify, and the simulator may have a longer wait time for reading and sending instructions. In order to minimize the delay problem caused by too many coroutines, this solution also uses multi-threading technology for supplementation. By creating two threads globally, each thread has its own coroutine scheduler, which is responsible for reading and sending the simulator respectively, which can effectively reduce the delay problem and improve the execution efficiency of the simulator.
[0021] Furthermore, the coroutine encapsulation module adopts a non-blocking IO model when the simulator performs operations such as reading the server communication port, writing back instructions to the server communication port, sending heartbeat packets, sending voltage and status, so as to avoid waiting time caused by blocking operations. Through the non-blocking IO model, when the simulator performs operations such as reading, writing, and sending heartbeat packets at a fixed time, if it encounters a blockage, the coroutine will automatically pause to avoid waiting time. The use of the non-blocking IO model improves CPU utilization and reduces waiting time, thereby improving the overall performance of the simulator. Furthermore, the simulator creation and destruction management module also includes an off-grid reconnection mechanism. When the simulator loses connection with the charging platform communication terminal, it automatically attempts to reconnect; the simulator creation and destruction management module also includes a simulator resource destruction mechanism. When the simulator fails to reconnect after being off-grid, it can destroy simulator resources and release system resources. When the simulator is offline, it automatically tries to reconnect with the charging platform agent. The automatic reconnection mechanism improves the stability and availability of the simulator and reduces connection interruptions caused by network fluctuations. When the simulator fails to reconnect multiple times, the simulator resources are removed from the queue and the related threads and resources are destroyed. The resource destruction mechanism avoids the occupation of useless resources and improves the resource utilization and stability of the system. Furthermore, the simulator creation and destruction management module also includes the simulator's state management, which can monitor the simulator's state changes. State management improves the simulator's flexibility and response speed, and enhances the system's stability and reliability.
[0022] Furthermore, the preemptive scheduling algorithm module also includes two additional threads, each of which has its own scheduler, which is responsible for the reading and sending operations of the simulator, respectively, to reduce the delay problem and improve the execution efficiency of the simulator. The simulator provided by the present invention creates two threads, each of which contains a coroutine scheduler, which handles the reading and sending tasks of the simulator respectively, and supplements the coroutine scheduling through multi-threading technology, effectively reducing the delay problem and improving the execution efficiency of the simulator. Furthermore, the coroutine encapsulation module enables the simulator to release CPU resources to other coroutines when encountering blocking operations through the coroutine pause and resume mechanism. The coroutine pause and resume mechanism improves the utilization of CPU resources, reduces waiting time, and thus improves the concurrent processing capability of the system. The simulator provided by the present invention supports the concurrent creation and operation of large-scale simulators through non-blocking IO models and coroutine technology, optimizes resource allocation, solves the problems of low efficiency of charging pile simulators, untimely instruction transmission and reception, and excessive system resource occupation in the prior art, and realizes automatic reconnection and resource destruction after the simulator is off the network, thereby improving the stability and reliability of the simulator.
[0023] It should be noted that in the description of the present invention, if there are any orientation descriptions, such as up, down, front, back, left, right, etc., the orientations or positional relationships indicated are all based on the orientations or positional relationships shown in the drawings. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed or operated in a specific orientation, and cannot be understood as a limitation on the present invention.
[0024] In the description of the present invention, the meaning of "several" is one or more, the meaning of "more" is two or more, "greater than", "less than", "exceed" etc. are understood as not including the number itself, and "above", "below", "within" etc. are understood as including the number itself. If there is a description of the first high-concurrency charging pile simulator based on the preemptive scheduling algorithm or the second, it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.
[0025] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in the present invention based on the specific content of the technical solution.
[0026] The above-mentioned embodiments are only preferred embodiments of the present invention and cannot be used to limit the scope of protection of the present invention. Any non-substantial changes and substitutions made by technicians in this field on the basis of the present invention shall fall within the scope of protection required by the present invention.
Claims
1. A high-concurrency charging pile simulator based on a preemptive scheduling algorithm, characterized in that: include: A coroutine encapsulation module, a preemptive scheduling algorithm module and a simulator creation and destruction management module under a non-blocking IO model, wherein: the coroutine encapsulation module is used to encapsulate the charging pile simulator into a coroutine that can be suspended and resumed; the preemptive scheduling algorithm module is used to schedule the execution of the coroutine. When the coroutine encounters a blockage, it automatically pauses and saves the context. When the blockage is released, the context is reloaded and the execution is resumed; the simulator creation and destruction management module is used to manage the creation, reconnection and destruction of the simulator. When the simulator is off the network, it automatically attempts to reconnect, and destroys the simulator resources after the reconnection fails.
2. The charging simulator according to claim 1, characterized in that: The steps of the preemptive scheduling algorithm include: S1: initializing the scheduler, creating a global double-ended queue for storing all coroutines to be executed; S2: starting the scheduler, starting the scheduler in the thread, and entering an infinite loop mode; S3: the scheduler obtains the coroutine from the queue through a preemptive algorithm and executes it.
3. The charging simulator according to claim 2, characterized in that: In step S2, the current system is scanned periodically, and when it is detected that a user has created a simulator, the simulator is added to a queue; When a simulator that needs to be destroyed is detected, the simulator is removed from the queue and marked as destroyed.
4. The charging simulator according to claim 2, characterized in that: In step S3, if a blockage occurs, the coroutine will automatically pause and give up CPU control to the scheduler, push the current coroutine into the stack, and rejoin the end of the queue; when the simulator instruction reading and sending are completed and the sleep state stops, the coroutine will be marked as ready and added to the first place in the queue by the scheduler.
5. The charging pile simulator according to claim 1, characterized in that: The coroutine encapsulation module adopts a non-blocking IO model when the simulator executes operations such as reading the server communication port, writing back instructions to the server communication port, sending heartbeat packets, sending voltage and status, so as to avoid waiting time caused by blocking operations.
6. The charging pile simulator according to claim 1, characterized in that: The simulator creation and destruction management module also includes an off-grid reconnection mechanism, which automatically attempts to reconnect when the simulator loses connection with the charging platform communication terminal.
7. The charging pile simulator according to claim 1, characterized in that: The simulator creation and destruction management module also includes a simulator resource destruction mechanism, which can destroy simulator resources and release system resources when the simulator fails to reconnect after being disconnected from the network.
8. The charging pile simulator according to claim 1, characterized in that: The preemptive scheduling algorithm module also includes two additional threads, each of which has its own scheduler, which is responsible for the reading and sending operations of the simulator respectively, so as to reduce the delay problem and improve the execution efficiency of the simulator.
9. The charging pile simulator according to claim 1, characterized in that: The coroutine encapsulation module uses the coroutine pause and resume mechanism to enable the simulator to release CPU resources for other coroutines when encountering blocking operations.
10. The charging pile simulator according to claim 1, characterized in that: The simulator creation and destruction management module also includes simulator state management, which can monitor the simulator state changes.
Citation Information
Patent Citations
Blocked task scheduling method and device
CN104142858A
Time-aware shaper enhancement method for solving emergency flow in time-sensitive network
CN116032855A
Coroutine scheduling method and device and storage medium
CN117850995A
Partial and start-over threads in embedded real-time kernel
US20040139306A1
Resource management in a multicore architecture
US20050223382A1