CN108874513A - Handle method, system, electronic equipment and the computer-readable medium of timed task - Google Patents

Handle method, system, electronic equipment and the computer-readable medium of timed task Download PDF

Info

Publication number
CN108874513A
CN108874513A CN201710329377.5A CN201710329377A CN108874513A CN 108874513 A CN108874513 A CN 108874513A CN 201710329377 A CN201710329377 A CN 201710329377A CN 108874513 A CN108874513 A CN 108874513A
Authority
CN
China
Prior art keywords
timed task
server
priority query
sent
redis
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.)
Pending
Application number
CN201710329377.5A
Other languages
Chinese (zh)
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information 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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201710329377.5A priority Critical patent/CN108874513A/en
Publication of CN108874513A publication Critical patent/CN108874513A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR 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/54Interprogram communication
    • G06F9/546Message passing systems or structures, e.g. queues
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/48Indexing scheme relating to G06F9/48
    • G06F2209/484Precedence
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2209/00Indexing scheme relating to G06F9/00
    • G06F2209/54Indexing scheme relating to G06F9/54
    • G06F2209/548Queue

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer And Data Communications (AREA)

Abstract

The present invention provides a kind of method, system, electronic equipment and computer-readable medium for handling timed task, it does not need every data in scanning MySQL table, but the processing to timed task is realized using the Zset priority query including key, score, value of Redis database, the data of first position of scan queue are only needed every time.And separate the end Server and the end Worker, make their asynchronous executions, to improve reliability, success rate and the retractility of timed task processing.This method includes:Engineering worker has been added to the timed task in the priority query of Redis according to predeterminated frequency scanning, and the timed task for meeting default execution condition is sent to server by message queue, so that server executes the timed task.

Description

