CN113760665A - Reminding task operation method and device - Google Patents
Reminding task operation method and device Download PDFInfo
- Publication number
- CN113760665A CN113760665A CN202010484392.9A CN202010484392A CN113760665A CN 113760665 A CN113760665 A CN 113760665A CN 202010484392 A CN202010484392 A CN 202010484392A CN 113760665 A CN113760665 A CN 113760665A
- Authority
- CN
- China
- Prior art keywords
- reminding
- task
- thread
- time interval
- tasks
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 75
- 230000000903 blocking effect Effects 0.000 claims abstract description 28
- 230000015654 memory Effects 0.000 claims description 33
- 238000012217 deletion Methods 0.000 claims description 8
- 230000007958 sleep Effects 0.000 claims description 7
- 230000037430 deletion Effects 0.000 claims description 6
- 230000008569 process Effects 0.000 description 18
- 238000010586 diagram Methods 0.000 description 12
- 230000006870 function Effects 0.000 description 8
- 238000012545 processing Methods 0.000 description 8
- 238000004891 communication Methods 0.000 description 4
- 230000009286 beneficial effect Effects 0.000 description 3
- 238000013461 design Methods 0.000 description 3
- 238000011161 development Methods 0.000 description 2
- 230000000694 effects Effects 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000014509 gene expression Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000013515 script Methods 0.000 description 2
- 238000003491 array Methods 0.000 description 1
- 235000019800 disodium phosphate Nutrition 0.000 description 1
- 230000003203 everyday effect Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000012423 maintenance Methods 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000011084 recovery Methods 0.000 description 1
- 239000007787 solid Substances 0.000 description 1
- 238000000638 solvent extraction Methods 0.000 description 1
- 230000003442 weekly effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/32—Monitoring with visual or acoustical indication of the functioning of the machine
- G06F11/324—Display of status information
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/3006—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is distributed, e.g. networked systems, clusters, multiprocessor systems
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Quality & Reliability (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Retry When Errors Occur (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention provides a method and a device for running a reminding task, electronic equipment and a computer readable storage medium; the method is applied to a distributed system, wherein the distributed system comprises a plurality of servers; the method comprises the following steps: the server receives a plurality of set reminding tasks and stores the reminding tasks according to the time intervals of the reminding time of the received reminding tasks; setting a thread for executing the reminding task to be in a blocking state, and trying to acquire a distributed lock in the distributed system; when the distributed lock is acquired, converting the thread in the blocking state into an executable state, and executing a reminding task in the current time interval through the thread to send a reminding message corresponding to the executed reminding task; and the current time interval is the time interval when the thread acquires the distributed lock. By the method and the device, stable reminding service can be provided.
Description
Technical Field
The invention relates to the technical field of internet, in particular to a reminding task running method and device, electronic equipment and a computer readable storage medium.
Background
With the development of internet technology, users can perform various services using applications installed on terminals. For example, a user may record a personal work schedule through a calendar application, and may also initiate a schedule of participation by multiple people, such as a meeting, a team event, and so forth. Meanwhile, in order to avoid forgetting of the user, a plurality of services need to use reminding services, such as schedules, meetings, to-do services, and the like. Particularly, when the number of services is large, the reminding service is very important.
In the related art, the reminding task is usually executed by a single server, however, there is a single point effect in executing the reminding task by a single server, which results in the loss of the reminding task when the server fails, and a stable reminding service cannot be provided for the user.
Disclosure of Invention
The embodiment of the invention provides a reminding task running method and device, electronic equipment and a computer readable storage medium, which can provide stable reminding service.
The technical scheme of the embodiment of the invention is realized as follows:
the embodiment of the invention provides a method for running a reminding task, which is applied to a distributed system, wherein the distributed system comprises a plurality of servers and comprises the following steps:
the server receives a plurality of set reminding tasks and stores the reminding tasks according to the time intervals of the reminding time of the received reminding tasks;
setting a thread for executing the reminding task to be in a blocking state, and trying to acquire a distributed lock in the distributed system;
when the distributed lock is acquired, the thread in the blocking state is converted into an executable state, and a reminding task in the current time interval is executed through the thread so as to
Sending a reminding message corresponding to the executed reminding task;
and the current time interval is the time interval when the thread acquires the distributed lock.
The embodiment of the invention provides a running device for reminding tasks, which is applied to a distributed system, wherein the distributed system comprises a plurality of servers and comprises the following components:
the storage module is used for receiving the set reminding tasks and storing the reminding tasks according to the time intervals of the reminding time of the received reminding tasks;
the acquisition module is used for setting a thread for executing the reminding task to be in a blocking state and trying to acquire a distributed lock in the distributed system;
the execution module is used for converting the thread in the blocking state into an executable state when the distributed lock is acquired, and executing a reminding task in a current time interval through the thread, wherein the current time interval is the time interval in which the thread acquires the distributed lock;
and the sending module is used for sending the reminding message corresponding to the executed reminding task.
In the above scheme, the storage module is further configured to divide each day into a plurality of time intervals according to a set time granularity, and establish a corresponding index table for each time interval;
and determining the time interval of the reminding time of the received reminding task in the divided time intervals, and storing the received reminding task in an index table corresponding to the determined time interval.
In the above scheme, the apparatus further includes a dividing module, configured to perform a modulo operation on a plurality of reminding tasks stored in any time interval in the index table according to numbers of the plurality of reminding tasks;
and dividing the modulus operation result into a plurality of number segments according to the set granularity, and dividing the plurality of reminding tasks into corresponding number segments according to the numbers of the plurality of reminding tasks.
In the foregoing solution, the execution module is further configured to adjust the number of threads started in the server according to the number of the number segments in the current time interval, so that the number of threads started in the server is adjusted to enable the number segments to be equal to or greater than a predetermined number
Each thread reads the reminding task in one number segment and adds the read reminding task into the corresponding circular queue;
and aiming at any circular queue in the plurality of circular queues, executing the reminding task in any circular queue through a thread corresponding to any circular queue.
In the above scheme, the execution module is further configured to execute, by the thread, a reminding service within a current time interval within a validity period of the distributed lock;
when the validity period of the distributed lock is exceeded, the distributed lock is released and the thread in the executable state is reconverted to a blocking state.
In the above scheme, the execution module is further configured to add the reminding task to be executed in the current time interval to a message queue in an asynchronous manner, so as to send the reminding message corresponding to the executed reminding task through the message queue.
In the foregoing solution, the execution module is further configured to, when the number of the reminding tasks that need to be executed in the current time interval is greater than a preset threshold, read the reminding task that needs to be executed in the current time interval by reading the task thread, store the read reminding task in the memory container, and
and acquiring the reminding task to be executed from the memory container through a task execution thread and executing the reminding task.
In the above scheme, the execution module is further configured to switch the read task thread to a sleep state after the reminding task that needs to be executed in the current time interval is read;
and starting a group of new reading task threads to read the reminding tasks needing to be executed in the next time interval when the time of the next time interval is up, wherein the number of the new reading task threads is the same as the number of the number segments in the next time interval.
In the above scheme, the execution module is further configured to, when the execution of the reminding task fails, add the reminding task that has failed to be executed into a retry queue, so as to re-execute the reminding task through the retry queue;
when the reminding task is successfully executed, deleting the reminding task which is successfully executed, and
and when the deletion fails, adding the reminding task with the deletion failure into the retry queue so as to delete the reminding task again through the retry queue.
An embodiment of the present invention provides an electronic device, including:
a memory for storing executable instructions;
and the processor is used for realizing the running method of the reminding task provided by the embodiment of the invention when the executable instruction stored in the memory is executed.
The embodiment of the invention provides a computer-readable storage medium, which stores executable instructions and is used for causing a processor to execute the executable instructions so as to realize the running method of the reminding task provided by the embodiment of the invention.
The embodiment of the invention has the following beneficial effects:
the reminding task is executed by the servers through respective threads based on the distributed system, and the state of the threads for executing the reminding task by the servers is controlled based on the distributed lock, so that the efficient and ordered execution of the reminding task is realized; and the plurality of servers realize disaster tolerance of the reminding service and can provide stable reminding service.
Drawings
FIG. 1 is an alternative architecture diagram of a system for running a reminder task according to an embodiment of the present invention;
FIG. 2 is an alternative structural diagram of a server according to an embodiment of the present invention;
FIG. 3 is an alternative flow chart of a method for running a reminder task according to an embodiment of the present invention;
FIG. 4 is a schematic flow chart of another alternative method for running a reminder task according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of a user interface for a schedule-setting reminder task according to an embodiment of the present invention;
FIG. 6 is a schematic interface diagram of a reminder task set by a user for a meeting according to an embodiment of the present invention;
FIG. 7 is a schematic interface diagram of a user's set reminder task for to-do according to an embodiment of the present invention;
FIG. 8 is a schematic diagram of an architecture for providing an alert service based on a distributed lock chubby according to an embodiment of the present invention;
fig. 9 is a flowchart illustrating a reminding task executed by multiple threads in different number segments according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail with reference to the accompanying drawings, the described embodiments should not be construed as limiting the present invention, and all other embodiments obtained by a person of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.
In the following description, reference is made to "some embodiments" which describe a subset of all possible embodiments, but it is understood that "some embodiments" may be the same subset or different subsets of all possible embodiments, and may be combined with each other without conflict.
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs. The terminology used herein is for the purpose of describing embodiments of the invention only and is not intended to be limiting of the invention.
Before further detailed description of the embodiments of the present invention, terms and expressions mentioned in the embodiments of the present invention are explained, and the terms and expressions mentioned in the embodiments of the present invention are applied to the following explanations.
1) Reminder services, i.e. meeting, scheduling, to-do, etc. business support events wake up participants when or before they occur.
2) Disaster recovery, multiple machines working simultaneously, when one of the machines fails accidentally and stops working, other machines can work normally, and service is provided normally.
3) Distributed systems, systems in which components are distributed over networked computers, and in which the components communicate and act in concert by passing messages between the components. In a distributed system, a server typically includes multiple machines that together form a cluster, with each machine providing the same service.
4) Thread, the smallest unit in the operating system that can perform computational scheduling. It is contained within the process and is the actual unit of execution within the process. A thread refers to a single sequential control flow in a process, and a process can concurrently execute a plurality of threads, each thread concurrently executing different tasks.
5) The message queue, an important component in a distributed system, can provide a reliable asynchronous communication mechanism based on messages, and can store the messages sent and received between different applications in distributed deployment in a reliable and effective message queue to prevent the messages from being lost. The message queue supports simultaneous reading and writing of multiple processes, receiving and sending are not interfered mutually, and all applications or components are not required to be in a running state all the time.
The inventor finds that in the related art, a single server is usually used for executing the reminding task, but the single server has a single-point effect when the reminding task is executed, so that the reminding task is lost when the server fails, disaster tolerance does not exist, and stable reminding service cannot be provided for users.
In contrast, the embodiment of the present invention provides a method for running a reminder task, which provides a reminder service based on a distributed system, and thus can be applied to the distributed system, where the distributed system includes a plurality of servers; the server receives a plurality of set reminding tasks and stores the reminding tasks according to the time intervals of the reminding time of the received reminding tasks; setting a thread for executing the reminding task to be in a blocking state, and trying to acquire a distributed lock in a distributed system; when the distributed lock is acquired, converting the thread in the blocking state into an executable state, and executing the reminding task in the current time interval through the thread so as to send a reminding message corresponding to the executed reminding task; and the current time interval is the time interval when the thread acquires the distributed lock.
In view of this, embodiments of the present invention provide a method and an apparatus for running a reminding task, an electronic device, and a computer-readable storage medium, which can provide a stable reminding service.
An exemplary application of the method for running the reminder task according to the embodiment of the present invention is described below, and the method for running the reminder task according to the embodiment of the present invention may be implemented by various electronic devices, for example, a server cluster, or a method in which a user terminal and the server cluster cooperate with each other.
Referring to fig. 1, fig. 1 is an optional architecture schematic diagram of an operation system 100 for a reminding task according to an embodiment of the present invention, where the operation system 100 for a reminding task includes: a distributed system 200 (wherein the distributed system 200 comprises a server cluster composed of a plurality of servers 300, and in fig. 1, a server 300-2, and a server 300-N are exemplarily shown), a network 400 and a terminal 500 (a terminal 500-1, a terminal 500-2, and a terminal 500-N are exemplarily shown), the terminal 500 is connected to the distributed system 200 through the network 400, and the network 400 may be a wide area network or a local area network, or a combination of both.
The operation method of the reminding task provided by the embodiment of the invention can be realized through the following processes: firstly, the terminal 500 sends a plurality of reminding tasks set by a user for a service to the distributed system 200 through the network 400, after receiving the plurality of reminding tasks sent by the terminal 500, the distributed system 200 stores the plurality of reminding tasks in the server 300-1 according to the time interval of the reminding time of the received reminding task, and then the distributed system 200 backs up the reminding tasks stored in the server 300-1 to the servers 300-2 to 300-N, so that each server stores the same reminding task. Subsequently, the servers 300-1 to 300-N set respective threads for performing the reminder task to a blocking state and attempt to acquire a distributed lock in the distributed system 200, respectively. When a thread started by one of the servers acquires the distributed lock, the thread is converted from a blocking state to an executable state, the thread executes a reminding task in the current time interval, and a reminding message corresponding to the executed reminding task is sent to the terminal 500. The distributed lock is sometimes limited, and when the validity period of the distributed lock is exceeded, the distributed lock is released so that other threads which are opened in the server acquiring the distributed lock can execute a reminding task.
Referring to fig. 2, fig. 2 is a schematic structural diagram of a server 300 according to an embodiment of the present invention, where the server 300 shown in fig. 2 includes: at least one processor 310, memory 340, at least one network interface 320. The various components in server 300 are coupled together by a bus system 330. It is understood that the bus system 330 is used to enable connected communication between these components. The bus system 330 includes a power bus, a control bus, and a status signal bus in addition to a data bus. For clarity of illustration, however, the various buses are labeled as bus system 330 in fig. 2.
The Processor 310 may be an integrated circuit chip having Signal processing capabilities, such as a general purpose Processor, a Digital Signal Processor (DSP), or other programmable logic device, discrete gate or transistor logic device, discrete hardware components, or the like, wherein the general purpose Processor may be a microprocessor or any conventional Processor, or the like.
The memory 340 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid state memory, hard disk drives, optical disk drives, and the like. Memory 340 optionally includes one or more storage devices physically located remote from processor 310.
The memory 340 includes volatile memory or nonvolatile memory, and may include both volatile and nonvolatile memory. The nonvolatile memory may be a Read Only Memory (ROM), and the volatile memory may be a Random Access Memory (RAM). The memory 340 described in connection with embodiments of the invention is intended to comprise any suitable type of memory.
In some embodiments, memory 340 is capable of storing data to support various operations, examples of which include programs, modules, and data structures, or subsets or supersets thereof, as exemplified below.
An operating system 341 including system programs for processing various basic system services and performing hardware-related tasks, such as a framework layer, a core library layer, a driver layer, etc., for implementing various basic services and processing hardware-based tasks;
a network communication module 342 for communicating to other computing devices via one or more (wired or wireless) network interfaces 320, exemplary network interfaces 320 including: bluetooth, wireless compatibility authentication (WiFi), and Universal Serial Bus (USB), etc.;
in some embodiments, the running device of the reminding task provided by the embodiment of the present invention may be implemented in software, and fig. 2 shows the running device 343 of the reminding task stored in the memory 340, which may be software in the form of programs and plug-ins, and includes the following software modules: the storage module 3431, the obtaining module 3432, the executing module 3433 and the sending module 3434 are logical modules, and thus may be arbitrarily combined or further divided according to the functions implemented. The functions of the respective modules will be explained below.
In other embodiments, the running Device of the reminding task provided by the embodiments of the present invention may be implemented in hardware, and as an example, the running Device of the reminding task provided by the embodiments of the present invention may be a processor in the form of a hardware decoding processor, which is programmed to execute the running method of the reminding task provided by the embodiments of the present invention, for example, the processor in the form of the hardware decoding processor may be implemented by one or more Application Specific Integrated Circuits (ASICs), DSPs, Programmable Logic Devices (PLDs), Complex Programmable Logic Devices (CPLDs), Field Programmable Gate Arrays (FPGAs), or other electronic components.
The following specifically describes an operation method of the reminding task provided by the embodiment of the present invention. Referring to fig. 3, fig. 3 is an alternative flowchart of a method for running a reminder task according to an embodiment of the present invention, which will be described with reference to the steps shown in fig. 3.
In step S301, the distributed system receives a plurality of set reminder tasks transmitted from the user terminal.
Here, the user may set a reminding task for each service, and then the user terminal transmits a plurality of reminding tasks set for the service by the user to the distributed system.
For example, a user may set a reminding task for a schedule, for example, the user may fill a specific schedule in a interface of the calendar application (for example, meeting time 2 month 18 day 4 pm, meeting duration 1 hour, reminding time 15 minutes before the meeting starts, and the like), and then the calendar application sends the reminding task containing the above information to the distributed system.
For example, the user may set a reminding task for the meeting, for example, the user may fill in a specific meeting schedule (e.g., a start time of the meeting, a duration of the meeting, participants of the meeting, etc.) in an interface of the enterprise WeChat, and then the enterprise WeChat sends the reminding task containing the above information to the distributed system.
For example, the user may set a reminder task for to-do, for example, the user may fill in details to be handled in an interface of the calendar application (for example, the details to be handled are to write a weekly report, the reminder time is friday afternoon 3 pm, and the like), and then the calendar application sends the reminder task including the above information to the distributed system.
In some embodiments, the distributed system may employ chubby, which is a lock service for a loosely-coupled distributed system, and is generally used to provide a highly available lock service for a loosely-coupled distributed system composed of a large number of small computers, and may implement functions such as synchronization, storing metadata, topology, or configuration information in the distributed system. In terms of system architecture, a typical chubby cluster generally consists of 5 servers, and the replica servers adopt Paxos protocol and determine one server as a main server by voting. Once a server becomes the master server, chubby ensures that other servers do not become the master server for a period of time called a lease. In the operation process, the main server can continuously rent, and if the main server fails, the rest servers can elect a new server to become the main server. In actual operation, only the main server can write data, and other servers copy data from the database of the main server by using the Paxos protocol. Therefore, after receiving the plurality of reminding tasks sent by the user terminal, the received plurality of reminding tasks are firstly stored in the database of the main server, and then the reminding tasks are backed up in other servers so as to store the same reminding tasks in each server.
In other embodiments, the distributed system may also adopt Zookeeper, which is an open-source scalable high-throughput distributed coordination system, and the Zookeeper cluster service also consists of multiple servers (minimum 3), and generates 1 master server and multiple slave servers by election. The client can read the required data from any one server, but the written or modified data must be executed on the main server. When the client connects to the slave servers to write or update data, the slave servers forward the request to the master server, the master server completes the writing or updating of the data, and notifies all the slave servers of corresponding information. The Zookeeper cluster generally consists of 2n +1 (odd number) servers, can tolerate the fault of n slave servers to the maximum extent, and has strong disaster tolerance capability.
The embodiment of the invention sends the plurality of reminding tasks set by the user aiming at the service to the distributed system so as to be stored in the plurality of servers included in the distributed system, thus, when a certain server breaks down and stops working, other servers can still work normally, the disaster tolerance of the service is improved, and more stable reminding service can be provided for the user.
In step S302, the server stores the received time interval of the reminding time of the reminding task.
In some embodiments, the server stores the received time interval of the reminding time of the reminding task, and the storage may be implemented as follows: dividing each day into a plurality of time intervals according to set time granularity, and establishing a corresponding index table for each time interval; and determining the time interval of the reminding time of the received reminding task in the divided time intervals, and storing the received reminding task in an index table corresponding to the determined time interval.
For example, the set time granularity may be minutes, each day is divided into 1440(24 hours by 60 minutes) different time intervals according to the minutes, and a corresponding index table is established for each time interval, that is, the received multiple reminding tasks are scattered and stored in 1440 different tables, respectively, where table 1 is used for storing the reminding tasks with the reminding time of 00:00-00: 01; table 2 is used to store the reminding task with the reminding time of 00:01-00:02, and so on.
For example, the set time granularity may also be hours, each day is divided into 24 different time intervals according to the hours, and a corresponding index table is established for each time interval, that is, the received plurality of reminding tasks are scattered and stored in 24 different tables, wherein table 1 is used for storing the reminding tasks with the reminding time of 00:00-01: 00; and the table 2 is used for storing the reminding tasks with the reminding time of 01:00-02:00, and so on.
It should be noted that the time granularity may be set according to the number of the reminding tasks that need to be executed actually, for example, when the number of the reminding tasks that need to be executed is small, a larger time granularity may be set; conversely, when the number of the reminding tasks to be executed is larger, a smaller time granularity may be set, which is not specifically limited in the embodiment of the present invention.
In other embodiments, in order to support multithread execution of the reminding tasks, the plurality of reminding tasks stored in each time interval may be further divided, for example, a modulo operation may be performed on the numbers of the plurality of reminding tasks stored in each time interval, and a modulo operation result is divided into a plurality of number segments according to a set granularity, so as to divide the plurality of reminding tasks into corresponding number segments. And then, the server simultaneously starts threads with the same number according to the number of the number segments in the current time interval, and each thread executes the reminding task in one number segment.
It should be noted that, for the reminding tasks stored in different time intervals, after performing modulo operation on the serial numbers of the reminding tasks, the granularity of dividing the modulo operation result is also different, for example, when the number of the reminding tasks stored in a certain time interval is large, a larger granularity may be set to divide the modulo operation result, for example, the modulo operation result may be divided into 5 different number segments, and at this time, the server simultaneously starts 5 threads to execute the reminding tasks in the corresponding number segments; when the number of the reminding tasks stored in a certain time interval is small, a small granularity can be set to divide the modulo operation result, for example, the modulo operation result can be divided into 2 different number segments, and at this time, the server simultaneously starts 2 threads to execute the reminding tasks in the corresponding number segments.
In other embodiments, the specific storage manner of the reminder task may be stored by using a distributed Key value database, for example, by using a pkv (paxosstore Key value) with high disaster tolerance. The PKV is a high-availability storage system, and the system adopts a combined design in a storage layer and develops different storage engines aiming at different storage models. The PKV is characterized in that the distributed consistency protocol based on the Paxos is extracted to be used as a middleware, and the underlying multi-model storage engine can access the middleware in various conditions. This makes the adjustment, maintenance, scaling and expansion of the storage engine easier. The overall architecture of PKV includes a programming model, a consistency layer, and a storage layer 3 layer, where the programming model provides a variety of data architectures for various external applications. The consistency layer implements the Paxos-based storage protocol. The storage tier contains a plurality of storage engines built from different storage models that can meet a variety of performance requirements. The architecture of PKV differs from conventional storage designs in that it can abstract the consistency protocol application as a middleware that provides data consistency guarantees to all potential storage engines. PK V adopts a combined storage design, a plurality of storage models are applied to a storage layer, only the realization problem of high availability is processed, and the consistency problem is processed by a consistency layer. This allows each storage engine and the entire storage tier to be expanded as needed. Since the consistency protocol application has been decoupled from the storage engine, all supported storage models can utilize data consistency guarantees under various circumstances, which also makes cross-model data access easier to implement. The index of the PKV adopts the leftmost matching principle, so that a minute time field is added in the index of the reminding task in the table, the index can be completely hit through the field, and the query efficiency can be greatly improved.
After receiving the plurality of reminding tasks sent by the user terminal, the embodiment of the invention stores the reminding tasks according to the time intervals of the reminding time of the received reminding tasks, namely, the reminding tasks are scattered and stored in different index tables, thereby improving the writing and query efficiency of the reminding tasks.
In step S303, the server sets the thread for executing the reminder task to a blocking state and attempts to acquire a distributed lock in the distributed system.
Here, the plurality of servers in the distributed system respectively set the threads for executing the reminder task to be in the blocking state, and attempt to acquire the distributed lock in the distributed system.
For example, a plurality of servers in the distributed system respectively start respective GetLock threads and attempt to acquire a distributed lock in the distributed system in a blocking manner. The GetLock thread judges whether the distributed lock is acquired or not through a CheckHeld (fd) method, when the CheckHeld (fd) method returns true, the corresponding GetLock thread is determined to acquire the distributed lock, and when the CheckHeld (fd) method returns false, the corresponding GetLock thread is determined not to acquire the distributed lock.
In step S304, when the distributed lock is acquired, the server converts the thread in the blocking state into an executable state, and executes the reminding task in the current time interval through the thread.
In some embodiments, when a thread corresponding to a server in the distributed system acquires the distributed lock, the thread is converted from a blocking state to an executable state, and a reminding task within a current time interval is executed by the thread, wherein the current time interval is a time interval in which the thread acquires the distributed lock.
In other embodiments, the step S304 of executing the reminding task in the current time interval by the thread may be implemented by steps S401 to S405 shown in fig. 4, which will be described with reference to the steps shown in fig. 4.
In step S401, the distributed system first determines the number of threads in the server for executing the reminding task according to the number of the number segments in the current time interval.
Here, when the number of the reminding tasks to be executed is large, backlog is easily formed by executing the reminding tasks through a single thread, and the reminding tasks are lost. In contrast, according to the operation method of the reminding task provided by the embodiment of the present invention, the reminding task to be executed is divided into different number segments according to the number of the reminding task, and then the number of the number segments in the current time interval used for executing the reminding task in the server is determined.
For example, assuming that the number of number segments in the current time interval is 5 (i.e. dividing the reminding task to be executed into 5), 5 threads are simultaneously started in the server.
Step S402, the thread 1 reads the reminding task in the number section 1 and adds the read reminding task into the circular queue 1.
In step S403, the thread N reads the reminding task in the number segment N, and adds the read reminding task to the circular queue N.
Here, there is a one-to-one correspondence between threads, number segments, and circular queues. The thread 1 is used for reading the reminding task in the number section 1 and adding the read reminding task into the circular queue 1, the thread 2 is used for reading the reminding task in the number section 2 and adding the read reminding task into the circular queue 2, and the like.
In step S404, thread 1 executes the reminder task in circular queue 1.
In step S405, the thread N executes the reminder task in the circular queue N.
In this case, the mutual independence between the reminding tasks is considered, so that a plurality of circular queues are used, and different threads only execute the reminding tasks in the corresponding circular queues, so that the execution speed of the reminding tasks can be increased by executing the reminding tasks of different number segments through the plurality of threads, and the reminding tasks are prevented from being lost due to overstock.
In some embodiments, in order to avoid the loss of the reminding task, the reading task and the executing task may be further divided into 2 threads, where the reading task thread is responsible for reading the reminding task to be executed in the current time interval and adding the read reminding task to the memory container, and the executing task thread is responsible for obtaining the reminding task stored in the memory container by the reading task thread from the memory container and executing the reminding task. In addition, after the reading task thread finishes reading the reminding tasks in the current time interval, if the number of the reminding tasks to be executed is larger than zero, the reading task thread enters a sleep state, and at the moment, the reminding tasks added newly are lost after the reading is finished. For this purpose, the server may separately start a group of threads for reading the creation time and the scheduling time as the reminding tasks in the next time interval, where the number of the threads is the same as the number of the number segments in the next time interval, so that the reminding tasks may be prevented from being lost.
In other embodiments, in order to avoid repeated execution of the reminder task, the reminder task that was successfully executed may also need to be deleted from the reminder task list. The deleting process is a remote process call, and there may be a failure, for this reason, a retry queue may be started in each server, and the reminding task that failed to delete is added to the retry queue, and is deleted again by the retry queue.
The embodiment of the invention divides the reminding task, simultaneously starts a plurality of threads in the server, and each thread only executes the reminding task of one number segment, thereby greatly accelerating the execution speed of the reminding task and avoiding the overstocked reminding task.
In step S305, a reminder message corresponding to the executed reminder task is transmitted to the terminal.
In some embodiments, the reminding task to be executed may be added to the message queue, and the message queue sends the reminding message corresponding to the executed reminding task to the terminal, so, based on the asynchronous logic, the server only needs to trigger the reminding task, and the specific task processing logic is executed by the message queue, which may greatly increase the execution speed of the reminding task.
It should be noted that, the reminding task to be executed is added to the message queue, and the specific task processing logic executed by the message queue is a remote procedure call, which may cause the reminding task to be lost due to timeout and other problems.
In step S306, when the validity period of the distributed lock is exceeded, the distributed lock is released and the thread is reconverted to the blocking state.
Here, the distributed lock is sometimes limited (e.g., a 5 second timeout), and when the validity period of the distributed lock is exceeded, the thread releases the distributed lock, and the server reconverts the thread to a blocking state. At this time, other servers in the distributed system can try to acquire the distributed lock, so that other servers acquiring the distributed lock execute the reminding task, and thus, the reminding task is executed by the plurality of servers, when one server fails and stops working, the other servers can still work normally, the disaster tolerance of the reminding service is improved, and reliable reminding service can be provided for users.
Continuing with the exemplary structure of the operation device 343 for reminding task provided by the embodiment of the present invention implemented as a software module, in some embodiments, as shown in fig. 2, the software module stored in the operation device 343 for reminding task in the memory 340 may include: a storage module 3431, an acquisition module 3432, an execution module 3433, and a sending module 3434.
The storage module 3431 is configured to receive a plurality of set reminding tasks, and store the plurality of set reminding tasks according to time intervals where reminding times of the received reminding tasks are located; an obtaining module 3432, configured to set a thread for executing a reminding task to a blocking state, and attempt to obtain a distributed lock in a distributed system; the execution module 3433 is configured to, when the distributed lock is acquired, convert the thread in the blocking state into an executable state, and execute the reminding task in the current time interval through the thread, where the current time interval is a time interval in which the thread acquires the distributed lock; a sending module 3434, configured to send a reminder message corresponding to the executed reminder task.
In some embodiments, the storage module 3431 is further configured to divide each day into a plurality of time intervals according to the set time granularity, and establish a corresponding index table for each time interval; and determining the time interval of the reminding time of the received reminding task in the divided time intervals, and storing the received reminding task in an index table corresponding to the determined time interval.
In some embodiments, the operation device 343 for reminding tasks further includes a partitioning module 3435, configured to perform a modulo operation on the plurality of reminding tasks stored in any time interval in the index table according to the numbers of the plurality of reminding tasks; and dividing the modulus operation result into a plurality of number segments according to the set granularity, and dividing the plurality of reminding tasks into corresponding number segments according to the numbers of the plurality of reminding tasks.
In some embodiments, the execution module 3433 is further configured to adjust the number of threads started in the server according to the number of number segments in the current time interval, so that each thread reads the reminding task in one number segment, and adds the read reminding task to the corresponding circular queue; and aiming at any circular queue in the plurality of circular queues, executing the reminding task in any circular queue through a thread corresponding to any circular queue.
In some embodiments, the execution module 3433 is further configured to execute, by the thread, the alert service within the current time interval within the validity period of the distributed lock; when the validity period of the distributed lock is exceeded, the distributed lock is released and the thread in the executable state is reconverted to the blocking state.
In some embodiments, the execution module 3433 is further configured to add the reminder task to be executed in the current time interval to the message queue in an asynchronous manner, so as to send the reminder message corresponding to the executed reminder task through the message queue.
In some embodiments, the execution module 3433 is further configured to, when the number of the reminding tasks that need to be executed in the current time interval is greater than the preset threshold, read the reminding task that needs to be executed in the current time interval by the read task thread, store the read reminding task in the memory container, and acquire the reminding task that needs to be executed from the memory container by the execution task thread and execute the reminding task.
In some embodiments, the execution module 3433 is further configured to switch the read task thread to a sleep state after the reminding task that needs to be executed in the current time interval is read; and when the time of the next time interval is up, starting a group of new reading task threads to read the reminding task to be executed in the next time interval, wherein the number of the new reading task threads is the same as the number of the number segments in the next time interval.
In some embodiments, the execution module 3433 is further configured to, when the execution of the reminder task fails, add the reminder task that failed to execute into the retry queue for re-execution through the retry queue; and when the reminding task is successfully executed, deleting the reminding task which is successfully executed, and when the deletion fails, adding the reminding task which fails to delete into the retry queue so as to delete again through the retry queue.
It should be noted that the description of the apparatus according to the embodiment of the present invention is similar to the description of the method embodiment, and has similar beneficial effects to the method embodiment, and therefore, the description is omitted. The inexhaustible technical details of the running device of the reminding task provided by the embodiment of the invention can be understood according to the description of any one of the figures 3-4.
In the following, an exemplary application of the embodiments of the present invention in a practical application scenario will be described.
With the development of internet technology, a user can install various applications on a terminal and perform different services based on the installed applications. For example, a user may record a user's personal work schedule through a calendar application installed on the terminal, and may also initiate a schedule in which multiple people participate, such as a meeting, a team event, and so on. Meanwhile, in order to avoid forgetting of the user, a plurality of services need to use the reminding service, and especially when the number of the services is large, the reminding service is very important. The specific implementation process of the reminding service is as follows: the method comprises the steps that a user sets a reminding task aiming at a service in a graphical interface of a terminal, then the terminal sends the reminding task set aiming at the service by the user to a server, and the server executes the reminding task so as to send a reminding message to the terminal at preset time to remind the user.
In the related art, the reminding service is usually provided by delaying a message queue (delaymq), but the method has short delay time and does not support the reminding service after one month; in addition, problems such as queue backlog are easily caused, which results in delay of the reminding service or loss of the reminding task.
In view of the above problems, embodiments of the present invention provide a method for running a reminding task, which can provide a reliable reminding service, is more suitable for a service, and enables more services to access the reminding service, thereby providing various reminding functions for a user.
The operation method of the reminding task provided by the embodiment of the invention supports the reminding service of various services.
For example, referring to fig. 5, fig. 5 is a schematic interface diagram of a reminding task set by a user for a schedule according to an embodiment of the present invention. As shown in fig. 5, a user may set information such as a reminding time (501), a duration of a conference (502), a participant of the conference (503), whether to repeat reminding (504) or not, and the like for a schedule, and then, a terminal sends a reminding task including the information to a distributed system, and a server in the distributed system sends a corresponding reminding message to the terminal at a preset time.
For example, referring to fig. 6, fig. 6 is an interface schematic diagram of a reminding task set by a user for a conference according to an embodiment of the present invention, as shown in fig. 6, the user may set information such as a reminding time (601), a duration (602) of the conference, and a participant (603) of the conference for the conference, and then, a terminal sends the reminding task including the information to a distributed system, and a server in the distributed system sends a corresponding reminding message to a corresponding terminal at a preset time.
For example, referring to fig. 7, fig. 7 is an interface schematic diagram of a reminding task set by a user for pending, as shown in fig. 7, the user may set information such as a specific pending event (701) and a reminding time (702), and then the terminal sends the reminding task including the information to the distributed system, and a server in the distributed system sends a corresponding reminding message to the terminal at a preset time.
The following specifically describes an operation method of the reminding task provided by the embodiment of the present invention.
The implementation process of the reminding service can be mainly divided into two parts, namely a reminding task receiving part and a reminding task executing part, which are respectively described in detail below.
Receiving reminding task
The method for running the reminding task provided by the embodiment of the invention adopts a distributed system, the distributed system comprises a plurality of servers, and the user terminal sends the plurality of reminding tasks set by the user aiming at the service to the distributed system so as to store the plurality of reminding tasks in the plurality of servers in the distributed system. And executing the subsequent reminding task by the server acquiring the distributed lock. Specifically, according to the method for running the reminding task provided by the embodiment of the invention, the distributed lock is adopted, the plurality of servers are started, and the thread which obtains the distributed lock in the servers executes the reminding task. Each thread in the server judges whether the distributed lock is acquired or not through a CheckHeld (fd) method (when the return value of the CheckHeld (fd) function is true, the thread is determined to acquire the distributed lock, and when the return value of the CheckHeld (fd) function is false, the thread is determined not to acquire the distributed lock). Each server starts a GetLock thread in a blocking manner to attempt to acquire a distributed lock. Meanwhile, the distributed lock is time-efficient (for example, 5 seconds are overtime), the distributed lock is automatically released after overtime, other servers acquiring the distributed lock execute the reminding task, switching time is short, and the reminding task cannot be lost.
In some embodiments, the distributed lock may be a chubby, which is a loosely-coupled distributed system-oriented lock service that is typically used to provide highly available lock services for a loosely-coupled distributed system consisting of a large number of small computers. The purpose of a distributed lock service is to allow its client processes to synchronize each other's operations and agree on the basic state information of the current environment. A typical chubby cluster, for example, may consist of 5 servers that are completely identical in configuration and are in peer-to-peer positions at the very beginning of the system.
Referring to fig. 8, fig. 8 is a schematic diagram of an architecture for providing a reminding service based on a distributed lock chubby according to an embodiment of the present invention, and as shown in fig. 8, each server starts a GetLock thread to attempt to acquire the distributed lock in a blocking manner, executes a reminding task by the thread that acquires the distributed lock, and sends a reminding message corresponding to the executed reminding task to a corresponding terminal. And when the validity period of the distributed lock is exceeded, the distributed lock is automatically released, and other servers acquiring the distributed lock execute a reminding task. Therefore, the plurality of servers execute the reminding task, when one server breaks down and stops working, other servers can still work normally to continue providing the service, the disaster tolerance of the reminding service is improved, and more reliable reminding service can be provided for users.
In some embodiments, in order to further improve writing and searching efficiency of the reminding task, in the method for operating the reminding task provided by the embodiment of the present invention, a distributed key value database with high disaster tolerance is used to store a plurality of reminding tasks, the storage is performed by using a minute level table, the reminding task is determined to be stored in which table according to the reminding time minutes, the execution precision of the reminding task is specifically to the minute level, that is, the reminding tasks that need to be executed every day are scattered in 1440(24 hours × 60 minutes) tables, so as to improve writing and searching efficiency. Meanwhile, in order to support multithread execution of the reminding task, the reminding task which needs to be executed in each minute can be further split into a plurality of number segments, each thread executes the reminding task in one number segment, and the reminding task which needs to be executed is inquired according to the number segments.
For example, a pkv (paxosstore Key value) with high disaster tolerance may be used to store the reminder task. The PKV is a distributed storage system which is synchronously copied among trans-campus data centers, provides flexible data modes and access interfaces, supports hundred million rows of a single table, and has the advantages of quick scalability, low delay, low cost, strong consistency and high availability. The index of the PKV adopts a leftmost matching principle, namely leftmost first, any continuous index can be matched by taking the leftmost as a starting point, and the matching is stopped when a range query is encountered. Therefore, the minute time field is added in the index of the reminding task in the table, the index can be completely hit through the minute time field, and the query efficiency is greatly improved. The query mode can be as follows:
select*from RemindSched% 02d% 02d where minTime=xxx and num>=minNum and num<maxNum。
(II) executing reminding task
In some embodiments, in order to avoid that the execution of the reminding task is too slow, the operation method of the reminding task provided in the embodiments of the present invention adopts asynchronous logic, adds the reminding task to be executed into a Message Queue (MQ), executes specific task processing logic through the Message Queue (i.e., sends the reminding Message to the terminal through the Message Queue), and the reminding service is only responsible for triggering the reminding task, so that the execution speed of the reminding task can be greatly increased, and backlog can be avoided. In addition, it should be noted that, a specific task processing logic is executed by the message queue, and adding an asynchronous task is a remote procedure call, and there may be a problem that a reminding task is lost due to a timeout or the like. Therefore, the reminding task which fails to be executed is added into a retry queue started by the server to be executed again, and the loss of the reminding task is avoided.
In other embodiments, when the number of reminding tasks required to be executed in a certain minute is too large, which may cause the time to be longer than a preset time (e.g. longer than 2 minutes), the reminding task may be lost. Therefore, the read reminding task and the execution reminding task can be separated into 2 threads, the read task thread reads out the reminding task to be executed and stores the reminding task into the memory container, and the execution task thread obtains the reminding service stored in the read task thread from the memory container and executes the reminding service. The multithreading execution reminds that the tasks have concurrency problems, the memory container needs to be locked, and a circular queue can be adopted to replace the lock, so that the efficiency is improved.
In other embodiments, when one thread finishes reading the reminding task but does not finish executing the reminding task, the distributed lock is lost, at this time, threads started by other servers continue to read the reminding task in the current minute and execute the reminding task after acquiring the distributed lock, and if the whole process occurs in the same minute, the reminding task is repeatedly executed. In contrast, according to the operation method of the reminding task provided by the embodiment of the invention, after the reminding task is executed each time, the executed reminding task is deleted from the task list. The delete Procedure is a Remote Procedure Call (RPC) and there may be a failure. Therefore, each server starts a retry queue, and if the reminding task fails to be deleted, the reminding task which fails to be deleted is added into the retry queue for re-deletion, so that the situation of repeated execution of the reminding task is greatly reduced.
In some embodiments, after the reminding tasks are read, if the number of the reminding tasks to be executed is greater than zero, the reading task thread will sleep for the next minute, and at this time, the reminding tasks of the current minute newly added after the reading is finished will be lost. To this end, the server may individually start a set of threads for reading the reminder task with the creation time and the schedule time of the next minute, thereby avoiding the loss of the reminder task.
In other embodiments, when the number of the reminding tasks to be executed is large, the reminding tasks are further split, for example, a plurality of reminding tasks can be divided into different number segments according to the unique identification account number in an enterprise of the reminding tasks, meanwhile, in consideration of the mutual independence of the reminding tasks, a plurality of circular queues can be used, a plurality of threads are simultaneously started in the server to read the reminding tasks of different number segments, the read reminding tasks of different number segments are added into different circular queues, and each thread executes the reminding task in the corresponding circular queue.
Referring to fig. 9, fig. 9 is a schematic flowchart illustrating a reminding task executed by multiple threads in different number segments according to an embodiment of the present invention. As shown in fig. 9, after dividing a plurality of reminding tasks into N different number segments, the server correspondingly starts N threads to correspondingly execute the reminding tasks in the N different number segments (i.e., execute the reminding task in number segment 1 through thread 1, execute the reminding task in number segment 2 through thread 2, and so on), and adds corresponding thread locks to the N threads (i.e., thread 1 uses lock 1, thread 2 uses lock 2, and so on).
Taking thread 2 as an example, when thread 2 acquires lock 2, the reminding tasks divided into number segment 2 are read from a relational database management system (MySQL) or PKV in which the reminding tasks are stored, the read reminding tasks in number segment 2 are added into circular queue 2, and after all the reminding tasks in number segment 2 are added into circular queue 2, thread 2 sleeps for the next minute. The reminding task in the number section 2 can be obtained by setting a time range, a numerical range of the number section and the like and searching MySQL or PKV based on the leftmost matching principle, and when the reminding task of the number section 2 cannot be searched from MySQL or PKV, the thread 2 sleeps for 5 seconds.
Then, one of the reminding tasks stored in the circular queue 2 is sequentially taken out for execution, specifically, each time one reminding task is executed, one reminding task is removed from the head of the circular queue 2, whether the current circular queue 2 is an empty POP (that is, whether a reminding task to be executed still exists in the current circular queue 2) is judged, and when the current circular queue 2 is an empty POP, it is determined that all the reminding tasks in the circular queue 2 are completely executed.
The specific execution process of the reminding task may adopt asynchronous logic, that is, the reminding task to be executed is added into a Message Queue (MQ), and the Message Queue executes a specific logic processing process (that is, according to the specific content of the reminding task, a corresponding reminding Message is sent to a corresponding terminal at a set time point). After the reminding task is executed, the reminding task which is executed successfully needs to be deleted from the MyS QL or the PKV.
When the deletion fails, the reminding task which fails to delete is added into a retry queue opened by the server for re-deletion, for example, the server polls the retry queue by taking 1 second as a period, and when the reminding task which fails to delete exists in the retry queue, the reminding task which fails to delete is re-deleted.
It should be noted that the specific process of executing the reminder task by the thread 1 and the thread N is similar to the process of executing the thread 2, and the specific subsequent processes of executing the thread 1 and the thread N are not shown in fig. 9 for saving space.
The operation method of the reminding task provided by the embodiment of the invention can support the reminding service of various business support events, can provide more reliable reminding service, is more suitable for business, can enable more business to access the reminding service, and provides various reminding functions for users.
Embodiments of the present invention provide a computer-readable storage medium storing executable instructions, which when executed by a processor, will cause the processor to execute a method for running a reminder task provided by embodiments of the present invention, for example, the method for running a reminder task as shown in fig. 3 or 4.
In some embodiments, the storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EE PROM, flash, magnetic surface memory, optical disk, or CD-ROM; or may be various devices including one or any combination of the above memories.
In some embodiments, executable instructions may be written in any form of programming language (including compiled or interpreted languages), in the form of programs, software modules, scripts or code, and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
By way of example, executable instructions may correspond, but do not necessarily have to correspond, to files in a file system, and may be stored in a portion of a file that holds other programs or data, e.g., in one or more scripts in a hypertext Markup Language (HT ML) document, in a single file dedicated to the program in question, or in multiple coordinated files (e.g., files that store one or more modules, sub-programs, or portions of code).
By way of example, executable instructions may be deployed to be executed on one computing device or on multiple computing devices at one site or distributed across multiple sites and interconnected by a communication network.
In summary, the embodiment of the invention has the following beneficial effects:
the operation method of the reminding task provided by the embodiment of the invention can support the reminding service of various services, can provide more reliable reminding service, is more suitable for the services, can enable more services to be accessed into the reminding service, and provides various reminding functions for users.
The above description is only an example of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, and improvement made within the spirit and scope of the present invention are included in the protection scope of the present invention.
Claims (10)
1. The running method of the reminding task is applied to a distributed system, and the distributed system comprises a plurality of servers;
the method comprises the following steps:
the server receives a plurality of set reminding tasks and stores the reminding tasks according to the time intervals of the reminding time of the received reminding tasks;
setting a thread for executing the reminding task to be in a blocking state, and trying to acquire a distributed lock in the distributed system;
when the distributed lock is acquired, the thread in the blocking state is converted into an executable state, and a reminding task in the current time interval is executed through the thread so as to
Sending a reminding message corresponding to the executed reminding task;
and the current time interval is the time interval when the thread acquires the distributed lock.
2. The method according to claim 1, wherein the storing according to the time interval of the received reminding time of the reminding task comprises:
dividing each day into a plurality of time intervals according to set time granularity, and establishing a corresponding index table for each time interval;
and determining the time interval of the reminding time of the received reminding task in the divided time intervals, and storing the received reminding task in an index table corresponding to the determined time interval.
3. The method of claim 2, further comprising:
performing modular operation on a plurality of reminding tasks stored in any time interval in the index table according to the serial numbers of the reminding tasks;
and dividing the modulus operation result into a plurality of number segments according to the set granularity, and dividing the plurality of reminding tasks into corresponding number segments according to the numbers of the plurality of reminding tasks.
4. The method of claim 3, wherein executing, by the thread, the reminder task within the current time interval comprises:
adjusting the number of threads started in the server according to the number of the number segments in the current time interval so as to enable the number of the threads to be adjusted
Each thread reads the reminding task in one number segment and adds the read reminding task into the corresponding circular queue;
and aiming at any circular queue in the plurality of circular queues, executing the reminding task in any circular queue through a thread corresponding to any circular queue.
5. The method of claim 1, wherein executing, by the thread, a reminder task within a current time interval comprises:
executing a reminding service in the current time interval through the thread within the valid period of the distributed lock;
releasing the distributed lock when the validity period of the distributed lock is exceeded and re-converting the thread in the executable state to a blocking state.
6. The method of claim 1, wherein executing, by the thread, a reminder task within a current time interval comprises:
and adding the reminding tasks to be executed in the current time interval into a message queue in an asynchronous mode so as to send reminding messages corresponding to the executed reminding tasks through the message queue.
7. The method of claim 1, wherein executing, by the thread, a reminder task within a current time interval comprises:
when the number of the reminding tasks needing to be executed in the current time interval is larger than a preset threshold value, reading the reminding tasks needing to be executed in the current time interval through a task reading thread, storing the read reminding tasks in a memory container, and
and acquiring the reminding task to be executed from the memory container through a task execution thread and executing the reminding task.
8. The method of claim 7, further comprising:
after the reminding task needing to be executed in the current time interval is read, switching the reading task thread to a sleep state;
and starting a group of new reading task threads to read the reminding tasks needing to be executed in the next time interval when the time of the next time interval is up, wherein the number of the new reading task threads is the same as the number of the number segments in the next time interval.
9. The method according to any one of claims 1 to 8, further comprising:
when the reminding task fails to be executed, adding the reminding task which fails to be executed into a retry queue so as to be re-executed through the retry queue;
when the reminding task is successfully executed, deleting the reminding task which is successfully executed, and
and when the deletion fails, adding the reminding task with the deletion failure into the retry queue so as to delete the reminding task again through the retry queue.
10. The running device of the reminding task is applied to a distributed system, and the distributed system comprises a plurality of servers;
the device comprises:
the storage module is used for receiving the set reminding tasks and storing the reminding tasks according to the time intervals of the reminding time of the received reminding tasks;
the acquisition module is used for setting a thread for executing the reminding task to be in a blocking state and trying to acquire a distributed lock in the distributed system;
the execution module is used for converting the thread in the blocking state into an executable state when the distributed lock is acquired, and executing a reminding task in a current time interval through the thread, wherein the current time interval is the time interval in which the thread acquires the distributed lock;
and the sending module is used for sending the reminding message corresponding to the executed reminding task.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010484392.9A CN113760665B (en) | 2020-06-01 | 2020-06-01 | Operation method and device for reminding task |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010484392.9A CN113760665B (en) | 2020-06-01 | 2020-06-01 | Operation method and device for reminding task |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113760665A true CN113760665A (en) | 2021-12-07 |
CN113760665B CN113760665B (en) | 2024-05-07 |
Family
ID=78782506
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010484392.9A Active CN113760665B (en) | 2020-06-01 | 2020-06-01 | Operation method and device for reminding task |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113760665B (en) |
Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20070198978A1 (en) * | 2006-02-22 | 2007-08-23 | David Dice | Methods and apparatus to implement parallel transactions |
CN101464884A (en) * | 2008-12-31 | 2009-06-24 | 阿里巴巴集团控股有限公司 | Distributed task system and data processing method using the same |
CN101931553A (en) * | 2009-06-17 | 2010-12-29 | 智能技术Ulc公司 | Be used to manage the distributed system and the method for multi-user and multi-work space |
US20130182713A1 (en) * | 2012-01-18 | 2013-07-18 | LineRate Systems, Inc. | State management using a large hash table |
CN103581611A (en) * | 2013-11-19 | 2014-02-12 | 北京兆维电子(集团)有限责任公司 | Implementation method for audio and video recording based on routing server and routing server |
US20140310236A1 (en) * | 2013-04-15 | 2014-10-16 | International Business Machines Corporation | Out-of-Order Execution of Strictly-Ordered Transactional Workloads |
US20160277439A1 (en) * | 2015-03-20 | 2016-09-22 | Ncluud Corporation | Locking Applications and Devices Using Secure Out-of-Band Channels |
CN108965587A (en) * | 2018-06-26 | 2018-12-07 | 恒生电子股份有限公司 | A kind of message prompt method, device and equipment |
CN109582466A (en) * | 2017-09-29 | 2019-04-05 | 北京金山软件有限公司 | A kind of timed task executes method, distributed server cluster and electronic equipment |
US20190197496A1 (en) * | 2016-08-29 | 2019-06-27 | Alibaba Group Holding Limited | Task reminding method and apparatus for multiple information sources |
WO2019174129A1 (en) * | 2018-03-13 | 2019-09-19 | 平安科技(深圳)有限公司 | Event reminder method, apparatus, computer device, and storage medium |
-
2020
- 2020-06-01 CN CN202010484392.9A patent/CN113760665B/en active Active
Patent Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20070198978A1 (en) * | 2006-02-22 | 2007-08-23 | David Dice | Methods and apparatus to implement parallel transactions |
CN101464884A (en) * | 2008-12-31 | 2009-06-24 | 阿里巴巴集团控股有限公司 | Distributed task system and data processing method using the same |
CN101931553A (en) * | 2009-06-17 | 2010-12-29 | 智能技术Ulc公司 | Be used to manage the distributed system and the method for multi-user and multi-work space |
US20130182713A1 (en) * | 2012-01-18 | 2013-07-18 | LineRate Systems, Inc. | State management using a large hash table |
US20140310236A1 (en) * | 2013-04-15 | 2014-10-16 | International Business Machines Corporation | Out-of-Order Execution of Strictly-Ordered Transactional Workloads |
CN103581611A (en) * | 2013-11-19 | 2014-02-12 | 北京兆维电子(集团)有限责任公司 | Implementation method for audio and video recording based on routing server and routing server |
US20160277439A1 (en) * | 2015-03-20 | 2016-09-22 | Ncluud Corporation | Locking Applications and Devices Using Secure Out-of-Band Channels |
US20190197496A1 (en) * | 2016-08-29 | 2019-06-27 | Alibaba Group Holding Limited | Task reminding method and apparatus for multiple information sources |
CN109582466A (en) * | 2017-09-29 | 2019-04-05 | 北京金山软件有限公司 | A kind of timed task executes method, distributed server cluster and electronic equipment |
WO2019174129A1 (en) * | 2018-03-13 | 2019-09-19 | 平安科技(深圳)有限公司 | Event reminder method, apparatus, computer device, and storage medium |
CN108965587A (en) * | 2018-06-26 | 2018-12-07 | 恒生电子股份有限公司 | A kind of message prompt method, device and equipment |
Non-Patent Citations (3)
Title |
---|
KERO小柯: "分布式锁实现与分布式定时任务", pages 1 - 12, Retrieved from the Internet <URL:https://www.cnblogs.com/kesimin/p/11395995.html> * |
不眠不休不写BUG: "java程序员进阶:详解多线程之分布式锁及其实现方式", pages 1 - 8, Retrieved from the Internet <URL:https://zhuanlan.zhihu.com/p/94778220> * |
丘志杰: "分布式文件系统的研究——并发通信及网络互斥的设计与实现", 《中国优秀硕士学位论文全文数据库(电子期刊)》, 31 January 2005 (2005-01-31), pages 1 - 10 * |
Also Published As
Publication number | Publication date |
---|---|
CN113760665B (en) | 2024-05-07 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US9983957B2 (en) | Failover mechanism in a distributed computing system | |
ES2703901T3 (en) | Distributed file system through consensus nodes | |
US6990606B2 (en) | Cascading failover of a data management application for shared disk file systems in loosely coupled node clusters | |
US6823474B2 (en) | Method and system for providing cluster replicated checkpoint services | |
US10331625B2 (en) | Managing sequential data store | |
US9596301B2 (en) | Distributed-leader-election service for a distributed computer system | |
US7426653B2 (en) | Fault tolerant distributed lock management | |
US20080071878A1 (en) | Method and system for strong-leader election in a distributed computer system | |
CN112955874A (en) | System and method for self-healing in decentralized model building using machine learning of blockchains | |
CN113760513B (en) | Distributed task scheduling method, device, equipment and medium | |
WO2021104178A1 (en) | Dynamic message pushing method and system and vehicle diagnosis server | |
CN102724304A (en) | Information warehouse federation in subscription/release system and data synchronization method | |
CN108989391B (en) | Consistency processing method and system | |
CN114466027B (en) | Cloud primary database service providing method, system, equipment and medium | |
CN111177254B (en) | Method and device for data synchronization between heterogeneous relational databases | |
CN111045745A (en) | Method and system for managing configuration information | |
US20230110826A1 (en) | Log execution method and apparatus, computer device and storage medium | |
CN109347906B (en) | Data transmission method, device and server | |
CN113760665B (en) | Operation method and device for reminding task | |
US8230444B2 (en) | Global attribute uniqueness (GAU) using an ordered message service (OMS) | |
CN113515574B (en) | Data synchronization method and device | |
CN114780296A (en) | Data backup method, device and system for database cluster | |
CN115202925A (en) | Common identification method and system supporting fine-grained fault tolerance based on RDMA | |
Le Lann | Chapter 11 Synchronization | |
CN118051564B (en) | Quart-based distributed asynchronous data synchronization method |
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 |