在进行实验的过程中,在Upload这一阶段通过观察多组实验数据的时间长短发现:
1:视频总大小相同,视频分片数量不同时,从本地Upload上传到HDFS上的时间不同;
趋势为视频分片越多,传递时间可能越长。
2:同组测试数据,同样分割方法,upload的时间偶尔也存在较大差异
思考:
在控制台看到上图的upload的时间统计过程时,是逐步打印出每一个分片的copyFromLocal的命令的,有点单条命令(某分片上传)成功的等待时间短,也亦存在单条命令(某分片上传)成功的时间长,这也许就造成了每次实验中upload过程时间的差异。
如果upload过程中是单片单片的上传,造成了这种差异,那在Upload过程中我们将整个文件夹往上传,文件夹大小(测试视频总大小)一样,会不会能够消除这一过程的时间差异,从而将数据的特点(差异)转到transcode过程中。使transcode过程的时间优化在数据上展示的更加明显。
当然这只一个小小的想法,要验证这个思考,可能需要弄清三个因素:
A:copyFromLoacl这个函数的使用方法,到底其是对文件夹进行copy,还是对文件进行copy
B:弄清楚A后确认,若目前是是单片传递,则调整代码实现成对文件夹的操作,测试几组数据看看。(来确认是不是和分片数量有关)
C: 单片upload时间差异存在,即“逐步打印出每一个分片的copyFromLocal的命令的,有点单条命令(某分片上传)成功的等待时间短,也亦存在单条命令(某分片上传)成功的时间长”,那整个文件夹来Upload操作,虽然文件大小一样,但会不会也存在时间差异。存在即合理~~不对,存在即麻烦呐!
关于A思考与结论:
首先分析我的Upload阶段的代码
private String[] generate_idx() throws FileNotFoundException {
String[] splitList = null;
File splitVideoPath = new File(splitPath);
splitList = splitVideoPath.list(filter(".*\\.(mp4|ts|m2ts)"));
Arrays.sort(splitList);
for (String splitname : splitList) {
PrintWriter outTxt = new PrintWriter(indexPath + splitname + ".idx");
outTxt.println(splitname + "@" + this.parameter + "&" + this.outformat + "$" + this.username);
outTxt.close();
}
return splitList;
}
private boolean copy_to_cluster(String[] splitList) throws IOException, InterruptedException {
//String hadoop = "/opt/hadoop/hadoop-2.7.1/bin/hadoop ";
String hadoop="hadoop ";
String command = null;
Runtime rt = Runtime.getRuntime();
int exit = 0;
//查看这一部分的运行时间
//要包含循环体,是多个分片都有传到集群上
long copy_to_cluster_start = System.currentTimeMillis();
for (String splitname : splitList) {
// copy the index videos to hadoop cluster
command = hadoop + "fs -copyFromLocal -f " + indexPath + splitname + ".idx /" + this.username + "/"
+ procesfileName + "/index";
exit = callexec(rt, command);
if (exit != 0) {
return false;
}
// copy the splits videos to hadoop cluster
command = hadoop + "fs -copyFromLocal -f " + splitPath + splitname + " /" + this.username + "/"
+ procesfileName + "/split";
exit = callexec(rt, command);
print("TaskID=" + this.taskid + ": " + command);
println(": " + (exit == 0 ? "Success" : "Fail"));
if (exit != 0) {
return false;
}
}
long copy_to_cluster_end = System.currentTimeMillis();
System.out.println("分片传到集群用时:"+(copy_to_cluster_end-copy_to_cluster_start)+"毫秒");
return true;
}
for (String splitname : splitList)的意思就是类似于下面的:
是for循环的增强形式,在jdk1.5出来才有的
for(String str : strs)
意思是定义了一个新的字符串,收集str集合(数组)中的元素
1 2 3 4 |
for(int i=0;i<strs.size();i++){ |
for 循环 一定程度上取代了在集合中遍历元素使用的Iterator
但是for循环有一点不好,它无法体现出你所求的集合的下标,你不知道哪个对应哪个
所以在我们的代码中的splitname应该就是split文件夹中的每一分片的名字,splitpath=“/opt/DVTS/output/.temp/splits/”
command = hadoop + "fs -copyFromLocal -f " + splitPath + splitname + " /" + this.username + "/"
+ procesfileName + "/split";
结论就是在Upload阶段是单个单个视频分片往上传递的。
下一步则需要检索测试将splits这整个文件夹一下传递到HDFS上的/hadoop/Transcoding_0.mp4/split文件中。若能,这就是一个优化方向,可在upload和download两个阶段进行改进测试。