为了账号安全,请及时绑定邮箱和手机立即绑定

Datax3.0中配置解读(1)

标签:
Java

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

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的话,有三个线程到线程池中去执行切分的任务。
并发会增大。






点击查看更多内容
2人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
JAVA开发工程师
手记
粉丝
6396
获赞与收藏
157

关注作者,订阅最新文章

阅读免费教程

感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消