I'm using an production server for loading large data set to Hadoop to access from Hive table.
We are loading subscribers web browsing data of Telecom Sector. We've large number of .csv.gz file (File sizes around 300-500MB) which is compressed using gzip
.
Suppose a file is as below:
Filename: dna_file_01_21090702.csv.gz
Contents:
A,B,C,2
D,E,F,3
We unzip 50 or so files and concatenate to one file. For troubleshooting purposes, we append the file name as first column of every row.
So concatenet data file would be:
dna_file_01_21090702.csv.gz,A,B,C,2
dna_file_01_21090702.csv.gz,D,E,F,33
For that purposed written below bash script:
#!/bin/bash
func_gen_new_file_list()
{
> ${raw_file_list}
ls -U raw_directory| head -50 >> ${raw_file_list}
}
func_create_dat_file()
{
cd raw_directory
gzip -d `cat ${raw_file_list}`
awk '{printf "%s|%s\n",FILENAME,$0}' `cat ${raw_file_list}|awk -F".gz" '{print $1}'` >> ${data_file}
}
func_check_dir_n_load_data()
{
## Code to copy data file to HDFS file system
}
##___________________________ Main Function _____________________________
##__Variable
data_load_log_dir=directory
raw_file_list=${data_load_log_dir}/raw_file_list_name
data_file_name=dna_data_file_`date "+%Y%m%d%H%M%S"`.dat
data_file=${data_load_log_dir}/${data_file_name}
##__Function Calls
func_gen_new_file_list
func_create_dat_file
func_check_dir_n_load_data
Now the problem is gzip -d
command performing extremely slow. I mean really really slow. If it unzip 50 files and make the concatenated data file the size would be around 20-25GB.
To unzip 50 files and concatenate it to one takes almost 1 hour which is huge. In this rate, its impossible to process all the data generated in a single day.
My production server(VM) is pretty powerful. Total core is 44 and RAM is 256GB. Also HARD Disk is very good and high performing. IOwait is around 0-5.
How can I faster this process? What is the alternatives of gzip -d
. Is there any other way to make the concatenated data file more efficiently. Please note that we need to keep the file name in records for trouble shooting purpose.
Otherwise we could have just use zcat
and append to a data file without unzipping at all.
/dev/shm
or other RAMdisk territory at a test to see if things speed up appreciably?