Handle method, system, electronic equipment and the computer-readable medium of timed task
Technical field
The present invention relates to computer fields, more particularly to method, system, electronic equipment and the calculating of processing timed task Machine readable medium.
Background technique
In the prior art, processing timed task is carried out by periodically scanning MySQL table, in the method, is needed Scan every data in MySQL table, judge timestamp, efficiency in this way it is very low;And pass through timing Worker constantly inquires database, also big to the pressure of MySQL, and availability is not high;In addition, in the prior art, the end Server and The end Worker is synchronous to be executed, and there is also detrimental effects for the efficiency of processing timed task for this.
Summary of the invention
In view of this, the embodiment of the present invention provides a kind of method, system, electronic equipment and computer for handling timed task Readable medium, do not need scanning MySQL table in every data, but utilize Redis database include key, score, The Zset priority query of value realizes the processing to timed task, only needs first position of scan queue every time Data.And separate the end Server (server end) with the end Worker, make their asynchronous executions, to improve timed task Reliability, success rate and the retractility of processing.
According to an aspect of an embodiment of the present invention, a kind of method based on priority query's processing timed task is provided.
A kind of method of processing timed task of the embodiment of the present invention includes:Engineering worker is scanned according to predeterminated frequency The timed task for meeting default execution condition is passed through message queue by the timed task being added in the priority query of Redis It is sent to server, so that server executes the timed task.
Optionally, the priority query be the Zset ordered set based on Redis, timed task with key, value with And the form of score, foundation score sequence are stored in sorted order in the priority query, wherein with timed task queue class Type as key, using the particular content of timed task as value, using the timestamp of timed task as score.
Optionally, the timed task for meeting default execution condition is sent to server by message queue includes:Scanning Whether the priority query, judgement are located at the timestamp of the timed task of queue first place earlier than current time, if earlier than, Timed tasks earlier than current time all in the priority query are sent to server by message queue, are otherwise refused It sends.
Optionally, after the timed task for meeting default execution condition is sent to server by message queue, institute The method of stating further includes:The default execution condition of meeting of server will be sent in the priority query by message queue Timed task is deleted.
Optionally, the method also includes:Timed task in the priority query for having been added to Redis, is adding While being added in the priority query, it is stored in MySQL together.
Optionally, the method also includes:Timed task in the priority query for having been added to Redis, is adding While being added in the priority query, being together that each timed task setting is default in Redis retries threshold value, to work as State timed task retry number of processing be more than it is default retry threshold value after, the timed task is permanent from priority query It deletes.
Optionally, in the method, server distribution formula, load balancing the timed task is executed.
According to another aspect of an embodiment of the present invention, the method for another processing timed task is provided.
A kind of method of processing timed task of the embodiment of the present invention includes:Server receives engineering worker and passes through message What queue was sent meets the timed task of default execution condition, wherein the timed task utilizes the priority based on Redis Queue is stored;Execute the timed task.
Optionally, the priority query be the Zset ordered set based on Redis, timed task with key, value with And the form of score, foundation score sequence are stored in sorted order in the priority query, wherein with timed task queue class Type as key, using the particular content of timed task as value, using the timestamp of timed task as score.
Optionally, engineering worker includes by the timed task for meeting default execution condition that message queue is sent: Engineering worker scans the priority query according to predeterminated frequency, judges the timestamp of the timed task positioned at queue first place Earlier than current time after, by message queue selection be sent to it is all earlier than current in the priority query of server The timed task of time.
Optionally, engineering worker is received in server meet determining for default execution condition by what message queue was sent When task after, the method also includes:Engineering worker will be sent to clothes by message queue in the priority query The timed task for meeting default execution condition of business device is deleted.
Optionally, the method also includes:The timed task using the priority query based on Redis in addition to being deposited Other than storage, also made a backup store using MySQL.
Optionally, the method also includes:The timed task using the priority query based on Redis in addition to being deposited Promising each the default of timed task setting is also stored other than storage, in Redis retries threshold value.
Optionally, in the method, server distribution formula, load balancing the timed task is executed.
Optionally, the method also includes:If server executes the timed task failure, by the timed task weight Newly it is added in priority query, carries out retrying processing, it, will be described fixed if retrying number of processing is more than to preset to retry threshold value When task permanent delet from the priority query.
Optionally, engineering worker is received in server meet determining for default execution condition by what message queue was sent When task after, the method also includes:Server will fail to hold in time according to the current the upper limit of the number N for executing timed task Capable timed task is added in waiting list, is completed and then when currently performed N number of timed task executes according to FIFO Principle select being executed no more than N number of timed task in the waiting list.
According to another aspect of an embodiment of the present invention, a kind of system based on priority query's processing timed task is provided.
A kind of system of processing timed task of the embodiment of the present invention, including:Client, engineering worker and service Device, wherein:Client is for timed task to be added in the priority query of Redis;Engineering worker is used for according to default Frequency scanning has been added to the timed task in the priority query of Redis, and the timed task that will meet default execution condition Server is sent to by message queue;Server is used to receive engineering worker default by meeting of sending of message queue The timed task of execution condition, and execute the timed task.
In accordance with a further aspect of the present invention, a kind of electronic equipment terminal is provided, including:One or more processors;With In the storage device for storing one or more programs, when one or more of programs are held by one or more of processors Row, so that the method that one or more of processors realize provided processing timed task according to the present invention.
In accordance with a further aspect of the present invention, a kind of computer-readable medium is provided, computer program is stored thereon with, institute State the method that processing timed task provided by the present invention is realized when program is executed by processor.
One embodiment in foregoing invention has the following advantages that or beneficial effect:Because being stored in using by timed task Technological means in priority query, so overcoming the efficiency for needing every data in scan database to judge timestamp Low technical problem, and then reach the technical effect for improving timed task scan efficiency;Because using according to predeterminated frequency Timed task is scanned, and the timed task for meeting default execution condition is sent to the technology hand of server end by message queue Section, it is synchronous so as to the process that avoids scan data table from handling with task, cause task dispatching to wait for, the technology that is unfavorable for extending is asked Topic, to reach the end worker and server end separation, non-obstruction, the technical effect for handling to asynchronization timed task;Cause Method to use distributed, load balancing the execution timed task of server-side, so as to realize the height of timed task processing Availability, the performance that task is handled are scalable;Abnormal retry mechanism is handled by utilizing, so as to improve timed task The reliability of processing ensures the performance of processing while guaranteeing the success rate of processing;By engineering worker by the priority It is deleted by the timed task for meeting default execution condition that message queue is sent to server in queue, so as to It prevents the timed task of processing overweight, avoids the timed task when the arrival of next sweep time of engineering woker and do not handle also Completion can iterate through the drawbacks of message queue sends task;By being timed task backup storage using MySQL, so as to To ensure when Redis delay machine, task recovery can be carried out from MySQL;By executing timing times according to current on the server The upper limit of the number N of business maintains a waiting list, the timed task for failing to execute in time is added in waiting list, so as to While to guarantee High Availabitity, the process performance of server is ensured.
Further effect possessed by above-mentioned non-usual optional way adds hereinafter in conjunction with specific embodiment With explanation.
Detailed description of the invention
Fig. 1 is that the embodiment of the present invention can be applied to exemplary system architecture figure therein;
Fig. 2 is a kind of schematic diagram of the key step of method for handling timed task according to an embodiment of the present invention;
Fig. 3 is the schematic diagram of the key step of the method for another processing timed task according to an embodiment of the present invention;
Fig. 4 is the timestamp of timed task in the method for processing timed task according to an embodiment of the present invention;
Fig. 5 is the flow chart of the method for processing timed task according to an embodiment of the present invention;
Fig. 6 is the schematic diagram of the major part of the system of processing timed task according to an embodiment of the present invention;With
Fig. 7 is adapted for the structural representation of the computer system for the terminal device or server of realizing the embodiment of the present invention Figure.
Specific embodiment
Present invention is further described in detail in the following with reference to the drawings and specific embodiments, but not as to limit of the invention It is fixed.
Fig. 1 is shown can be using the method for the processing timed task of the embodiment of the present invention or the device of processing timed task Exemplary system architecture 100.
As shown in Figure 1, system architecture 100 may include terminal device 101,102,103, network 104 and server 105. Network 104 between terminal device 101,102,103 and server 105 to provide the medium of communication link.Network 104 can be with Including various connection types, such as wired, wireless communication link or fiber optic cables etc..
User can be used terminal device 101,102,103 and be interacted by network 104 with server 105, to receive or send out Send message etc..Various telecommunication customer end applications, such as the application of shopping class, net can be installed on terminal device 101,102,103 (merely illustrative) such as the application of page browsing device, searching class application, instant messaging tools, mailbox client, social platform softwares.
Terminal device 101,102,103 can be the various electronic equipments with display screen and supported web page browsing, packet Include but be not limited to smart phone, tablet computer, pocket computer on knee and desktop computer etc..
Server 105 can be to provide the server of various services, such as utilize terminal device 101,102,103 to user The shopping class website browsed provides the back-stage management server (merely illustrative) supported.Back-stage management server can be to reception To the data such as information query request analyze etc. processing, and by processing result (such as target push information, product letter Breath -- merely illustrative) feed back to terminal device.
It should be noted that the method for processing timed task provided by the embodiment of the present invention is generally held by server 105 Row, correspondingly, the device for handling timed task is generally positioned in server 105.
It should be understood that the number of terminal device, network and server in Fig. 1 is only schematical.According to realization need It wants, can have any number of terminal device, network and server.
It is the explanation of several technical terms involved in the embodiment of the present invention below:
Redis:It is an open source (BSD license), memory storage data structure server, can be used as database, it is high Speed caching and message queue agency.It supports character string, Hash table, list, set, ordered set, bitmap, hyperloglogs Etc. data types.Built-in duplication, Lua script, LRU withdrawal, affairs and different stage disk persistence function, pass through simultaneously Redis Sentinel provides High Availabitity, provides auto-partition by Redis Cluster;
Worker:It is a kind of service type engineering, is timed in the embodiment of the present invention using it and scans Zset;
MQ:Message queue realizes non-obstruction framework for realizing the communication at the end worker and Server, improves reliability;
Zset:Essence is a kind of data structure stored in Redis, is an ordered set, is used as in the present invention excellent First grade queue, by key, score, value three parts composition sorts according to the score value of each Zset, and worker only needs to sweep Retouch the data of queue front.Zset is a upgraded version of Set data structure in Redis, it is increased on the basis of Set One sequential attribute, this attribute can specify when element is modified in addition, and after specifying every time, Zset can be pressed again automatically New value adjustment sequence.The setting of weight can be ranked up to the value of assignment key, it is relatively more using ranking module.Zset collection Conjunction can complete the case where orderly executing, execute according to priority.
Fig. 2 is a kind of schematic diagram of the key step of method for handling timed task according to an embodiment of the present invention.
As shown in Fig. 2, a kind of method of processing timed task of the embodiment of the present invention mainly includes the following steps:
Step S201:Engineering worker has been added to the timing in the priority query of Redis according to predeterminated frequency scanning The timed task for meeting default execution condition is sent to server by message queue by task, for described in server execution Timed task.
In the embodiment of the present invention, priority query can be the Zset ordered set based on Redis, in Zset priority team In column, timed task is stored in sorted order in the form of key, value and score, according to score sequence in the priority team In column, wherein using timed task queue type as key, using the particular content of timed task as value, with timed task Timestamp as score.
In abovementioned steps, the timed task for meeting default execution condition is sent to server by message queue and mainly may be used To include:Scan the priority query, judgement be located at the timed task of queue first place timestamp whether earlier than it is current when Between, if earlier than the timed tasks earlier than current time all in the priority query are sent to clothes by message queue Business device, otherwise not sends.
In addition, after the timed task for meeting default execution condition is sent to server by message queue, this hair The method of the processing timed task of bright embodiment can also include:It will be sent to by message queue in the priority query The timed task for meeting default execution condition of server is deleted.
In addition, the timed task in the priority query of Redis is had been added to, in being added to the priority query At the same time it can also be stored in MySQL together, can also together be that each timed task setting is default in Redis retries threshold value, with The box lunch timed task retry number of processing be more than it is default retry threshold value after, by the timed task from priority query Middle permanent delet.
In the embodiment of the present invention, server carries out distribution, executes to load balancing the timed task, in order to effective Ground dilatation.
Fig. 3 is the schematic diagram of the key step of the method for another processing timed task according to an embodiment of the present invention.
As shown in figure 3, the method for another processing timed task of the embodiment of the present invention mainly includes the following steps:
Step S301 server receives engineering worker and meets determining for default execution condition by what message queue was sent When task, wherein the timed task is stored using the priority query based on Redis.
Step S302:Execute the timed task.
Wherein, engineering worker is mainly wrapped by the timed task for meeting default execution condition that message queue is sent It includes:Engineering worker scans the priority query according to predeterminated frequency, judge the timed task positioned at queue first place when Between stab earlier than current time after, by message queue selection be sent in the priority query of server it is all earlier than The timed task of current time.
In this method, server distribution formula, load balancing the timed task is executed.
In addition, the timed task can be re-added to preferentially if server executes the timed task failure Grade queue in, carry out retrying processing, if retry number of processing be more than preset retry threshold value (can previously according to actual conditions and It is fixed, such as be set as 3 times), then by the timed task from the priority query permanent delet.
In addition, receiving the timing for meeting default execution condition that engineering worker is sent by message queue in server After task, the method for the processing timed task of the embodiment of the present invention can also include:Server executes timing times according to current The upper limit of the number N of business, the timed task for failing to execute in time is added in waiting list, when currently performed N number of timing Task execution is completed and then selects to carry out in the waiting list no more than N number of timed task according to the principle of FIFO It executes.
Fig. 4 is the timestamp of timed task in the method for processing timed task according to an embodiment of the present invention;Fig. 5 is basis The flow chart of the method for the processing timed task of the embodiment of the present invention.Fig. 6 is processing timed task according to an embodiment of the present invention System major part schematic diagram.
In the embodiment of the present invention, mainly solve the problems, such as follows:1, without the data of each of table in scan database, Make the pressure of paired data library table, but the number for only needing first position of scan queue every time is realized in use priority queue According to;2, the process for solving scan table is synchronous with the process that timed task is handled, caused by frequent timed task waiting it is also unfavorable In the extension the problem of, so that the end worker is separated with the end Server, asynchronization processing improves reliability and success rate, so that locating The mechanism for managing timed task is scalable.
As shown in fig. 6, being for realizing the processing timed task of the method for processing timed task in the embodiment of the present invention System 600 mainly includes following part:Client 601, engineering worker602 and server 603, wherein:
Client 601 is for timed task to be added in the priority query of Redis;Engineering worker602 is for pressing The timed task in the priority query of Redis is had been added to according to predeterminated frequency scanning, and determining for default execution condition will be met When task server 603 is sent to by message queue;Server 603 is sent for receiving engineering worker by message queue That comes meets the timed task of default execution condition, and executes the timed task.
Below in conjunction with Fig. 4, Fig. 5 and Fig. 6, the process of the method for the processing timed task of the embodiment of the present invention is carried out detailed It describes in detail bright.Specifically, the complete technical solution of the processing timed task of the embodiment of the present invention is from client (end Client), work Journey worker, server (end Server) are illustrated.
Client (end Client):
The groundwork at the end Client is the addition and deletion to timed task, adds one to Zset when the end Client and determines When task when, the key in Zset is used to indicate that store herein is that timed task queue (has inside this queue and all determines When mission bit stream), be for distinguishing other key in Redis, the score in Zset houses the time of this timed task Information, i.e. timestamp, and value storage is the relevant processing information of timed task.The number of timed task in priority query It anticipates as shown in the table according to structure:
It should be noted that writing a conduct into MySQL table together while timed task is stored in priority query Calamity is standby, in this way, when Redis hangs, it can be from wherein restoring timed task.The deletion of timed task is also same process.
worker:
When timed task is constantly stored in Zset by the end Client, Zset can be inserted it into according to score Corresponding position, worker only need to judge the timed task of queue first place, because being located at the subsequent timed task of queue Timestamp be all be later than queue first place.For the efficiency of scanning, can be, but not limited to set 1 for the scan frequency of worker Minute is primary.
In the embodiment of the present invention, when worker is scanned, whether the score value i.e. timestamp of queue first place data is judged Through before current time, if it is just can trigger pipeline Pipeline processing, worker can be by all earlier than current time Timed task in Zset is sent to the processing of the end Server by message queue MQ;After MQ is sent, worker can be deleted immediately Fall the data in Zset, deletion movement is deleted again after the completion of not being placed on the timed task of the end Server processing, is to be based on preventing The overweight consideration of the timed task of processing.Because when next sweep time of woker, which stabs, to arrive, if timed task is not handled also It completes, will repeat to send MQ.Timed task delete after whether it is processed at mechanism can pass through the end Server below Abnormality processing and retry mechanism are come perfect.
The end Server:
The end woker has sent MQ, and the end Server is next just needed to execute timed task.If all timed tasks are all It is assigned on the same Server, other business of Server may be impacted, when concurrently very high, if load is uneven Even, it is big to will cause a certain server stress, may break down this server, therefore, here by MQ by timed task It is distributed on different server, realizes load balancing.
Specifically, realize load balancing logic utilize as follows Broker (Broker is the transfer mechanism of a message, It is equivalent to a kind of server), thereon it is believed that there are a kind of queue for storing message, worker scans a series of timings come Task can will be pushed to Broker in form of a message by MQ, and the message queue of Broker (can be loaded with certain strategy Balance policy, such as random algorithm, polling algorithm) by these message it is balanced be distributed to it is different execute timed task The end Server.
In addition, a waiting list can be maintained on each Server, when the timed task of a certain Server processing Reach the upper limit when, behind distribute come timed task can be added in this waiting list.Using fifo fifo Principle (can be indicated, N is the positive integer greater than 0, can basis when Server has handled certain predetermined upper limit quantity with N herein Depending on the actual treatment ability of Server) timed task after, N number of timed task in queue can be put into Server holds again Row processing.
In the embodiment of the present invention, the end Server is also provided with exception and retry mechanism.As previously described, because the end worker is sent out The timed task data in Zset will be deleted after sending MQ, not ensure that whether subsequent timed task runs succeeded.Therefore, After timed task, which executes, to fail, the end Server can be rejoined this timed task in Zset and MySQL table, pass through Worker triggering, allows timed task to retry.Certainly, for the performance of safeguards system, unnecessary waist performance, Mei Geding are avoided When task the limitation of one number of retries can be set.Number of retries limits herein, i.e., the default threshold value that retries is when client is past When a timed task being added in Zset, client can create that a timed task is corresponding to retry key in Redis, be used for All Server for executing timed task share this and retry key, specifically, this retries key to store number of retries, save In Redis.Each Server can do atom when executing current timed task and reduce, after number of retries is finished, regardless of timing The success or failure of task processing, permanent can all delete this timed task data from Zset.It is retried in Redis secondary Several data structures are anticipated as shown in the table:
Timed task 1+ is retried Number of retries
Timed task 2+ is retried Number of retries
Timed task 3+ is retried Number of retries
The method of processing timed task according to an embodiment of the present invention, because being stored in priority team using by timed task Technological means in column, so overcoming the skill for needing every data in scan database to judge the inefficiency of timestamp Art problem, and then reach the technical effect for improving timed task scan efficiency;Timing is scanned according to predeterminated frequency because using Task, and the timed task for meeting default execution condition is sent to the technological means of server end by message queue, thus Can be synchronous with the process that task is handled to avoid scan data table, it causes task dispatching to wait for, be unfavorable for the technical issues of extension, thus The end worker and server end separation, non-obstruction, the technical effect for handling to asynchronization timed task are reached;Because using clothes The method of the execution timed task for the end distribution, load balancing of being engaged in, so as to realize the high availability of timed task processing, make The performance of the task of obtaining processing is scalable;It, can so as to improve timed task processing by using handling abnormal retry mechanism The performance of processing is ensured while guaranteeing the success rate of processing by property;By engineering worker by the priority query It is deleted by the timed task for meeting default execution condition that message queue is sent to server, so as to prevent from handling Timed task it is overweight, avoid when engineering woker next sweep time arrival when timed task also no processing complete can not weigh The drawbacks of task is sent by message queue again;By being timed task backup storage using MySQL, work as so as to ensure When Redis delay machine, task recovery can be carried out from MySQL;By on the server according to the current quantity for executing timed task Upper limit N maintains a waiting list, the timed task for failing to execute in time is added in waiting list, thereby may be ensured that height While can using, the process performance of server is ensured.
Below with reference to Fig. 7, it illustrates the computer systems 700 for the terminal device for being suitable for being used to realize the embodiment of the present invention Structural schematic diagram.Terminal device shown in Fig. 7 is only an example, function to the embodiment of the present invention and should not use model Shroud carrys out any restrictions.
As shown in fig. 7, computer system 700 includes central processing unit (CPU) 701, it can be read-only according to being stored in Program in memory (ROM) 702 or be loaded into the program in random access storage device (RAM) 703 from storage section 708 and Execute various movements appropriate and processing.In RAM 703, also it is stored with system 700 and operates required various programs and data. CPU 701, ROM 702 and RAM 703 are connected with each other by bus 704.Input/output (I/O) interface 705 is also connected to always Line 704.
I/O interface 705 is connected to lower component:Importation 706 including keyboard, mouse etc.;It is penetrated including such as cathode The output par, c 707 of spool (CRT), liquid crystal display (LCD) etc. and loudspeaker etc.;Storage section 708 including hard disk etc.; And the communications portion 709 of the network interface card including LAN card, modem etc..Communications portion 709 via such as because The network of spy's net executes communication process.Driver 710 is also connected to I/O interface 705 as needed.Detachable media 711, such as Disk, CD, magneto-optic disk, semiconductor memory etc. are mounted on as needed on driver 710, in order to read from thereon Computer program be mounted into storage section 708 as needed.
Particularly, disclosed embodiment, the process described above with reference to flow chart may be implemented as counting according to the present invention Calculation machine software program.For example, embodiment disclosed by the invention includes a kind of computer program product comprising be carried on computer Computer program on readable medium, the computer program include the program code for method shown in execution flow chart.? In such embodiment, which can be downloaded and installed from network by communications portion 709, and/or from can Medium 711 is dismantled to be mounted.When the computer program is executed by central processing unit (CPU) 701, system of the invention is executed The above-mentioned function of middle restriction.
It should be noted that computer-readable medium shown in the present invention can be computer-readable signal media or meter Calculation machine readable storage medium storing program for executing either the two any combination.Computer readable storage medium for example can be --- but not Be limited to --- electricity, magnetic, optical, electromagnetic, infrared ray or semiconductor system, device or device, or any above combination.Meter The more specific example of calculation machine readable storage medium storing program for executing can include but is not limited to:Electrical connection with one or more conducting wires, just Taking formula computer disk, hard disk, random access storage device (RAM), read-only memory (ROM), erasable type may be programmed read-only storage Device (EPROM or flash memory), optical fiber, portable compact disc read-only memory (CD-ROM), light storage device, magnetic memory device, Or above-mentioned any appropriate combination.In the present invention, computer readable storage medium can be it is any include or storage journey The tangible medium of sequence, the program can be commanded execution system, device or device use or in connection.And at this In invention, computer-readable signal media may include in a base band or as carrier wave a part propagate data-signal, Wherein carry computer-readable program code.The data-signal of this propagation can take various forms, including but unlimited In electromagnetic signal, optical signal or above-mentioned any appropriate combination.Computer-readable signal media can also be that computer can Any computer-readable medium other than storage medium is read, which can send, propagates or transmit and be used for By the use of instruction execution system, device or device or program in connection.Include on computer-readable medium Program code can transmit with any suitable medium, including but not limited to:Wirelessly, electric wire, optical cable, RF etc. or above-mentioned Any appropriate combination.
Flow chart and block diagram in attached drawing are illustrated according to the system of various embodiments of the invention, method and computer journey The architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generation A part of one module, program segment or code of table, a part of above-mentioned module, program segment or code include one or more Executable instruction for implementing the specified logical function.It should also be noted that in some implementations as replacements, institute in box The function of mark can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are practical On can be basically executed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.Also it wants It is noted that the combination of each box in block diagram or flow chart and the box in block diagram or flow chart, can use and execute rule The dedicated hardware based systems of fixed functions or operations is realized, or can use the group of specialized hardware and computer instruction It closes to realize.
As on the other hand, the present invention also provides a kind of computer-readable medium, which be can be Included in equipment described in above-described embodiment;It is also possible to individualism, and without in the supplying equipment.Above-mentioned calculating Machine readable medium carries one or more program, when said one or multiple programs are executed by the equipment, makes Obtaining the equipment includes:The timed task in the priority query of Redis is had been added to according to predeterminated frequency scanning, it is default by meeting The timed task of execution condition is sent to server by message queue, so that server executes the timed task.
Technical solution according to an embodiment of the present invention does not need every data in scanning MySQL table, but utilizes The Zset priority query including key, score, value of Redis database realizes the processing to timed task, every time only Need the data of first position of scan queue.And separate the end Server and the end Worker, make their asynchronous executions, from And improve reliability, success rate and the retractility of timed task processing.
Method provided by the embodiment of the present invention can be performed in the said goods, has the corresponding functional module of execution method and has Beneficial effect.The not technical detail of detailed description in the present embodiment, reference can be made to method provided by the embodiment of the present invention.
Although the embodiment of the present invention is described in detail in conjunction with attached drawing, embodiment is only used for the explanation and illustration present invention, Rather than for limiting the present invention.The scope of the present invention is defined by the claims, change, replacement of some of them element etc. It is obvious.

