A high-concurrency charging pile simulator based on a preemptive scheduling algorithm

Through the non-blocking IO model and preemptive scheduling algorithm, the problem of low efficiency of charging pile simulators in high concurrency situations and inability to reconnect after the simulator is off-grid, achieving high concurrent execution and stability improvement.

CN119335896BActive Publication Date: 2025-07-04ZHUHAI LCOLA TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411338900.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-25
Publication Date
2025-07-04
Estimated Expiration
2044-09-25

AI Technical Summary

Technical Problem

The existing charging pile simulators are inefficient when the number of simulators increases, the inter-thread switching overhead is large, the resource occupancy is high, and the simulator cannot be automatically reconnected after being off-grid, which affects stability and resource utilization.

Method used

The non-blocking IO model and preemptive scheduling algorithm are adopted to encapsulate the simulator through coroutines to achieve high concurrency, and the simulator offline reconnection and resource destruction mechanism are introduced to ensure that the simulator automatically reconnects and releases resources when off-grid.

Benefits of technology

It improves the stability and resource utilization of the simulator, reduces the waiting time, and ensures the reliability and efficient operation of the simulator when the network fluctuates.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119335896B_ABST
    Figure CN119335896B_ABST
Patent Text Reader

Abstract

The present invention discloses a high-concurrency charging pile simulator based on a preemptive scheduling algorithm, which includes: a coroutine encapsulation module under a non-blocking IO model, a preemptive scheduling algorithm module, and a simulator creation and destruction management module. Among them: 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. When the coroutine encounters a block, it automatically pauses and saves the context. When the block is lifted, 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 goes off the network, it automatically attempts to reconnect, and destroys the simulator resources after the reconnection fails. The present invention uses a non-blocking IO model and realizes high concurrency through coroutines and a preemptive scheduling algorithm, avoiding the waiting time caused by blocking operations.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of charging pile simulators, and particularly relates to a high-concurrency charging pile simulator based on a preemptive scheduling algorithm. Background Art

[0002] With the popularization and development of electric vehicles, the demand for charging piles has increased sharply, and the testing and verification of charging piles have 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-thread technology to batch-create simulators, and these simulators interact with the charging platform to simulate the working process of real charging piles. However, this technology has certain limitations and deficiencies. First, due to the limitations of multi-thread technology itself, three threads need to be generated for each created simulator: the simulator instance thread, the instruction reading thread, and the instruction sending thread. When the number of simulators reaches a certain scale, the switching overhead between threads becomes very large, resulting in untimely instruction sending and receiving, and the overall efficiency of the system is greatly reduced. Moreover, the existence of a large number of threads also significantly consumes CPU resources. Second, the existing technology lacks effective reconnection mechanisms and thread destruction mechanisms in the case of the simulator being 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 the resources that are no longer in use. This not only affects the availability and stability of the simulator, but also causes unnecessary system resource occupation. These problems limit the application scope and expansion ability of the existing charging pile simulator technology. Therefore, a new technical solution is needed to overcome these defects to improve the concurrent processing ability and stability of the simulator. Summary of the Invention

[0003] In order to overcome the deficiencies 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 problems of low efficiency and excessive system resource occupation caused by creating too many simulators at the same time, and to solve the problem that the simulator cannot automatically reconnect after going off-grid.

