Multilingual sharding model
SchedulerX can schedule various jobs, such as timed jobs, orchestrated workflows, and historical data reprocessing. It provides a multilingual sharding model for Java, Python, Shell, and Go for processing large-scale data workloads.
Background
The sharding model uses static sharding, where you predefine the number of shards. These shards are then distributed evenly among available workers for execution. For example:
-
For a sharded database with a fixed number of 128 tables, you can distribute the processing of these tables across multiple machines.
-
You can configure 100 shards based on user ID prefixes from 00 to 99 and distribute the workload across several machines.
Features
The multilingual sharding model also provides the following features:
-
Compatibility with the static sharding model of elastic-job.
-
Support for Java, Python, Shell, and Go.
-
High availability: The sharding model is based on MapReduce, which provides high availability. If a worker fails during execution, a master worker initiates a failover and reassigns the shard to another slave node.
-
Throttling: The sharding model inherits the throttling feature from the MapReduce model, which allows you to control the concurrency of subtasks on a single machine. For example, if you have 1,000 shards and 10 machines, you can limit each machine to running a maximum of five shards concurrently, with the rest waiting in a queue.
-
Automatic shard retry on failure: Based on the MapReduce model, the sharding model inherits the automatic retry of failed subtasks.
You can configure high availability and throttling in the Advanced Settings when you create a job. For more information, see Create a scheduled job and Parameters for advanced settings of a job.
The multilingual sharding model is supported only in client versions 1.1.0 and later.
Java sharding job
Log on to the MSE SchedulerX console.
-
In the top navigation bar, select a region.
-
If you are using the MSE SchedulerX console, choose Task Management in the left-side navigation pane.
-
On the Task Management page, select a namespace and click Add Task in the upper-left corner.
-
In the Add Task panel, on the Basic configuration tab, set Execution mode to Shard run, configure Sharding parameters, and then click Next Step.
Separate sharding parameters with commas (,) or line breaks. For example:
shard_id_1=parameter_1,shard_id_2=parameter_2,....On the Basic Information tab of the Create Job page, set Job Name (for example,
sharding_job), set Job Type to Java, and enter the Full Class Name. Set Execution Mode to Sharded and Priority to Medium. In the Sharding Parameters field, enter the shard information in the specified format, and then click Next. -
In your application code, extend
JavaProcessor. UseJobContext.getShardingId()to get the shard ID andJobContext.getShardingParameter()to get the sharding parameter.Example:
@Component public class HelloWorldProcessor extends JavaProcessor { @Override public ProcessResult process(JobContext context) throws Exception { System.out.println("Shard ID=" + context.getShardingId() + ", Shard Parameter=" + context.getShardingParameter()); return new ProcessResult(true); } } -
On the Execution List page, click Details in the Actions column of the target job to view shard details.
Python sharding job
To run distributed batch jobs for a Python application, install the Agent. You can then manage the script in SchedulerX.
-
Download the SchedulerX Agent and use it to deploy the script job.
-
Create a Python sharding job in SchedulerX. For more information, see Create a scheduled job.
The script receives the shard ID as
sys.argv[1]and the sharding parameter assys.argv[2].Separate sharding parameters with commas (,) or line breaks. For example:
shard_id_1=parameter_1,shard_id_2=parameter_2,....In the Job Configuration dialog box, set Job Type to Python. In the code editor, enter the shard processing script. Set Execution Mode to Sharded. In the Sharding Parameters field, enter the shard configuration, such as
0=hello,1=world,2=my,3=name,4=is,5=huang. Then, click Next. -
On the Execution List page, click Details in the Actions column of the target job to view shard details.
Shell and Go sharding jobs
The process for creating Shell and Go sharding jobs is similar to that for Python sharding jobs. For more information, see Python Sharding Job.