Claims (19)

1. a kind of method for handling timed task, which is characterized in that including:
Engineering worker has been added to the timed task in the priority query of Redis according to predeterminated frequency scanning, will meet pre- If the timed task of the condition of execution is sent to server by message queue, so that server executes the timed task.
2. the method according to claim 1, wherein the priority query is that the Zset based on Redis is orderly Set, timed task are stored in sorted order in the form of key, value and score, according to score sequence in the priority team In column, wherein using timed task queue type as key, using the particular content of timed task as value, with timed task Timestamp as score.
3. the method according to claim 1, wherein the timed task for meeting default execution condition is passed through message Queue is sent to server:
Scanning the priority query, whether judgement is located at the timestamp of the timed task of queue first place earlier than current time, If earlier than the timed tasks earlier than current time all in the priority query are sent to service by message queue Otherwise device is not sent.
4. the method according to claim 1, wherein in the timed task by default execution condition is met by disappearing Breath queue is sent to after server, the method also includes:
The timed task for meeting default execution condition of server will be sent in the priority query by message queue It is deleted.
5. the method according to claim 1, wherein the method also includes:It is described to have been added to the excellent of Redis Timed task in first grade queue is stored in MySQL together while being added in the priority query.
6. the method according to claim 1, wherein the method also includes:It is described to have been added to the excellent of Redis Timed task in first grade queue is each timed task in Redis while being added in the priority query together Setting is default to retry threshold value, so as to when the timed task retry number of processing be more than it is default retry threshold value after, will described in Timed task permanent delet from priority query.
7. the method according to claim 1, wherein being held to server distribution formula, load balancing in the method The row timed task.
8. a kind of method for handling timed task, which is characterized in that including:
Server receives the timed task for meeting default execution condition that engineering worker is sent by message queue, wherein The timed task is stored using the priority query based on Redis;
Execute the timed task.
9. according to the method described in claim 8, it is characterized in that, the priority query is that the Zset based on Redis is orderly Set, timed task are stored in sorted order in the form of key, value and score, according to score sequence in the priority team In column, wherein using timed task queue type as key, using the particular content of timed task as value, with timed task Timestamp as score.
10. according to the method described in claim 8, it is characterized in that, engineering worker is met by what message queue was sent The timed task of default execution condition includes:
Engineering worker scans the priority query according to predeterminated frequency, judge the timed task positioned at queue first place when Between stab earlier than current time after, by message queue selection be sent in the priority query of server it is all earlier than The timed task of current time.
11. according to the method described in claim 8, it is characterized in that, receiving engineering worker in server passes through message queue After the timed task for meeting default execution condition sent, the method also includes:
Engineering worker will meet default execution condition by what message queue was sent to server in the priority query Timed task deleted.
12. according to the method described in claim 8, it is characterized in that, the method also includes:The timed task is in addition to utilizing Other than priority query based on Redis is stored, also made a backup store using MySQL.
13. according to the method described in claim 8, it is characterized in that, the method also includes:The timed task is in addition to utilizing Promising each the default of timed task setting is also stored other than priority query based on Redis is stored, in Redis retries threshold Value.
14. according to the method described in claim 8, it is characterized in that, in the method, server distribution formula, load balancing Execute the timed task.
15. according to the method for claim 13, which is characterized in that the method also includes:
If server executes the timed task failure, the timed task is re-added in priority query, is carried out Processing is retried, if retrying number of processing is more than to preset to retry threshold value, by the timed task from the priority query Permanent delet.
16. according to the method described in claim 8, it is characterized in that, receiving engineering worker in server passes through message queue After the timed task for meeting default execution condition sent, the method also includes:
The timed task for failing to execute in time is added to waiting according to the current the upper limit of the number N for executing timed task by server In queue, complete and then when currently performed N number of timed task executes according to the principle of the FIFO selection waiting list In executed no more than N number of timed task.
17. a kind of system for handling timed task, including:Client, engineering worker and server, wherein:
Client is for timed task to be added in the priority query of Redis;
Engineering worker is used for the timed task being had been added in the priority query of Redis according to predeterminated frequency scanning, and will The timed task for meeting default execution condition is sent to server by message queue;
Server is used to receive the timed task for meeting default execution condition that engineering worker is sent by message queue, and Execute the timed task.
18. a kind of electronic equipment terminal, which is characterized in that including:
One or more processors;
Storage device, for storing one or more programs,
When one or more of programs are executed by one or more of processors, so that one or more of processors are real The now method as described in any in claim 1-16.
19. a kind of computer-readable medium, is stored thereon with computer program, which is characterized in that described program is held by processor The method as described in any in claim 1-16 is realized when row.
CN201710329377.5A 2017-05-11 2017-05-11 Handle method, system, electronic equipment and the computer-readable medium of timed task Pending CN108874513A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710329377.5A CN108874513A (en) 2017-05-11 2017-05-11 Handle method, system, electronic equipment and the computer-readable medium of timed task

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710329377.5A CN108874513A (en) 2017-05-11 2017-05-11 Handle method, system, electronic equipment and the computer-readable medium of timed task

