Distributed development--Distributed scheduled Tasks

Source: Internet
Author: User
One: Let's consider the following solutions for several business scenarios:-The payment system runs daily at 1 o'clock in the morning and is cleared for one day, and the monthly number 1th is cleared last month.
-Taobao on the hour, the price of goods 8 o'clock the start of the promotion
-12306 ticketing system, more than 30 minutes did not successfully pay the order, for the recycling process
-After the product has been successfully shipped, you need to send SMS alerts to the customer

> Similar business scenarios are very numerous and how we solve them.
Two: Why do we need a timed mission ?Many business scenarios require a particular moment of our time to do a certain task, which is the business scenario that the timed task solves. In general, the system can use message passing instead of part of a timed task, which has many similarities and can replace the scene with each other.     For example, the above delivery successfully texted the customer's business scenario, we can send the MQ message to the queue after successful delivery, and then go to consume MQ messages, send SMS. But in some scenarios it is not interchangeable: a) time-driven/event-driven: The internal system can generally be driven by time, but it involves external systems, only time-driven. If you are afraid to take the external website price, climb once per hour b) batch processing/article-by-line processing: Batch processing of accumulated data is more efficient, without the need for real-time performance of the message middleware more advantages. And some business logic can only be processed in batches. such as moving every month to settle our charges C) real-time/non-real-time: message middleware can do real-time processing of data, but in some cases do not need real-time, such as: VIP upgrade D) system internal/System decoupling: Scheduled task scheduling is generally within the system, and message middleware can be used between two systems
III: Points to be considered in the task frameworkSingle thread or multithreaded
When the task is delayed, is it lost or continues to delay
Serial or parallel
Whether the exception affects

Four: What is the framework of the scheduled tasks for Java?> Standalone-timer: is a timer class that can be configured for a specified scheduled task.   The TimerTask class is a timed task class that implements the Runnable interface, and the disadvantage of exception not checking aborts the thread-scheduledexecutorservice: relative delay or period as scheduled task scheduling, disadvantage no absolute date or time- Spring Timing Framework: More simple configuration, if the system uses a single machine, you can prioritize the spring timer
Advantages: Simple
Cons: cannot be highly available, that is, the node is hung, the task cannot run

> Clusters-Quartz:java the de facto standard for scheduled tasks. But the quartz focus is on timed tasks rather than data, and there is no set of processes tailored to data processing. Although quartz can implement high availability of jobs based on databases, it lacks the functionality of distributed parallel scheduling

Advantages: Guaranteed High availability, that is, node hangs, other nodes can still be replaced
Disadvantage: The same task can only be used to promote a single node execution, the other nodes will not perform tasks, low performance, wasting resources

> Distribution-tbschedule: Ali's early open source distributed task scheduling system. The code is slightly stale, using a timer rather than a thread pool to perform task scheduling. It is well known that the timer is flawed in dealing with abnormal conditions. And the Tbschedule job type is relatively single, can only be a mode of acquiring/processing data. And the lack of documentation is more serious.
-Elastic-job: When developing the flexible distributed task scheduling system, the feature is rich and powerful, the use of zookeeper for distributed coordination, to achieve high availability of tasks and shards, is currently version 2, and can support cloud development
-Saturn: is a distributed scheduled task scheduling platform developed independently by the product, which is based on the Elastic-job version 1, and can be deployed to Docker containers for true elasticity.

Advantages: High availability and high performance can be achieved, the task is fragmented, allocated to multiple nodes to execute, and support elastic scaling, the node can dynamically increase the deletion
Cons: Complex, relying on third-party distributed coordination components

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.