[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. When the coroutine encounters a block, it automatically pauses and saves the context. When the block 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 goes off-grid, it automatically attempts to reconnect, 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 and realizes high concurrency through coroutines and a preemptive scheduling algorithm, avoiding the waiting time caused by blocking operations, enabling concurrent execution of processes, and encapsulating the simulator through coroutine technology, enabling each simulator to be paused and resumed, reducing the overhead of system resources. At the same time, a simulator reconnection mechanism and simulator scheduling management are introduced to ensure that the simulator can automatically reconnect when off the network, and corresponding resources can be destroyed after reconnection fails, improving the stability and reliability of the simulator.

[0006] For the above-mentioned charging device simulator, 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 a thread, and enter an infinite loop mode; S3: The scheduler obtains coroutines from the queue through the preemptive algorithm and executes them.

[0007] For the above-mentioned charging device simulator, in step S2, regularly scan the current system. When it is detected that a user creates a simulator, add the simulator to the queue; when it is detected that a simulator needs to be destroyed, remove the simulator from the queue and mark it as the destroyed state.

[0008] For the above-mentioned charging device simulator, in step S3, when encountering a block, the coroutine will automatically pause and yield the CPU control right to the scheduler, push the current coroutine onto 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 the ready state and added to the head of the queue by the scheduler.

[0009] For the above-mentioned charging device simulator, 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, etc., to avoid the waiting time caused by blocking operations.

[0010] For the above-mentioned charging device simulator, the simulator creation and destruction management module further includes an off-network reconnection mechanism, which automatically attempts to reconnect when the simulator loses connection with the charging platform communication end.

[0011] For the above-mentioned charging device simulator, the simulator creation and destruction management module further includes a simulator resource destruction mechanism, which can destroy simulator resources and release system resources when the reconnection fails after the simulator goes off the network.

[0012] For the above-mentioned charging device simulator, the preemptive scheduling algorithm module further includes two additional threads, and there is a respective scheduler in each thread, which are respectively responsible for the reading and sending operations of the simulator to reduce latency problems and improve the execution efficiency of the simulator.

[0013] The above-mentioned charging pile simulator. Through the pause and resume mechanism of the coroutine, the simulator can release CPU resources for other coroutines to use when encountering blocking operations.

[0014] The above-mentioned charging pile simulator. The simulator creation and destruction management module also includes the state management of the simulator, which can monitor the state changes of the simulator. Description of the Drawings

[0015] Figure 1 It is the flowchart of the technical solution of the embodiment of the present invention;

[0016] Figure 2 It is the flowchart of the scheduler scheduling of the embodiment of the present invention;

[0017] Figure 3 It is the step schematic diagram of the preemptive scheduling algorithm of the embodiment of the present invention; Detailed Embodiment

[0018] The embodiments of the present invention will be described in detail below. Referring to Figures 1 to 3 The embodiments of the present invention provide 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. Among them: 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. When the coroutine encounters a block, it automatically pauses and saves the context. When the block is lifted, it reloads the context and resumes execution; the simulator creation and destruction management module is used to manage the creation, reconnection, and destruction of the simulator. When the simulator goes off the network, it automatically attempts to reconnect. After the reconnection fails, it destroys the simulator resources. The present invention uses a non-blocking IO model and realizes high concurrency through coroutines and a preemptive scheduling algorithm, avoiding the waiting time caused by blocking operations, enabling the program to execute concurrently, and encapsulating the simulator through coroutine technology, so that each simulator can be paused and resumed, reducing the overhead of system resources. At the same time, a simulator disconnection and reconnection mechanism and simulator scheduling management are introduced to ensure that the simulator can automatically reconnect when it goes off the network and destroy the corresponding resources after the reconnection fails. The stability and reliability of the simulator are improved.

[0019] Further, referring to Figure 1 The flowchart of the technical solution of the present invention is as shown in 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, the polling is performed for the sending and receiving of instructions. When the instruction sending fails, the simulator will automatically attempt to reconnect. After the reconnection is successful, the polling will continue to execute. After the reconnection fails, it will be marked as the off-grid state and the simulator resources will be destroyed. Further, there are multiple blocking operations during the operation of the simulator of the present invention, 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 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, causing the CPU to wait until the blocking operation is completed before it can continue to execute downward. To avoid the program from being blocked, the non-blocking IO model is used. Further, referring to Figure 2 , the simulator is encapsulated by means of coroutines. Here, the coroutine represents the subroutine of a single simulator, and this subroutine can be paused and resumed. Further, the preemptive scheduling algorithm module starts the scheduler in the thread. The flowchart of the scheduling is as shown in the figure. There are three simulators in the program, namely Simulator 1, Simulator 2, and Simulator 3. When the program starts running, first, the execution code 1 of Simulator 1 will be executed. When it comes to the moment of Socket reading and sending instructions, the operating system will be blocked due to network requests and IO read and write operations, and the scheduler will automatically switch to Simulator 2 in the next queue to continue execution; when Simulator 2 comes to the moment of Socket reading and sending instructions, the operating system will be blocked due to network requests and IO read and write operations, and the scheduler will automatically switch to Simulator 3 in the next queue to continue execution; when Simulator 3 comes to the moment of Socket reading and sending instructions, the operating system will be blocked due to network requests and IO read and write operations, and the scheduler will automatically switch to the first Simulator 1 to obtain the results of IO read and write and the results of instruction sending and receiving, and execute code 2; switch to the second Simulator 2, obtain the results of IO read and write and the results of instruction sending and receiving, and execute code 2; switch to the third Simulator 3, obtain the results of IO read and write and the results of instruction sending and receiving, and execute code 2. The above operations are repeated to achieve the effect of concurrency.

[0020] Further, referring 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 a thread and enter an infinite loop mode; S3: The scheduler obtains coroutines from the queue through the preemptive algorithm and executes them. Specifically, in step S1, when initializing the scheduler, mark the current state of each coroutine at the same time; in step S2, regularly scan the current system. When it detects that the user creates a simulator, add the simulator to the queue; when it detects a simulator that needs to be destroyed, remove the simulator from the queue and mark it as the destroyed state; in step S3, when encountering a block, the coroutine will automatically pause and yield the CPU control right to the scheduler, push the current coroutine onto 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 the ready state and be added to the head of the queue by the scheduler. Preferably, the time interval for regularly scanning the system is 1 second. Specifically, when encountering a block, the coroutine will automatically pause and yield the CPU control right to the scheduler, push the current coroutine context onto 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 the ready state and be added to the head of the queue by the scheduler, immediately preempt the resource, obtain the coroutine context from the stack and resume execution. By regularly scanning the system status, it ensures the effective management and scheduling of simulator resources, improves the flexibility and response speed of the system. Further, through the loop execution of the above steps, in a time slice, the coroutine will be continuously paused and resumed, avoiding the waiting time for blocking, enabling the program to execute concurrently, and fully improving the utilization rate of the single-core CPU. When the number of simulators increases and reaches a certain number, it will lead to increased resource competition among coroutines, and there may be a longer wait for the simulator to read and send instructions. To minimize the latency problem caused by too many coroutines as much as possible, this solution also adopts multithreading technology for supplementation. By globally creating two threads, each thread has its own coroutine scheduler, which is responsible for the reading and sending of simulators respectively, and can effectively reduce the latency 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, etc., to avoid the waiting time caused by blocking operations. Through the non-blocking IO model, when the simulator performs operations such as reading, writing, and periodically sending heartbeat packets, if a blockage occurs, the coroutine will automatically pause, avoiding waiting time. The use of the non-blocking IO model improves the utilization rate of the CPU, reduces the waiting time, and thus improves the overall performance of the simulator. Even further, 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 end; 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 reconnection fails after the simulator goes off-grid. When the simulator goes off-grid, it automatically attempts to re-establish a connection with the charging platform proxy end. 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 after multiple attempts, the simulator resources are removed from the queue, and the relevant threads and resources are destroyed. The resource destruction mechanism avoids the occupation of useless resources and improves the resource utilization rate and stability of the system. Even further, the simulator creation and destruction management module also includes the status management of the simulator, which can monitor the status changes of the simulator. The status management improves the flexibility and response speed of the simulator and enhances the stability and reliability of the system.

[0022] Even further, the preemptive scheduling algorithm module also includes two additional threads, and there is a respective scheduler in each thread, which are responsible for the reading and sending operations of the simulator respectively, to reduce latency issues and improve the execution efficiency of the simulator. The simulator provided by the present invention, by creating two threads, each thread containing a coroutine scheduler, respectively processing the reading and sending tasks of the simulator, supplements the coroutine scheduling through multi-threading technology, effectively reduces latency issues, and improves the execution efficiency of the simulator. Furthermore, the coroutine encapsulation module, through the pause and resume mechanism of the coroutine, enables the simulator to release CPU resources for other coroutines to use when encountering blocking operations. The pause and resume mechanism of the coroutine improves the utilization rate of CPU resources, reduces waiting time, and thus improves the concurrent processing ability of the system. The simulator provided by the present invention, through the non-blocking IO model and coroutine technology, supports the concurrent creation and operation of a large number of simulators, optimizes resource allocation, solves the problems of low efficiency of the existing charging pile simulator, untimely instruction sending and receiving, and excessive occupation of system resources, and at the same time realizes the automatic reconnection and resource destruction after the simulator goes off-grid, improving the stability and reliability of the simulator.

[0023] It should be noted that in the description of the present invention, when it comes to the description of directions, such as the directions or positional relationships indicated by up, down, front, back, left, right, etc., they are all based on the directions or positional relationships shown in the drawings. This is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed or operated in a specific direction, and should not be construed as a limitation to the present invention.

[0024] In the description of the present invention, the meaning of "several" is one or more, the meaning of "multiple" is two or more, "greater than", "less than", "exceeding", etc. are understood as not including the present number, and "above", "below", "within", etc. are understood as including the present number. If there is a description of the first high-concurrency charging pile simulator based on the preemptive scheduling algorithm or the second, etc., it is only for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance or implicitly indicating the quantity of the indicated technical features or the sequence relationship of the indicated technical features.

[0025] In the description of the present invention, unless otherwise clearly defined, words such as "set", "installed", "connected", etc. should be understood in a broad sense, and those skilled in the art can reasonably determine the specific meanings of the above words in the present invention in combination with the specific content of the technical solution.

[0026] The above embodiments are only the 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 those skilled in the art based on the present invention belong to 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 Including: A coroutine encapsulation module, a preemptive scheduling algorithm module, and a simulator creation and destruction management module under the non-blocking IO model, where: 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. When the coroutine encounters a block, it automatically pauses and saves the context. When the block is lifted, 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 goes offline, it automatically attempts to reconnect. After the reconnection fails, the simulator resources are destroyed; 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 a thread, and enter an infinite loop mode; S3: The scheduler obtains the coroutine from the queue through the preemptive algorithm and executes it; in step S2, regularly scan the current system. When it detects that the user creates a simulator, add the simulator to the queue; when it detects a simulator that needs to be destroyed, remove the simulator from the queue and mark it as the destroyed state.

2. The charging pile simulator according to claim 1, characterized in that In step S3, when encountering a block, the coroutine will automatically pause and yield the CPU control right to the scheduler, push the current coroutine onto 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 the ready state and added to the head of the queue by the scheduler.

3. The charging pile simulator according to claim 1, wherein: The coroutine encapsulation module adopts the 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 heartbeats, sending voltage and status, etc., to avoid the waiting time caused by blocking operations.

4. The charging pile simulator according to claim 1, wherein: The simulator creation and destruction management module also includes an offline reconnection mechanism. When the simulator loses connection with the charging platform communication end, it automatically attempts to reconnect.

5. The charging pile simulator according to claim 1, wherein: The simulator creation and destruction management module also includes a simulator resource destruction mechanism. When the reconnection fails after the simulator goes offline, it can destroy the simulator resources and release the system resources.

6. The charging pile simulator according to claim 1, characterized in that: The preemptive scheduling algorithm module also includes two additional threads. Each thread has its own scheduler, which is responsible for the reading and sending operations of the simulator respectively, to reduce the latency problem and improve the execution efficiency of the simulator.

7. The charging pile simulator according to claim 1, wherein: The coroutine encapsulation module enables the simulator to release the CPU resources for other coroutines to use when encountering blocking operations through the pause and resume mechanism of the coroutine.

8. The charging pile simulator according to claim 1, characterized in that: The simulator creation and destruction management module also includes the status management of the simulator, which can monitor the status changes of the simulator.

Citation Information

Patent Citations

  • Coroutine scheduling method and device and storage medium

    CN117850995A