继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Datax3.0中配置解读(1)

small_925_ant
关注TA
已关注
手记 69
粉丝 6396
获赞 157

首先从一个简单的配置文件开始

core.json部分配置
"container": {
    "job": {
        "reportInterval": 10000
    },
    "taskGroup": {
        "channel": 5
    },
    "trace": {
        "enable": "false"
    }
}
taskGroup.channel在什么地方会用到?
com.alibaba.datax.core.job.schedule() 方法中:
int channelsPerTaskGroup = this.configuration.getInt(
        CoreConstant.DATAX_CORE_CONTAINER_TASKGROUP_CHANNEL, 5);

taskGroup.channel有什么作用?我们现看另一个参数

"job": {
    "setting": {
      "speed": {
        "channel":1
      }
    },
    "content": [
      {
        "reader": {
        },
        "writer": { 
          }
        }
      }
    ]
  }
}
job.setting.speed.channel这个参数又有什么作用,在什么地方被用到?
com.alibaba.datax.core.job.split()方法中的this.adjustChannelNumber();方法中初始化
在没有配置job.setting.speed.byte,job.setting.speed.record的情况下会走到这里
boolean isChannelLimit = (this.configuration.getInt(
        CoreConstant.DATAX_JOB_SETTING_SPEED_CHANNEL, 0) > 0);//job.setting.speed.channel
if (isChannelLimit) {
    this.needChannelNumber = this.configuration.getInt(
            CoreConstant.DATAX_JOB_SETTING_SPEED_CHANNEL);//获取任务配置的channel

    LOG.info("Job set Channel-Number to " + this.needChannelNumber
            + " channels.");

    return;
}
继续schedule方法,此时会和拆分的任务数比较取最小值
this.needChannelNumber = Math.min(this.needChannelNumber, taskNumber);

然后进入关键的方法:
/**
 * 通过获取配置信息得到每个taskGroup需要运行哪些tasks任务
 * 总任务书/配置的任务组数目  获取需要定义几个taskGroupConfigs
 */
List<Configuration> taskGroupConfigs = JobAssignUtil.assignFairly(this.configuration,
        this.needChannelNumber, channelsPerTaskGroup);
        
可以看到下面一行代码:
int taskGroupNumber = (int) Math.ceil(1.0 * channelNumber / channelsPerTaskGroup);// 返回大于或者等于指定表达式的最小整数,即向上取整     
此时可以看到channelsPerTaskGroup 也就是taskGroup.channel的作用
会帮我们计算出taskGroupNumber.
List<Configuration> taskGroupConfig = doAssign(resourceMarkAndTaskIdMap, configuration, taskGroupNumber);
taskGroupNumber的作用是什么?继续跟进代码
scheduler.schedule(taskGroupConfigs);   
startAllTaskGroup(configurations);

public void startAllTaskGroup(List<Configuration> configurations) {
    this.taskGroupContainerExecutorService = Executors
            .newFixedThreadPool(configurations.size());

    for (Configuration taskGroupConfiguration : configurations) {
        TaskGroupContainerRunner taskGroupContainerRunner = newTaskGroupContainerRunner(taskGroupConfiguration);
        this.taskGroupContainerExecutorService.execute(taskGroupContainerRunner);
    }

    this.taskGroupContainerExecutorService.shutdown();
}
可以看到有几个taskGroupNumber,就会启动几个线程去执行任务组


从上面可以分享出:

job.setting.speed.channel配置1的话,只会有一个线程去执行切分的所有任务
当job.setting.speed.channel配置为15的话,有三个线程到线程池中去执行切分的任务。
并发会增大。






打开App,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP