hbase集群 数据写入_HBase数据写入测试

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();

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值