Visual MapReduce model

Updated at:

The Visual MapReduce model extends the standard MapReduce model with visual and operational capabilities. Without modifying your backend code, you can change the execution mode to Visual MapReduce in the MSE SchedulerX console. This adds a subtask list page where you can view the details, results, and logs for each subtask, and rerun subtasks individually.

Limitations

  • Older SDK versions have security vulnerabilities. Upgrade your client to version 1.12.2 or later.

  • This feature is available only in the Professional Edition.

  • The number of subtasks cannot exceed 1,000.

  • A single subtask cannot exceed 64 KB in size.

  • To display custom labels for subtasks, the subtask object must implement the specified interface.

  • The result returned by ProcessResult cannot exceed 1,000 bytes.

  • If you use the reduce method, the results of all subtasks are cached on the master node, causing high memory pressure. Keep the number of subtasks and the size of the returned result small. If you do not need the reduce functionality, use the MapJobProcessor interface.

  • SchedulerX does not guarantee exactly-once execution for subtasks. In certain failover conditions, a subtask may be executed more than once. Your application must handle this by being idempotent.

Interfaces

  • This model inherits all interfaces from the MapReduce model. The development model for task processing code is identical to that of the MapReduce model. For more information, see MapReduce Model.

  • (Optional) In addition to the MapReduce model interfaces, you can set a display label for each subtask. The subtask object must implement the com.alibaba.schedulerx.worker.processor.BizSubTask interface.

    Method

    Description

    Required

    public Map<String, String> labelMap()

    Implement this method to return a map of custom labels for the subtask. These labels display business-specific identifiers for each subtask object in the console, such as an account name, product code, or city.

    No

Comparison with MapReduce

Feature

MapReduce

Visual MapReduce

Number of subtasks

Supports millions of subtasks.

Up to 1,000.

Task development model

Identical for both.

Subtask list

Not supported.

Supported.

Subtask execution details

Not supported.

Supported. You can view the execution record, status, logs, distributed tracing, and stack trace for each subtask.

Subtask labels

Not supported.

Supported. If a subtask implements the BizSubTask interface, you can view its business labels.

Subtask operations

Not supported.

Supported. You can stop or rerun individual subtasks.

Task development demo

Batch account processing

This example demonstrates how to process a batch of bank accounts. Each account is handled as an independent subtask and processed in parallel across the cluster. In the UI, each subtask displays its corresponding account information, making it easy to track the status and execution details for every account. The following code is a reference implementation.

  1. Define a custom subtask object for account information. To display a label for each subtask, the object must implement the com.alibaba.schedulerx.worker.processor.BizSubTask interface and its labelMap method.

    View code

    public class ParallelAccountInfo implements BizSubTask {
    
        /**
         * Primary key
         */
        private long id;
    
        private String name;
    
        private String accountId;
    
        public ParallelAccountInfo(long id, String name, String accountId) {
            this.id = id;
            this.name = name;
            this.accountId = accountId;
        }
    
        /**
         * Implement the labelMap method to set custom labels for the subtask.
         * @return
         */
        @Override
        public Map<String, String> labelMap() {
            Map<String, String> labelMap = new HashMap();
            labelMap.put("Account Name", name);
            return labelMap;
        }
    }

    After the subtask object implements the required interface, the subtask list displays a unique label for each subtask, such as the account name in this example. This helps distinguish the processing status of each account and allows searching by label.

    image

  2. Create a processor for the account-processing task. It should handle the business logic for a single account and extend com.alibaba.schedulerx.worker.processor.MapReduceJobProcessor.

    View code

    public class ParallelJob extends MapReduceJobProcessor {
    
        private static final Logger logger = LoggerFactory.getLogger("schedulerx");
    
        @Override
        public ProcessResult reduce(JobContext context) throws Exception {
            return new ProcessResult(true);
        }
    
        @Override
        public ProcessResult process(JobContext context) throws Exception {
            if(isRootTask(context)){
                logger.info("Building the list of subtasks for parallel processing...");
                List<ParallelAccountInfo> list = new LinkedList();
                /**
                 *  If this is the root task, build the list of subtask objects for parallel execution.
                 *  In a real-world scenario, you can load subtask objects based on your business needs, 
                 *  ensuring that each object implements the BizSubTask interface.
                 *  Example scenarios:
                 *  1. Load unprocessed customer account information from a database.
                 *  2. Build a list of provinces and cities to distribute tasks geographically.
                 *  3. Classify subtasks based on business labels, such as electronics, daily goods, or food.
                 *  4. Classify subtasks based on time, such as by month (January, February, etc.).
                 */
                for(int i=0; i < 20; i++){
                    list.add(new ParallelAccountInfo(i, "CUS"+StringUtils.leftPad(i+"", 4, "0"),
                            "AC"+StringUtils.leftPad(i+"", 12, "0")));
                }
                return map(list, "transfer");
            }else {
                /**
                 * If this is not the root task, you can get the corresponding subtask object 
                 * and perform your business processing.
                 */
                ParallelAccountInfo obj = (ParallelAccountInfo)context.getTask();
                // Process the business logic for the retrieved subtask object 'obj'.
                // do something
                logger.info("Processing subtask: {}", JSON.toJSONString(obj));
                return new ProcessResult(true);
            }
        }
    }

    After developing and deploying the job, configure and run it as a scheduled task in the console. For instructions, see Procedure.

Procedure

Configure a task

  1. Log on to the MSE SchedulerX console. In the left-side navigation pane, click Task Management.

  2. On the Task Management page, click Add Task.

  3. In the Add Task panel, select Visual MapReduce from the Execution Mode drop-down list.

    image

  4. In the Advanced Settings section, configure the parameters. For information about other parameters, see Advanced Settings parameter reference for Task Management.

    Parameter

    Description

    Dispatch policy

    Round-robin policy (Default): Distributes an equal number of subtasks to each worker node. This policy is suitable for scenarios where each subtask takes a similar amount of time to process.

    WorkerLoad-based policy: The master node dynamically senses the load on each worker node and distributes subtasks accordingly. This policy is suitable for scenarios where processing times vary significantly across subtasks or worker nodes.

    Note

    Requires client version 1.10.14 or later.

    Subtask concurrency per machine

    The number of execution threads on a single machine. The default value is 5. To speed up execution, you can increase this value. If downstream systems or databases cannot handle the load, you can decrease it.

    Subtask failure retry attempts

    The number of times a failed subtask is automatically retried. The default value is 0.

    Subtask failure retry interval

    The interval between retry attempts for a failed subtask, in seconds. The default value is 0.

    Subtask failover policy

    Specifies whether to redistribute subtasks to other machines if an executing node goes down. If you enable this policy, subtasks may be executed more than once during a failover. You must implement idempotence in your application to handle this.

    Note

    Requires client version 1.8.13 or later.

    Master node participation

    Specifies whether the master node participates in subtask execution. This option requires at least two online worker nodes. We recommend disabling this option when the number of subtasks is very large.

    Note

    Requires client version 1.8.13 or later.

Visualization features

After a task runs, go to the Execution List page and click Details for an execution to view its subtask details.

  • On the Subtask list tab, you can view the processing status of each subtask.

  • On the Subtask list tab, click Log in the Actions column for a subtask to view its business logs and analyze its execution result.

  • While a task is running, go to the Current execution details tab and click View Stack to view the stack trace of the processing threads on the corresponding machine. This helps you diagnose issues such as hangs or performance bottlenecks.

  • On the Subtask list tab, if you have enabled distributed tracing, you can click a TraceId to view the complete call chain for that subtask. For more information, see Enable distributed tracing.

Related documentation