मेरे पास संभवतः लाखों लाइनों के साथ एक सादा पाठ फ़ाइल है जिसके लिए कस्टम पार्सिंग की आवश्यकता है और मैं इसे जितनी जल्दी हो सके HBase तालिका में लोड करना चाहता हूं (हैडोप या एचबेस जावा क्लाइंट का उपयोग करके)।प्रोग्रामिंग के रूप में एचबीएस में थोक लोड डेटा का सबसे तेज़ तरीका क्या है?
मेरा वर्तमान समाधान पर MapReduce नौकरी के बिना काम पर आधारित है। मैं पाठ फ़ाइल को पढ़ने के लिए FileInputFormat
का उपयोग करता हूं ताकि प्रत्येक पंक्ति मेरी Mapper
कक्षा की विधि को पास कर दी गई हो। इस बिंदु पर Put
ऑब्जेक्ट बनाने के लिए लाइन को पार्स किया गया है जो context
पर लिखा गया है। फिर, TableOutputFormat
Put
ऑब्जेक्ट लेता है और इसे तालिका में सम्मिलित करता है।
यह समाधान प्रति सेकंड 1,000 पंक्तियों की औसत प्रविष्टि दर उत्पन्न करता है, जो कि मेरी अपेक्षा से कम है। मेरा एचबीएस सेटअप एक सर्वर पर छद्म वितरित मोड में है।
एक दिलचस्प बात यह है कि 1,000,000 पंक्तियों के सम्मिलन के दौरान, 25 मैपर (कार्य) उत्पन्न होते हैं लेकिन वे क्रमशः (एक के बाद एक) चलाते हैं; क्या यह सामान्य है?
public static class CustomMap extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {
protected void map(LongWritable key, Text value, Context context) throws IOException {
Map<String, String> parsedLine = parseLine(value.toString());
Put row = new Put(Bytes.toBytes(parsedLine.get(keys[1])));
for (String currentKey : parsedLine.keySet()) {
row.add(Bytes.toBytes(currentKey),Bytes.toBytes(currentKey),Bytes.toBytes(parsedLine.get(currentKey)));
}
try {
context.write(new ImmutableBytesWritable(Bytes.toBytes(parsedLine.get(keys[1]))), row);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public int run(String[] args) throws Exception {
if (args.length != 2) {
return -1;
}
conf.set("hbase.mapred.outputtable", args[1]);
// I got these conf parameters from a presentation about Bulk Load
conf.set("hbase.hstore.blockingStoreFiles", "25");
conf.set("hbase.hregion.memstore.block.multiplier", "8");
conf.set("hbase.regionserver.handler.count", "30");
conf.set("hbase.regions.percheckin", "30");
conf.set("hbase.regionserver.globalMemcache.upperLimit", "0.3");
conf.set("hbase.regionserver.globalMemcache.lowerLimit", "0.15");
Job job = new Job(conf);
job.setJarByClass(BulkLoadMapReduce.class);
job.setJobName(NAME);
TextInputFormat.setInputPaths(job, new Path(args[0]));
job.setInputFormatClass(TextInputFormat.class);
job.setMapperClass(CustomMap.class);
job.setOutputKeyClass(ImmutableBytesWritable.class);
job.setOutputValueClass(Put.class);
job.setNumReduceTasks(0);
job.setOutputFormatClass(TableOutputFormat.class);
job.waitForCompletion(true);
return 0;
}
public static void main(String[] args) throws Exception {
Long startTime = Calendar.getInstance().getTimeInMillis();
System.out.println("Start time : " + startTime);
int errCode = ToolRunner.run(HBaseConfiguration.create(), new BulkLoadMapReduce(), args);
Long endTime = Calendar.getInstance().getTimeInMillis();
System.out.println("End time : " + endTime);
System.out.println("Duration milliseconds: " + (endTime-startTime));
System.exit(errCode);
}
मुझे लगता है कि आप चाहते हैं कि आपका शीर्षक "थोक भार" और "ब्लुक लोड" न हो ... लेकिन अगर मेरा सुधार गलत था तो मुझे बताएं। :-) –
क्या आपने इसे पढ़ा है? http://hbase.apache.org/docs/r0.89.20100621/bulk-loads।एचटीएमएल –
इसके अलावा, क्या आपने अपने क्षेत्रों को पूर्व-विभाजित किया है? यदि नहीं, तो मूल रूप से आपके पास एकल-थ्रेडेड लेखक होता है, जो इसे समझाएगा। आप मूल रूप से प्रति क्षेत्र एक लेखक प्राप्त करते हैं। –