[go: up one dir, main page]

CN114564291B - Method and device for executing timed snapshot task - Google Patents

Method and device for executing timed snapshot task Download PDF

Info

Publication number
CN114564291B
CN114564291B CN202210167289.0A CN202210167289A CN114564291B CN 114564291 B CN114564291 B CN 114564291B CN 202210167289 A CN202210167289 A CN 202210167289A CN 114564291 B CN114564291 B CN 114564291B
Authority
CN
China
Prior art keywords
task
queue
snapshot
timing
threads
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202210167289.0A
Other languages
Chinese (zh)
Other versions
CN114564291A (en
Inventor
王祥
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Suzhou Metabrain Intelligent Technology Co Ltd
Original Assignee
Suzhou Inspur Intelligent Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Suzhou Inspur Intelligent Technology Co Ltd filed Critical Suzhou Inspur Intelligent Technology Co Ltd
Priority to CN202210167289.0A priority Critical patent/CN114564291B/en
Publication of CN114564291A publication Critical patent/CN114564291A/en
Application granted granted Critical
Publication of CN114564291B publication Critical patent/CN114564291B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

本发明公开了一种定时快照任务的执行方法及装置,该方法包括:设置定时快照任务的定时周期,对每一个所述定时快照任务分配一个自增的ID号;检测所有的所述定时快照任务,选出命中定时周期的定时快照任务放入创建的队列中;从多个线程中选择空闲的线程检查所述队列中是否存在任务,并从队列中存在任务的对应位置处取出任务的ID号,根据ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合预设规则的空闲线程来执行。本申请通过设置这种多任务定时快照的单队方式,每个执行线程通过任务的ID和自身线程号取余比较来判断是否取出该任务进行执行,能够将同一任务不同时刻执行串行化防止同时执行,降低了队列维护的难度。

The present invention discloses a method and device for executing a timed snapshot task, the method comprising: setting a timing period of a timed snapshot task, assigning a self-incrementing ID number to each of the timed snapshot tasks; detecting all of the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into a created queue; selecting an idle thread from multiple threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and selecting the same task to be executed by only one idle thread that meets the preset rules at a certain moment according to the relationship between the ID number and the number of threads. The present application sets a single-queue mode for multi-task timed snapshots, and each execution thread determines whether to take out the task for execution by comparing the task ID with its own thread number by taking the remainder, which can serialize the execution of the same task at different times to prevent simultaneous execution, thereby reducing the difficulty of queue maintenance.

Description

一种定时快照任务的执行方法及装置A method and device for executing a timed snapshot task

技术领域Technical Field

本发明涉及网络数据存储技术领域,尤其涉及一种定时快照任务的执行方法及系统。The present invention relates to the technical field of network data storage, and in particular to a method and system for executing a timed snapshot task.

背景技术Background Art

数据中心、实验室或者各类规模的局域网,使用存储设备时通常是多个服务器或者主机同时使用。作为容灾的重要措施定时快照是不可缺少的环节,但是不同服务器和主机上部署不同的应用,对于定时的周期要求有所不同,目前通常的做法是采用如下两种方案。In data centers, laboratories, or local area networks of all sizes, storage devices are usually used by multiple servers or hosts at the same time. As an important disaster recovery measure, scheduled snapshots are an indispensable part, but different applications deployed on different servers and hosts have different requirements for scheduled cycles. Currently, the common practice is to use the following two solutions.

方案一、搭建一个专门的定时服务器编辑定时快照任务,在执行定时快照任务时,会将任务依次进入队列或者其他类型的数据结构,然后使用多线程或者多进程依次从队列中获取任务执行,这种方案会导致一个问题,就是如果同一个服务器的定时周期小于快照产生的时间,那么会产生同一时间进行了两次快照。Solution 1: Build a dedicated timing server to edit the timing snapshot task. When executing the timing snapshot task, the tasks will be entered into a queue or other types of data structures in sequence, and then multi-threading or multi-process will be used to obtain the tasks from the queue in sequence for execution. This solution will lead to a problem, that is, if the timing period of the same server is less than the time when the snapshot is generated, then two snapshots will be generated at the same time.

方案二、针对不同的服务器或者主机建立不同的队列,这种方案可以规避方案一同时两次快照的问题,但是要维护多个队列需要更多额外的工作,而且可能会导致内存溢出。Solution 2: Create different queues for different servers or hosts. This solution can avoid the problem of two snapshots at the same time in Solution 1, but maintaining multiple queues requires more extra work and may cause memory overflow.

因此,如何设计出一种针对定时快照任务,不会产生同时快照的问题并且不需要维护额外的队列,是目前需要解决的技术问题。Therefore, how to design a timed snapshot task that does not cause the problem of simultaneous snapshots and does not require the maintenance of additional queues is a technical problem that needs to be solved at present.

发明内容Summary of the invention

为了解决上述问题,本发明提供一种定时快照任务的执行方法及装置,具体地,本发明实施例提供了以下技术方案:In order to solve the above problems, the present invention provides a method and device for executing a timed snapshot task. Specifically, the embodiments of the present invention provide the following technical solutions:

第一方面,本发明实施例提供了一种定时快照任务的执行方法,包括:In a first aspect, an embodiment of the present invention provides a method for executing a timed snapshot task, including:

设置定时快照任务的定时周期,对每一个所述定时快照任务分配一个自增的ID号;Set the timing period of the scheduled snapshot task, and assign a self-increasing ID number to each of the scheduled snapshot tasks;

检测所有的所述定时快照任务,选出命中所述定时周期的定时快照任务放入创建的队列中;Detect all the scheduled snapshot tasks, select the scheduled snapshot tasks that hit the scheduled period and put them into the created queue;

从多个线程中选择空闲的线程检查所述队列中是否存在任务,并从所述队列中存在任务的对应位置处取出所述任务的ID号,根据所述ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合预设规则的所述空闲的线程来执行。An idle thread is selected from multiple threads to check whether there is a task in the queue, and the ID number of the task is taken out from the corresponding position of the task in the queue. According to the relationship between the ID number and the number of threads, the same task is selected to be executed by only one idle thread that meets the preset rules at a certain moment.

进一步地,根据所述ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合规则的所述空闲的线程来执行包括:Further, according to the relationship between the ID number and the number of threads, selecting at a certain moment that the same task is executed by only one idle thread that complies with the rule includes:

计算出所述ID号与线程数量相除后的取余值,若所述取余值等于所述空闲的线程的线程号,则将所述任务移除队列并由所述空闲的线程执行,若所述取余值不等于所述空闲的线程的线程号,则将所述任务放回原对应的位置处,并移动一个位置继续检查和计算。Calculate the remainder value after dividing the ID number by the number of threads. If the remainder value is equal to the thread number of the idle thread, remove the task from the queue and execute it by the idle thread. If the remainder value is not equal to the thread number of the idle thread, put the task back to the original corresponding position and move one position to continue checking and calculating.

进一步地,所述的队列为单队列,控制所述空闲的线程先从队列中的头部任务开始检测。Furthermore, the queue is a single queue, and the idle thread is controlled to start detecting from the head task in the queue first.

进一步地,检测所有的所述定时快照任务,选出命中所述定时周期的定时快照任务放入创建的队列包括:Further, detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into the created queue includes:

对到达定时周期时,所有需要执行的快照任务依序放入队列中,并对队列的位置进行标记,每存放一个任务,队列中的位置后移且标记值加1。When the timing cycle is reached, all snapshot tasks that need to be executed are placed in the queue in order, and the position of the queue is marked. Each time a task is stored, the position in the queue moves backward and the mark value increases by 1.

进一步地,当存在多个空余的线程时,多个空余的线程轮流检查和计算所述ID号与线程数量相除后的取余值。Further, when there are multiple free threads, the multiple free threads take turns to check and calculate the remainder value after dividing the ID number by the number of threads.

进一步地,所述的定时周期为间隔的时间段或固定的时间点。Furthermore, the timing period is an interval time period or a fixed time point.

进一步地,每间隔时间段检测所有的所述定时快照任务,所述的时间段为一分钟。Furthermore, all the timed snapshot tasks are detected in each interval time period, and the time period is one minute.

第二方面,本发明还提供了一种定时快照任务的执行装置,包括:In a second aspect, the present invention further provides a device for executing a timed snapshot task, comprising:

任务设置模块,用于设置定时快照任务的定时周期,以及对每一个所述定时快照任务分配一个自增的ID号;A task setting module, used to set the timing period of the scheduled snapshot task and assign a self-increasing ID number to each of the scheduled snapshot tasks;

任务检测模块,用于检测所有的所述定时快照任务,选出命中所述定时周期的定时快照任务放入创建的队列中;A task detection module, used to detect all the timed snapshot tasks, select the timed snapshot tasks that hit the timing period and put them into the created queue;

任务执行模块,用于从多个线程中选择一个空闲的线程检查所述队列中是否存在任务,并从所述队列中存在任务的对应位置处取出所述任务的ID号,根据所述ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合规则的所述空闲的线程来执行。The task execution module is used to select an idle thread from multiple threads to check whether there is a task in the queue, and take out the ID number of the task from the corresponding position of the task in the queue. According to the relationship between the ID number and the number of threads, the same task is selected at a certain moment to be executed by only one idle thread that meets the rules.

第三方面,本发明还提供了一种电子设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述处理器执行所述程序时实现如第一方面所述的定时快照任务的执行方法的步骤。In a third aspect, the present invention further provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the method for executing a timed snapshot task as described in the first aspect are implemented.

第四方面,本发明还提供了一种非暂态计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如第一方面所述的定时快照任务的执行方法的步骤。In a fourth aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method for executing a timed snapshot task as described in the first aspect are implemented.

由上述技术方案可知,本发明提供的一种定时快照任务的执行方法级装置,只使用单个队列保存定时任务不同时刻的待执行状态,每个执行线程通过任务的ID和自身线程号取余比较来判断是否取出该任务进行执行。通过这种多任务定时快照单队方式,能够将同一任务不同时刻执行串行化防止同时执行,同时不同任务间并发处理保证了性能同时降低了队列维护的难度。It can be seen from the above technical solution that the execution method-level device of a timed snapshot task provided by the present invention only uses a single queue to save the pending execution status of the timed task at different times, and each execution thread determines whether to take out the task for execution by comparing the task ID with its own thread number. Through this multi-task timed snapshot single-queue method, the execution of the same task at different times can be serialized to prevent simultaneous execution, and concurrent processing between different tasks ensures performance while reducing the difficulty of queue maintenance.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

此处所说明的附图用来提供对本发明的进一步理解,构成本发明的一部分,本发明的示意性实施例及其说明用于解释本发明,并不构成对本发明的不当限定。在附图中:The drawings described herein are used to provide a further understanding of the present invention and constitute a part of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

图1为本发明一个实施例提供的定时快照任务的执行方法的流程示意图。FIG. 1 is a schematic flow chart of a method for executing a timed snapshot task according to an embodiment of the present invention.

图2为本发明一个实施例提供的单队列的任务执行示意图。FIG. 2 is a schematic diagram of task execution in a single queue provided by an embodiment of the present invention.

图3为本发明一个实施例提供的单队列的任务执行的另一示意图。FIG. 3 is another schematic diagram of task execution in a single queue provided by an embodiment of the present invention.

图4为本发明一个实施例提供的定时快照任务的执行装置的结构示意图。FIG. 4 is a schematic diagram of the structure of a device for executing a timed snapshot task provided by an embodiment of the present invention.

图5为本发明一个实施例提供的电子设备的结构示意图。FIG5 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.

具体实施方式DETAILED DESCRIPTION

为使本发明的上述目的、特征和优点能够更加明显易懂,下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述。显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动的前提下所获得的所有其它实施例,均属于本发明保护的范围。In order to make the above-mentioned purposes, features and advantages of the present invention more obvious and easy to understand, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work belong to the scope of protection of the present invention.

下面将结合附图对本发明实施例进行详细介绍。The embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

本申请提出了一种多任务定时快照单队列并发执行方案,将多个定时快照任务放入单一队列中,在线程执行任务前根据判断函数决定是否执行来保证不会产生同时快照的问题并且不需要维护额外的队列。This application proposes a multi-task timed snapshot single queue concurrent execution solution, which puts multiple timed snapshot tasks into a single queue, and decides whether to execute based on a judgment function before the thread executes the task to ensure that the problem of simultaneous snapshots will not occur and there is no need to maintain additional queues.

图1示出了本发明实施例提供的定时快照任务的执行方法的流程图。如图1所示,本发明实施例提供的定时快照任务的执行方法,包括如下步骤:FIG1 is a flowchart of a method for executing a timing snapshot task provided by an embodiment of the present invention. As shown in FIG1 , the method for executing a timing snapshot task provided by an embodiment of the present invention comprises the following steps:

步骤S1、设置定时快照任务的定时周期,对每个定时快照任务生成一个自增ID。Step S1: Set the timing period of the timing snapshot task and generate a self-incrementing ID for each timing snapshot task.

具体的,定时快照任务的定时周期可以以固定的时间段或固定的一个或多个时间点来设定,比如可以设定定时周期为每分钟、每三十分钟、每天的08:00、12:00等,对每一个任务还设置有一个ID号,ID号按照递增的数字来标记,表示唯一标识的任务,比如总共有4个任务,分别编号为1号、2号、3号、4号。Specifically, the timing period of the scheduled snapshot task can be set as a fixed time period or one or more fixed time points. For example, the timing period can be set to every minute, every thirty minutes, 08:00, 12:00 every day, etc. An ID number is also set for each task. The ID number is marked with increasing numbers to indicate a uniquely identified task. For example, there are a total of 4 tasks, numbered 1, 2, 3, and 4 respectively.

定时快照即通常所说的自动快照,是指根据已设定的定时策略自动创建的快照,支持用户自定义创建快照的数目,每个文件系统最多可以创建128个定时快照。根据系统管理员设定的定时策略,定时自动创建快照,为存储设备上的数据灵活和频繁地生成多个恢复点,从而方便快速恢复数据。当用户对业务系统数据的安全性要求较高,需要在文件损坏或丢失的情况下能够快速恢复指定时间点的数据时,可以选择创建定时快照。Timing snapshots are also known as automatic snapshots. They are snapshots that are automatically created based on a set timing policy. Users can customize the number of snapshots created, and up to 128 timing snapshots can be created for each file system. Snapshots are automatically created based on the timing policy set by the system administrator, and multiple recovery points are generated flexibly and frequently for the data on the storage device, making it easy to quickly recover data. When users have high security requirements for business system data and need to quickly recover data at a specified time point in the event of file damage or loss, they can choose to create a timing snapshot.

步骤S2、创建一个单一的队列。Step S2: Create a single queue.

具体的,该队列为一个单一的队列,即所有的待执行任务存放在一个队列中,用X表示队列下标,X表示当前队列的任务所在位置,初始值可以设为0,0表示队列的初始位置,X在队列中永远指向最后的那一个任务所在的位置。Specifically, the queue is a single queue, that is, all tasks to be executed are stored in one queue. X is used to represent the queue index, X represents the position of the task in the current queue, and the initial value can be set to 0, which represents the initial position of the queue. X always points to the position of the last task in the queue.

步骤S3、检测所有的任务,选出命中该定时周期的任务放入创设的单队列中。Step S3: Check all tasks, select the tasks that hit the timing cycle and put them into the created single queue.

具体的,每间隔一个时间段,比如一分钟、五分钟开始检测所有的任务,选出命中定时周期的任务放入队列中。假设在14:00,4个任务中,1号任务和2号任务被命中需要执行,则将1号任务和2号任务需要放入队列中。Specifically, all tasks are checked at intervals of one minute or five minutes, and tasks that hit the timing period are selected and put into the queue. Assume that at 14:00, among the four tasks, tasks 1 and 2 are hit and need to be executed, then tasks 1 and 2 need to be put into the queue.

示例性的,先把1号任务放在队列的初始位置,然后位置X加1,也即向后移动一个位置,再把2号任务放入队列中,当前的位置作为新的位置X值,每存放一个任务,队列中的位置后移且标记值加1。如果没有命中定时周期的任务,则继续以设定的间隔时间段去检测。For example, first put task 1 at the initial position of the queue, then add 1 to position X, that is, move one position backward, and then put task 2 into the queue, and use the current position as the new position X value. Each time a task is stored, the position in the queue moves backward and the tag value increases by 1. If there is no task that hits the timing cycle, continue to detect at the set interval time period.

步骤S4、生成n个线程,对每个线程从1到n依次进行编号,假如该n个线程中第m(1≤m≤n)个线程空闲可用,则通过该第m个线程检查步骤S3中是否存在向队列中放入的任务,可以通过虚拟一个位置Y,位置Y对应变动的X位置,即设Y=X检查,位置Y处是否有任务,如果有,则转入下一步骤S5,如若检测出队列中没有任务,则继续间隔时间段去检查直到队列中有任务,其中,控制空闲的线程先从队列中的头部任务开始检测。Step S4, generate n threads, and number each thread from 1 to n in sequence. If the mth thread (1≤m≤n) among the n threads is idle and available, then the mth thread is used to check whether there is a task put into the queue in step S3. A virtual position Y can be created, and position Y corresponds to the changed position X, that is, Y=X is set to check whether there is a task at position Y. If so, proceed to the next step S5. If it is detected that there is no task in the queue, continue to check at intervals until there is a task in the queue. Among them, the idle thread is controlled to start checking from the head task in the queue first.

当存在多个空余的线程时,多个空余的线程轮流检查和计算所述ID号与线程数量相除后的取余值。也就是说,假如存在两个空余的线程1号和2号,则1号线程检测计算,若不由1号来执行,则进行2号线程进行检测计算,如若也不由2号线程来执行,则再移动至队列的其它位置。When there are multiple free threads, the multiple free threads take turns to check and calculate the remainder value after dividing the ID number by the number of threads. That is, if there are two free threads No. 1 and No. 2, thread No. 1 will check and calculate. If it is not executed by No. 1, thread No. 2 will check and calculate. If it is not executed by No. 2 either, it will move to other positions in the queue.

步骤S5、当存在任务时,第m个线程从Y位置对应的队列X位置处取出任务的ID,比较ID号与线程总数n之间的关系,选择在某时刻同一任务仅由一个符合预设规则的某空闲的线程来执行,以确保同一队列中的同一任务在不同时刻不会被重复执行。Step S5, when there is a task, the mth thread takes out the ID of the task from the X position of the queue corresponding to the Y position, compares the relationship between the ID number and the total number of threads n, and selects only one idle thread that meets the preset rules to execute the same task at a certain time, so as to ensure that the same task in the same queue will not be executed repeatedly at different times.

具体的,计算ID号与n相除后的结果取余值,也即计算k=MOD(ID/n),如果k=m,则代表该任务可以由该第m个线程执行,将任务移除队列并由m线程执行,之后再转入步骤S4看是否有其它空闲线程可供执行的任务。如果k≠m,则代表该任务不能由第m个线程执行,将任务放回Y处,并Y=Y-1,也即将原X位置左移一处,如果y<0,表示队列已经检查完毕,未发现需要执行的任务,则该第m个空闲的线程重复本步骤继续检查是否有新的任务。每在定时周期命中任务后,则由S5~S6步分配任务给空闲线程执行。Specifically, calculate the remainder of the result after dividing the ID number by n, that is, calculate k=MOD(ID/n). If k=m, it means that the task can be executed by the mth thread. Remove the task from the queue and execute it by the mth thread, and then go to step S4 to see if there are other idle threads available to execute the task. If k≠m, it means that the task cannot be executed by the mth thread. Put the task back to Y, and Y=Y-1, that is, move the original X position to the left. If y<0, it means that the queue has been checked and no tasks to be executed are found. Then the mth idle thread repeats this step to continue checking whether there are new tasks. After each task is hit in the timing cycle, the task is assigned to the idle thread for execution by steps S5~S6.

如图2所示,假设存在两个任务,即任务1和任务2被命中,放在一个单队列中,先把1号任务放在队列的初始位置,然后向右移动一处,再将2号任务放入队列中,此时X位置指向2号任务处,假如存在两个线程,即1号线程饿0号线程,1号线程正在忙,0号线程空闲,可以去执行任务,0号线程从X位置取出2号任务,由于线程总数是2,2对2取余,余数为0,正好等于线程的编号,那么线程0将队列取出并去执行2号任务,之后X位置左移,也即到1号任务的位置处,如图3所示。假设将单队列中的1号任务和2号任务的位置更换一下,2号任务在在左,1号任务在对应的最新X处,同样地,如果0号线程空闲,1对2取余,余数为1,不等于线程的编号0,则依次向左检查2号任务,2对2取余,余数为0,取出2号任务执行,由于最左边的2号任务被取出执行了,1号任务成为靠前的一个。As shown in Figure 2, suppose there are two tasks, namely, task 1 and task 2 are hit and placed in a single queue. Task 1 is first placed at the initial position of the queue, then moved to the right, and task 2 is placed in the queue. At this time, the X position points to task 2. If there are two threads, namely thread 1 and thread 0, thread 1 is busy and thread 0 is idle and can execute tasks. Thread 0 takes task 2 from position X. Since the total number of threads is 2, the remainder of 2 is 0, which is exactly equal to the thread number. Then thread 0 takes out the queue and executes task 2. Then the X position moves left, that is, to the position of task 1, as shown in Figure 3. Suppose that the positions of task 1 and task 2 in the single queue are swapped, task 2 is on the left, and task 1 is at the corresponding latest X. Similarly, if thread 0 is idle, 1 is taken modulo 2, and the remainder is 1, which is not equal to thread number 0, then task 2 is checked to the left in sequence, 2 is taken modulo 2, and the remainder is 0, so task 2 is taken out for execution. Since the leftmost task 2 is taken out for execution, task 1 becomes the front one.

本申请通过设置这种多任务定时快照单队方式,每个执行线程通过任务的ID和自身线程号取余比较来判断是否取出该任务进行执行,能够将同一任务不同时刻执行串行化防止同时执行,同时不同任务间并发处理保证了性能同时降低了队列维护的难度。This application sets up this multi-task timed snapshot single queue mode. Each execution thread determines whether to take out the task for execution by comparing the task ID with its own thread number. This can serialize the execution of the same task at different times to prevent simultaneous execution. At the same time, concurrent processing between different tasks ensures performance while reducing the difficulty of queue maintenance.

与上述实施例相对应的,本发明的另一实施例还提供了一种定时快照任务的执行装置,其中,在本实施例中,与上述实施例相同或相应的内容,请参考上文介绍,后续不再赘述。Corresponding to the above embodiment, another embodiment of the present invention further provides an execution device for a timed snapshot task. In this embodiment, for the contents that are the same or corresponding to the above embodiment, please refer to the above introduction and will not be repeated later.

如图4所示,本发明实施例公开的一种定时快照任务的执行装置,包括:As shown in FIG4 , an execution device for a timed snapshot task disclosed in an embodiment of the present invention includes:

任务设置模块301,用于设置定时快照任务的定时周期,以及对每一个所述定时快照任务分配一个自增的ID号;The task setting module 301 is used to set the timing period of the timing snapshot task and assign a self-increasing ID number to each of the timing snapshot tasks;

任务检测模块302,用于检测所有的所述定时快照任务,选出命中所述定时周期的定时快照任务放入创建的队列中;The task detection module 302 is used to detect all the timed snapshot tasks, select the timed snapshot tasks that hit the timing period and put them into the created queue;

任务执行模块303,用于从多个线程中选择一个空闲的线程检查所述队列中是否存在任务,并从所述队列中存在任务的对应位置处取出所述任务的ID号,根据所述ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合预设规则的所述空闲的线程来执行,保证同一任务的不同时刻不会同时进行。。The task execution module 303 is used to select an idle thread from multiple threads to check whether there is a task in the queue, and take out the ID number of the task from the corresponding position of the task in the queue, and select only one idle thread that meets the preset rules to execute the same task at a certain time according to the relationship between the ID number and the number of threads, so as to ensure that the same task will not be executed at different times at the same time.

由于本发明实施例提供的定时快照任务的执行装置,可以用于执行上述实施例所述的定时快照任务的执行方法,其工作原理和有益效果类似,故此处不再详述,具体内容可参见上述实施例的介绍。Since the execution device of the timing snapshot task provided in the embodiment of the present invention can be used to execute the execution method of the timing snapshot task described in the above embodiment, its working principle and beneficial effects are similar, so they are not described in detail here. For specific contents, please refer to the introduction of the above embodiment.

基于相同的发明构思,本发明又一实施例提供了一种电子设备,参见图5,所述电子设备具体包括如下内容:处理器、存储器、通信接口和通信总线;其中,所述处理器、存储器、通信接口通过所述通信总线完成相互间的通信;所述处理器用于调用所述存储器中的计算机程序,所述处理器执行所述计算机程序时实现上述方法的全部步骤,例如,所述处理器执行所述计算机程序时实现下述过程:设置定时快照任务的定时周期,对每一个所述定时快照任务分配一个自增的ID号;检测所有的所述定时快照任务,选出命中所述定时周期的定时快照任务放入创建的队列中;从多个线程中选择一个空闲的线程检查所述队列中是否存在任务,并从所述队列中存在任务的对应位置处取出所述任务的ID号,根据所述ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合预设规则的所述空闲的线程来执行。Based on the same inventive concept, another embodiment of the present invention provides an electronic device, see Figure 5, the electronic device specifically includes the following contents: a processor, a memory, a communication interface and a communication bus; wherein the processor, the memory, and the communication interface communicate with each other through the communication bus; the processor is used to call the computer program in the memory, and the processor implements all the steps of the above method when executing the computer program. For example, when the processor executes the computer program, it implements the following process: setting the timing period of the timed snapshot task, and assigning a self-incrementing ID number to each of the timed snapshot tasks; detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into the created queue; selecting an idle thread from multiple threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and according to the relationship between the ID number and the number of threads, selecting the same task to be executed by only one of the idle threads that meets the preset rules at a certain moment.

可以理解的是,所述计算机程序可以执行的细化功能和扩展功能可参照上面实施例的描述。It can be understood that the detailed functions and extended functions that can be executed by the computer program can refer to the description of the above embodiments.

基于相同的发明构思,本发明又一实施例提供了一种非暂态计算机可读存储介质,该非暂态计算机可读存储介质上存储有计算机程序,该计算机程序被处理器执行时实现上述方法的全部步骤,例如,所述处理器执行所述计算机程序时实现下述过程:设置定时快照任务的定时周期,对每一个所述定时快照任务分配一个自增的ID号;检测所有的所述定时快照任务,选出命中所述定时周期的定时快照任务放入创建的队列中;从多个线程中选择一个空闲的线程检查所述队列中是否存在任务,并从所述队列中存在任务的对应位置处取出所述任务的ID号,根据所述ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合预设规则的所述空闲的线程来执行。Based on the same inventive concept, another embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, all the steps of the above method are implemented. For example, when the processor executes the computer program, the following process is implemented: setting a timing period of a timed snapshot task, and assigning a self-incrementing ID number to each of the timed snapshot tasks; detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into the created queue; selecting an idle thread from multiple threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and according to the relationship between the ID number and the number of threads, selecting the same task to be executed by only one of the idle threads that meets the preset rules at a certain moment.

可以理解的是,所述计算机程序可以执行的细化功能和扩展功能可参照上面实施例的描述。It can be understood that the detailed functions and extended functions that can be executed by the computer program can refer to the description of the above embodiments.

基于相同的发明构思,本发明又一实施例提供了一种计算机程序产品,所计算机程序产品包括有计算机程序,该计算机程序被处理器执行时实现上述方法的全部步骤,例如,所述处理器执行所述计算机程序时实现下述过程:设置定时快照任务的定时周期,对每一个所述定时快照任务分配一个自增的ID号;检测所有的所述定时快照任务,选出命中所述定时周期的定时快照任务放入创建的队列中;从多个线程中选择一个空闲的线程检查所述队列中是否存在任务,并从所述队列中存在任务的对应位置处取出所述任务的ID号,根据所述ID号与线程数量的关系,选择在某时刻同一任务仅由一个符合预设规则的所述空闲的线程来执行。Based on the same inventive concept, another embodiment of the present invention provides a computer program product, which includes a computer program. When the computer program is executed by a processor, all the steps of the above method are implemented. For example, when the processor executes the computer program, the following process is implemented: setting a timing period of a timed snapshot task, and assigning a self-incrementing ID number to each of the timed snapshot tasks; detecting all the timed snapshot tasks, selecting the timed snapshot tasks that hit the timing period and putting them into a created queue; selecting an idle thread from multiple threads to check whether there is a task in the queue, and taking out the ID number of the task from the corresponding position of the task in the queue, and selecting, according to the relationship between the ID number and the number of threads, to execute the same task at a certain moment only by one of the idle threads that meets the preset rules.

此外,上述的存储器中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-OnlyMemory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。In addition, the logic instructions in the above-mentioned memory can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product. Based on such an understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本发明实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present invention. Those of ordinary skill in the art may understand and implement them without creative effort.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的流量审计方法。Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM/RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the traffic audit method described in each embodiment or some parts of the embodiment.

此外,在本发明中,诸如第一和第二等之类的关系术语仅仅用来将一个实体或者操作与另一个实体或操作区分开来,而不一定要求或者暗示这些实体或操作之间存在任何这种实际的关系或者顺序。而且,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、物品或者设备中还存在另外的相同要素。In addition, in the present invention, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

此外,在本发明中,参考术语“一个实施例”、“一些实施例”、“示例”、“具体示例”、或“一些示例”等的描述意指结合该实施例或示例描述的具体特征、结构、材料或者特点包含于本发明的至少一个实施例或示例中。在本说明书中,对上述术语的示意性表述不必须针对的是相同的实施例或示例。而且,描述的具体特征、结构、材料或者特点可以在任一个或多个实施例或示例中以合适的方式结合。此外,在不相互矛盾的情况下,本领域的技术人员可以将本说明书中描述的不同实施例或示例以及不同实施例或示例的特征进行结合和组合。In addition, in the present invention, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (9)

1. A method of executing a timed snapshot task, comprising:
setting a timing period of a timing snapshot task, and distributing a self-increasing ID number to each timing snapshot task;
detecting all the timing snapshot tasks, selecting the timing snapshot tasks hitting the timing period, and putting the timing snapshot tasks into a created queue;
Selecting an idle thread from a plurality of threads to check whether a task exists in the queue, extracting an ID number of the task from a corresponding position where the task exists in the queue, selecting that the same task is only executed by the idle thread conforming to a preset rule at a certain moment according to the relation between the ID number and the number of threads, and selecting that the same task is only executed by the idle thread conforming to the preset rule at the certain moment according to the relation between the ID number and the number of threads comprises:
And calculating a remainder value obtained by dividing the ID number and the number of threads, removing the task from the queue and executing the task by the idle thread if the remainder value is equal to the thread number of the idle thread, and replacing the task at the position corresponding to the original position and moving one position to continue checking and calculating if the remainder value is not equal to the thread number of the idle thread.
2. The method of claim 1, wherein the queue is a single queue, and the idle thread is controlled to start detecting from a head task in the queue.
3. The method of claim 1, wherein detecting all of the timed snapshot tasks, selecting a timed snapshot task that hits the timed period to place in a created queue comprises:
And when the timing period is reached, all snapshot tasks to be executed are sequentially put into the queue, the positions of the queue are marked, each task is stored, the positions in the queue are moved backwards, and the marking value is increased by 1.
4. The method according to claim 2, wherein when there are a plurality of empty threads, the plurality of empty threads alternately check and calculate a remainder value obtained by dividing the ID number by the number of threads.
5. The method of claim 1, wherein the timing period is an interval period or a fixed point in time.
6. The method of claim 1, wherein all of the timed snapshot tasks are detected every interval of time, the time period being one minute.
7. An apparatus for executing a timed snapshot task, the apparatus comprising:
the task setting module is used for setting the timing period of the timing snapshot task and distributing a self-increasing ID number to each timing snapshot task;
the task detection module is used for detecting all the timing snapshot tasks, selecting the timing snapshot tasks hitting the timing period, and putting the timing snapshot tasks into the created queue;
The task execution module is used for selecting an idle thread from a plurality of threads to check whether a task exists in the queue, extracting an ID number of the task from a corresponding position where the task exists in the queue, and selecting that the same task is executed by only the idle thread conforming to a preset rule at a certain moment according to the relation between the ID number and the number of threads;
According to the relation between the ID number and the number of threads, selecting that the same task is executed by only one idle thread conforming to a preset rule at a certain moment comprises the following steps:
And calculating a remainder value obtained by dividing the ID number and the number of threads, removing the task from the queue and executing the task by the idle thread if the remainder value is equal to the thread number of the idle thread, and replacing the task at the position corresponding to the original position and moving one position to continue checking and calculating if the remainder value is not equal to the thread number of the idle thread.
8. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor performs the steps of the method of performing timed snapshot tasks according to any one of claims 1 to 6 when the program is executed.
9. A non-transitory computer readable storage medium having stored thereon a computer program, which when executed by a processor, implements the steps of the method of performing a timed snapshot task according to any one of claims 1 to 6.
CN202210167289.0A 2022-02-23 2022-02-23 Method and device for executing timed snapshot task Active CN114564291B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210167289.0A CN114564291B (en) 2022-02-23 2022-02-23 Method and device for executing timed snapshot task

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210167289.0A CN114564291B (en) 2022-02-23 2022-02-23 Method and device for executing timed snapshot task

Publications (2)

Publication Number Publication Date
CN114564291A CN114564291A (en) 2022-05-31
CN114564291B true CN114564291B (en) 2024-10-29

Family

ID=81713515

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210167289.0A Active CN114564291B (en) 2022-02-23 2022-02-23 Method and device for executing timed snapshot task

Country Status (1)

Country Link
CN (1) CN114564291B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115454931A (en) * 2022-09-15 2022-12-09 苏州浪潮智能科技有限公司 Timing snapshot generating method and device, electronic equipment and storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111984402A (en) * 2020-07-25 2020-11-24 苏州浪潮智能科技有限公司 Unified scheduling monitoring method and system for thread pool
CN113687931A (en) * 2021-08-30 2021-11-23 济南浪潮数据技术有限公司 Task processing method, system and device

Family Cites Families (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9778990B2 (en) * 2014-10-08 2017-10-03 Hewlett Packard Enterprise Development Lp Methods and systems for concurrently taking snapshots of a plurality of virtual machines
US20220028002A1 (en) * 2020-07-24 2022-01-27 Gregor Ko{hacek over (z)}elj Mechanism for stability within automatic reserve management artificial intelligence

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111984402A (en) * 2020-07-25 2020-11-24 苏州浪潮智能科技有限公司 Unified scheduling monitoring method and system for thread pool
CN113687931A (en) * 2021-08-30 2021-11-23 济南浪潮数据技术有限公司 Task processing method, system and device

Also Published As

Publication number Publication date
CN114564291A (en) 2022-05-31

Similar Documents

Publication Publication Date Title
CN104572446B (en) A kind of automated testing method and system
US11385900B2 (en) Accessing queue data
CN110991127B (en) Task execution method and device, computer equipment and storage medium
CN111143331B (en) Data migration method, device and computer storage medium
KR20180009352A (en) Method and apparatus for data processing for mobile games
CN109714249A (en) A kind of method for pushing and relevant apparatus of small routine message
CN104503868B (en) Method of data synchronization, device and system
CN114564291B (en) Method and device for executing timed snapshot task
CN111290699A (en) Data migration method, device and system
CN109361553B (en) Configuration rollback method and device
CN111124890B (en) Distributed database performance test method, system, terminal and storage medium
CN116401015A (en) Cross-generation CPU cloud host thermomigration method, system, equipment and storage medium
CN111130834B (en) Method and device for processing network elasticity strategy
US11881984B2 (en) Method for handling large-scale host failures on cloud platform
CN109815047A (en) A kind of method and relevant apparatus of data processing
CN115174594B (en) Data synchronization method, device, equipment and medium of distributed system
CN112269663A (en) Android system resource management method, device, terminal device and readable storage medium
CN113791963B (en) View element exposure detection method, device, electronic device and storage medium
WO2024164715A1 (en) System configuration method and apparatus, electronic device, and storage medium
US20180046380A1 (en) Storage System and Method for Scanning For Devices
CN115269730A (en) Wide table synchronization method and device
CN108063808A (en) A kind of acquisition methods of business, device, storage medium and computer equipment
CN111078357A (en) Method and device for virtual machine backup
CN114143083A (en) Blacklist strategy matching method and device, electronic equipment and storage medium
CN113076178A (en) Message storage method, device and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address

Address after: 215168 Jiangsu Province, Suzhou City, Wuzhong Economic Development Zone, Guoqiang Street, Guanpu Road No. 1, Building 9

Patentee after: Suzhou Yuannao Intelligent Technology Co.,Ltd.

Country or region after: China

Address before: 215168 Jiangsu Province, Suzhou City, Wuzhong Economic Development Zone, Guoqiang Street, Guanpu Road No. 1, Building 9

Patentee before: SUZHOU LANGCHAO INTELLIGENT TECHNOLOGY Co.,Ltd.

Country or region before: China