Publications (1)

Publication Number Publication Date
CN108874513A true CN108874513A (en) 2018-11-23

Family

ID=64319489

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710329377.5A Pending CN108874513A (en) 2017-05-11 2017-05-11 Handle method, system, electronic equipment and the computer-readable medium of timed task

Country Status (1)

Country Link
CN (1) CN108874513A (en)

Cited By (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109597699A (en) * 2018-11-28 2019-04-09 泰康保险集团股份有限公司 Data processing method, device, electronic equipment and computer-readable medium
CN109800068A (en) * 2018-12-20 2019-05-24 航天信息股份有限公司 Handle method, system, primary server and the timed task server of timed task
CN110413384A (en) * 2019-06-25 2019-11-05 腾讯科技(深圳)有限公司 Delayed tasks processing method and processing device, storage medium, electronic equipment
CN110609758A (en) * 2019-08-30 2019-12-24 恒大智慧科技有限公司 Queue-based device operating method, computer device and readable storage medium
CN110990132A (en) * 2019-11-01 2020-04-10 浙江大搜车软件技术有限公司 Asynchronous task processing method and device, computer equipment and storage medium
CN111078383A (en) * 2019-12-24 2020-04-28 浙江诺诺网络科技有限公司 Timed task management method, device, equipment and storage medium
CN111309496A (en) * 2020-02-10 2020-06-19 北京无限光场科技有限公司 Method, system, device, equipment and storage medium for realizing delay task
CN111611059A (en) * 2020-05-21 2020-09-01 安徽兆尹信息科技股份有限公司 Redis pipeline communication method for financial asset management system
CN112596882A (en) * 2020-12-25 2021-04-02 上海悦易网络信息技术有限公司 Method, device and system for scheduling delayed tasks
CN113806046A (en) * 2021-09-15 2021-12-17 武汉虹信技术服务有限责任公司 Task scheduling system based on thread pool
CN115658278A (en) * 2022-12-07 2023-01-31 中国电子科技集团公司第三十研究所 Micro task scheduling machine supporting high concurrency protocol interaction

Citations (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005202976A (en) * 2005-02-15 2005-07-28 Mitsubishi Electric Corp Electronic apparatus
CN1828541A (en) * 2006-04-07 2006-09-06 浙江大学 Implementation method for timing task in Java operating system
CN102904746A (en) * 2012-09-13 2013-01-30 曙光信息产业(北京)有限公司 Cluster task self-dispatching system and method based on information mechanism
CN103092932A (en) * 2013-01-06 2013-05-08 潘旻琦 Distributed document transcoding system
CN103345423A (en) * 2013-07-03 2013-10-09 北京京东尚科信息技术有限公司 Method and system for processing asynchronous task
CN103475687A (en) * 2013-05-24 2013-12-25 北京网秦天下科技有限公司 Distributed method and distributed system for downloading website data
CN103475688A (en) * 2013-05-24 2013-12-25 北京网秦天下科技有限公司 Distributed method and distributed system for downloading website data
CN103793273A (en) * 2014-01-24 2014-05-14 北京京东尚科信息技术有限公司 Distributed type queue scheduling method and device based on Redis
WO2015061976A1 (en) * 2013-10-30 2015-05-07 Nokia Technologies Oy Methods and apparatus for task management in a mobile cloud computing environment
CN104935658A (en) * 2015-06-17 2015-09-23 交通银行股份有限公司 Bank task allocation method and device
CN105204933A (en) * 2015-09-18 2015-12-30 上海斐讯数据通信技术有限公司 Multitask switching execution method based on single process, multitask switching execution system based on single process and processor
CN105512244A (en) * 2015-11-30 2016-04-20 北京京东尚科信息技术有限公司 Database transaction processing method and device based on message queue
CN105528186A (en) * 2015-12-02 2016-04-27 北京京东尚科信息技术有限公司 Method and apparatus for printing tag data by mobile terminal
CN105719182A (en) * 2016-01-18 2016-06-29 北京京东尚科信息技术有限公司 Automatic account checking method and automatic account checking system
CN105760221A (en) * 2016-02-02 2016-07-13 中博信息技术研究院有限公司 Task dispatching system with distributed calculating frame
CN105786629A (en) * 2016-02-02 2016-07-20 四川长虹电器股份有限公司 Data processing method based on message queue
US9405602B1 (en) * 2012-06-25 2016-08-02 Google Inc. Method for application notification and tasking
CN105868033A (en) * 2016-04-06 2016-08-17 江苏物联网研究发展中心 Method and system for achieving priority message queues based on Redis
CN105915633A (en) * 2016-06-02 2016-08-31 北京百度网讯科技有限公司 Automated operational system and method thereof
CN106201694A (en) * 2016-07-13 2016-12-07 北京农信互联科技有限公司 Configuration method and system for executing timing task under distributed system
CN106325988A (en) * 2016-08-03 2017-01-11 天津西瑞尔信息工程有限公司 Task scheduling method and device
CN106330769A (en) * 2016-11-15 2017-01-11 腾讯科技(深圳)有限公司 Business processing method and server
CN106503017A (en) * 2015-09-08 2017-03-15 摩贝(上海)生物科技有限公司 A kind of distributed reptile system task grasping system and method

Patent Citations (23)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005202976A (en) * 2005-02-15 2005-07-28 Mitsubishi Electric Corp Electronic apparatus
CN1828541A (en) * 2006-04-07 2006-09-06 浙江大学 Implementation method for timing task in Java operating system
US9405602B1 (en) * 2012-06-25 2016-08-02 Google Inc. Method for application notification and tasking
CN102904746A (en) * 2012-09-13 2013-01-30 曙光信息产业(北京)有限公司 Cluster task self-dispatching system and method based on information mechanism
CN103092932A (en) * 2013-01-06 2013-05-08 潘旻琦 Distributed document transcoding system
CN103475687A (en) * 2013-05-24 2013-12-25 北京网秦天下科技有限公司 Distributed method and distributed system for downloading website data
CN103475688A (en) * 2013-05-24 2013-12-25 北京网秦天下科技有限公司 Distributed method and distributed system for downloading website data
CN103345423A (en) * 2013-07-03 2013-10-09 北京京东尚科信息技术有限公司 Method and system for processing asynchronous task
WO2015061976A1 (en) * 2013-10-30 2015-05-07 Nokia Technologies Oy Methods and apparatus for task management in a mobile cloud computing environment
CN103793273A (en) * 2014-01-24 2014-05-14 北京京东尚科信息技术有限公司 Distributed type queue scheduling method and device based on Redis
CN104935658A (en) * 2015-06-17 2015-09-23 交通银行股份有限公司 Bank task allocation method and device
CN106503017A (en) * 2015-09-08 2017-03-15 摩贝(上海)生物科技有限公司 A kind of distributed reptile system task grasping system and method
CN105204933A (en) * 2015-09-18 2015-12-30 上海斐讯数据通信技术有限公司 Multitask switching execution method based on single process, multitask switching execution system based on single process and processor
CN105512244A (en) * 2015-11-30 2016-04-20 北京京东尚科信息技术有限公司 Database transaction processing method and device based on message queue
CN105528186A (en) * 2015-12-02 2016-04-27 北京京东尚科信息技术有限公司 Method and apparatus for printing tag data by mobile terminal
CN105719182A (en) * 2016-01-18 2016-06-29 北京京东尚科信息技术有限公司 Automatic account checking method and automatic account checking system
CN105760221A (en) * 2016-02-02 2016-07-13 中博信息技术研究院有限公司 Task dispatching system with distributed calculating frame
CN105786629A (en) * 2016-02-02 2016-07-20 四川长虹电器股份有限公司 Data processing method based on message queue
CN105868033A (en) * 2016-04-06 2016-08-17 江苏物联网研究发展中心 Method and system for achieving priority message queues based on Redis
CN105915633A (en) * 2016-06-02 2016-08-31 北京百度网讯科技有限公司 Automated operational system and method thereof
CN106201694A (en) * 2016-07-13 2016-12-07 北京农信互联科技有限公司 Configuration method and system for executing timing task under distributed system
CN106325988A (en) * 2016-08-03 2017-01-11 天津西瑞尔信息工程有限公司 Task scheduling method and device
CN106330769A (en) * 2016-11-15 2017-01-11 腾讯科技(深圳)有限公司 Business processing method and server

Non-Patent Citations (4)

* Cited by examiner, † Cited by third party
Title
梁奕等: "基于分布流的城市照明监控***优化策略研究", 《电气应用》 *
欧志芳: "基于RocketMQ实现异构数据库同步", 《网络安全技术与应用》 *
王伟军等: "《大数据分析》", 30 April 2017 *
陈丹: "公寓智能门锁管理***的设计和实现", 《《中国优秀硕士学位论文全文数据库信息科技辑》》 *

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109597699A (en) * 2018-11-28 2019-04-09 泰康保险集团股份有限公司 Data processing method, device, electronic equipment and computer-readable medium
CN109800068A (en) * 2018-12-20 2019-05-24 航天信息股份有限公司 Handle method, system, primary server and the timed task server of timed task
CN110413384A (en) * 2019-06-25 2019-11-05 腾讯科技(深圳)有限公司 Delayed tasks processing method and processing device, storage medium, electronic equipment
CN110413384B (en) * 2019-06-25 2024-03-01 腾讯科技(深圳)有限公司 Delay task processing method and device, storage medium and electronic equipment
CN110609758A (en) * 2019-08-30 2019-12-24 恒大智慧科技有限公司 Queue-based device operating method, computer device and readable storage medium
CN110990132B (en) * 2019-11-01 2023-03-10 浙江大搜车软件技术有限公司 Asynchronous task processing method and device, computer equipment and storage medium
CN110990132A (en) * 2019-11-01 2020-04-10 浙江大搜车软件技术有限公司 Asynchronous task processing method and device, computer equipment and storage medium
CN111078383A (en) * 2019-12-24 2020-04-28 浙江诺诺网络科技有限公司 Timed task management method, device, equipment and storage medium
CN111309496A (en) * 2020-02-10 2020-06-19 北京无限光场科技有限公司 Method, system, device, equipment and storage medium for realizing delay task
CN111611059B (en) * 2020-05-21 2022-06-17 安徽兆尹信息科技股份有限公司 Redis pipeline communication method for financial asset management system
CN111611059A (en) * 2020-05-21 2020-09-01 安徽兆尹信息科技股份有限公司 Redis pipeline communication method for financial asset management system
CN112596882A (en) * 2020-12-25 2021-04-02 上海悦易网络信息技术有限公司 Method, device and system for scheduling delayed tasks
CN113806046A (en) * 2021-09-15 2021-12-17 武汉虹信技术服务有限责任公司 Task scheduling system based on thread pool
CN115658278A (en) * 2022-12-07 2023-01-31 中国电子科技集团公司第三十研究所 Micro task scheduling machine supporting high concurrency protocol interaction

Similar Documents

Publication Publication Date Title
CN108874513A (en) Handle method, system, electronic equipment and the computer-readable medium of timed task
CN110245011A (en) A kind of method for scheduling task and device
US8874587B2 (en) Tenant placement in multitenant cloud databases with one-to-many data sharing
CN109413127A (en) A kind of method of data synchronization and device
CN108897854A (en) A kind of monitoring method and device of overtime task
CN110019503A (en) The dilatation of Redis cluster and/or the method and device of capacity reducing
CN110019258A (en) The method and apparatus for handling order data
CN110348771A (en) The method and apparatus that a kind of pair of order carries out group list
CN110135925A (en) Order processing system, method and apparatus
CN110473036A (en) A kind of method and apparatus generating order number
CN108776692A (en) Method and apparatus for handling information
CN107506218A (en) The management method and management system of a kind of configuration file
CN109413125A (en) The method and apparatus of dynamic regulation distributed system resource
CN110471848A (en) A kind of method and apparatus of dynamic returned packet
CN110348650A (en) A kind of method and apparatus at order interflow
CN110019346A (en) A kind of data processing method and device based on double primary databases
CN110046178A (en) The method and apparatus of distributed data inquiry
CN110019539A (en) A kind of method and apparatus that the data of data warehouse are synchronous
CN110304385A (en) A kind of warehouse restocking method and apparatus
CN109901918A (en) A kind of method and apparatus handling overtime task
CN109918191A (en) A kind of method and apparatus of the anti-frequency of service request
CN109885593A (en) Method and apparatus for handling information
CN109960212A (en) Task sending method and device
CN110162448A (en) The method and apparatus of log collection
CN108536395A (en) A kind of method and apparatus of cleaning hard disk

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20181123

RJ01 Rejection of invention patent application after publication