Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/hadoop/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hadoop中的高效复制方法_Hadoop_Copy_Hdfs_Distcp - Fatal编程技术网

Hadoop中的高效复制方法

Hadoop中的高效复制方法,hadoop,copy,hdfs,distcp,Hadoop,Copy,Hdfs,Distcp,除了distcp之外,是否有一种更快或更有效的跨HDF复制文件的方法。我尝试了常规的hadoop fs-cp和distcp,它们似乎都提供了相同的传输速率,大约50Mbps 我有5TB的数据被分割成500GB的小文件,每个文件都必须复制到HDFS上的一个新位置。有什么想法吗 编辑: 原来的distcp只生成1个映射器,所以我添加了-m100选项来增加映射器 hadoop distcp -D mapred.job.name="Gigafiles distcp" -pb -i -m100 "/use

除了distcp之外,是否有一种更快或更有效的跨HDF复制文件的方法。我尝试了常规的hadoop fs-cp和distcp,它们似乎都提供了相同的传输速率,大约50Mbps

我有5TB的数据被分割成500GB的小文件,每个文件都必须复制到HDFS上的一个新位置。有什么想法吗

编辑: 原来的distcp只生成1个映射器,所以我添加了-m100选项来增加映射器

hadoop distcp -D mapred.job.name="Gigafiles distcp" -pb -i -m100 "/user/abc/file1" "/xyz/aaa/file1"

但它仍然只产生了1个而不是100个地图绘制者。我在这里遗漏了什么吗?

我能够通过使用pig脚本从路径a读取数据,转换为所需的存储格式parquet,然后将其写入路径B来解决这个问题。对于500GB的文件,这个过程平均需要近20分钟。谢谢您的建议。

如果您想在HDFS中将文件子集从一个文件夹复制到另一个文件夹,我会想到这个方法。它的效率可能不如distcp,但它可以完成这项工作,并在您需要执行其他操作时为您提供更多的自由。它还检查每个文件是否已经存在:

import pandas as pd
import os
from multiprocessing import Process
from subprocess import Popen, PIPE
hdfs_path_1 = '/path/to/the/origin/'
hdfs_path_2 = '/path/to/the/destination/'
process = Popen(f'hdfs dfs -ls -h {hdfs_path_2}', shell=True, stdout=PIPE, stderr=PIPE)
std_out, std_err = process.communicate()
already_processed = [fn.split()[-1].split('/')[-1] for fn in std_out.decode().readlines()[1:]][:-1]
print(f'Total number of ALREADY PROCESSED tar files = {len(already_processed)}')

df = pd.read_csv("list_of_files.csv")  # or any other lists that you have
to_do_tar_list = list(df.tar)
to_do_list = set(to_do_tar_list) - set(already_processed)
print(f'To go: {len(to_do_list)}')

def copyy(f):
    process = Popen(f'hdfs dfs -cp {hdfs_path_1}{f} {hdfs_path_2}', shell=True, stdout=PIPE, stderr=PIPE)
    std_out, std_err = process.communicate()
    if std_out!= b'':
        print(std_out)

ps = []
for f in to_do_list:
    p = Process(target=copyy, args=(f,))
    p.start()
    ps.append(p)
for p in ps:
    p.join()
print('done')
此外,如果您想拥有目录中所有文件的列表,请使用以下命令:

from subprocess import Popen, PIPE
hdfs_path = '/path/to/the/designated/folder'
process = Popen(f'hdfs dfs -ls -h {hdfs_path}', shell=True, stdout=PIPE, stderr=PIPE)
std_out, std_err = process.communicate()
list_of_file_names = [fn.split(' ')[-1].split('/')[-1] for fn in std_out.decode().readlines()[1:]][:-1]
list_of_file_names_with_full_address = [fn.split(' ')[-1] for fn in std_out.decode().readlines()[1:]][:-1]

为什么不创建一个具有目标位置的外部表并进行insert覆盖呢?那个insert会比hadoop copy更快吗?我们通常在拼花地板转换的数据上构建外部表,但我可以尝试这个选项。您不能修改此项。正如@Ambrish所说,insert将比distcp更快,但您将无法获得相同的文件结构。结果将是许多小文件,每个文件大小~=块大小。从您使用选项-pb的distcp命令中,我了解到“插入到表中”不是您要查找的选项。@franklinsijo感谢您提供有关distcp的信息。我不知道每个文件只有一个映射器。你能告诉我你是如何使用ApachePig脚本的吗?将hdfs写入s3存储桶是否有效。