手机版
你好,游客 登录 注册
背景:
阅读新闻

HBase数据写入测试

[日期:2013-01-25] 来源:Linux社区  作者:qiuchenl [字体:大 中 小]

测试程序

package GIS.Update;

import java.io.IOException;
import java.math.BigInteger;

import org.apache.Hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataOutputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class TestUpdate {
 
 public static void testHDFS() throws IOException{
  String str="hdfs://cloudgis4:9000/usr/tmp/";
  Path path=new Path(str);
  Configuration conf=new Configuration();
  conf.addResource(new Path("/usr/local/hadoop/conf/hdfs-site.xml"));
  FileSystem hdfs=path.getFileSystem(conf);
  hdfs.setReplication(path, (short)4);
  FSDataOutputStream fsDataOut=hdfs.create(new Path(str+"zzz"));
  long begin=System.currentTimeMillis();
  for(int i=0;i<10000000;i++){
   //byte [] kkk=new byte[10000+i/1000];
   byte [] kkk=new byte[12];
   fsDataOut.write(kkk);
   //fsDataOut.close();
   //hdfs.close();
  }
  fsDataOut.close();
  long end=System.currentTimeMillis();
  System.out.println("hdfs:"+(end-begin));
 }
 
 public static void testHBase() throws IOException{
  Configuration conf=HBaseConfiguration.create();
  conf.addResource(new Path("/usr/local/hbase/conf/hbase-site.xml"));
  //conf.addResource("/usr/local/hbase/conf/hdfs-site.xml");
  HBaseAdmin admin=new HBaseAdmin(conf);
  String tableName="qq";
  String familyName="imageFamily";
  String columnName="imageColumn";
  HTableDescriptor htd=new HTableDescriptor (tableName);
  HColumnDescriptor hdc=new HColumnDescriptor(familyName);
  htd.addFamily(hdc);
  long before=System.currentTimeMillis();
  //admin.createTable(htd,splits);
  admin.createTable(htd,Bytes.toBytes("0000000"),Bytes.toBytes("9999999"),150);
  long after=System.currentTimeMillis();
  System.out.println(after-before);
  HTable table=new HTable(conf,htd.getName());
  table.setAutoFlush(false);
  //table.setWriteBufferSize(209715200);
  System.out.println(table.getWriteBufferSize());
  long begin=System.currentTimeMillis();   
  for(int i=0;i<10000000;i++){
   byte [] kkk=new byte[10000+i/1000]; 
   //byte [] kkk=new byte[12];
   Put p1=new Put(Bytes.toBytes(intToString(i)));
   p1.setWriteToWAL(false);
   p1.add(Bytes.toBytes(familyName),Bytes.toBytes(columnName),kkk);
   table.put(p1);
  }
  long end=System.currentTimeMillis();
  table.flushCommits();
  System.out.println("HBase:"+(end-begin));
 }
 
 static public String intToString(int x){
  String result=String.valueOf(x);
  int size=result.length();
  while(size<7){
   size++;
   result="0"+result;
  }
  return result;
 }

 
 public static void main(String []args) throws IOException{
  testHBase();
 }
}

linux
相关资讯       Hbase 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款