测试HDFS读性能-读到本地缓存,不写硬盘的性能

7 篇文章 0 订阅

如果测试读完存到本地文件的话,直接用fs.copyToLocalFile()方法即可,但是如果测试读到缓存的性能,则需要用到FSDataInputStream

上代码:

/**
 * @ProjectName: Hadoop预研平台
 */
package com.hikvision.hdfs.test.performance;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;


/**
 * <p>测试hdfs读到本地缓存的性能</p>
 * @author 2013-1-10 下午5:05:36
 * @version V1.0   
 * @modificationHistory===逻辑或功能性重大变更记录===
 */
public class TestReadPerformence {
	
	/**
	 * @author wanglongyf2 2013-1-10 下午5:05:37
	 * @param args:  文件路经  每次读的大小(M为单位)
 	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		Configuration conf = HBaseConfiguration.create();
		conf.set("hbase.zookeeper.quorum", "node1,node2,node3");
		conf.set(/*"fs.defaultFS"*/"fs.default.name","hdfs://node1");
		FileSystem hdfs = FileSystem.get(conf);
		
		String fileName = "/hbase/testscan/5f525e5fc37da7f1fc0c42b4a5a3be0b/f1/2820765239803238635";//1g
		if(args.length >= 1) {
			fileName = args[0];
		}
		int mNumber = 1;
		if(args.length ==2 ) {
			mNumber = Integer.valueOf(args[1]);
		}
		//fileName = "/hbase/testscan/5f525e5fc37da7f1fc0c42b4a5a3be0b/f1/6774381191569120295";
		FSDataInputStream dis = hdfs.open(new Path(fileName));
		long start = System.currentTimeMillis();
		byte[] b = new byte[mNumber * 1024 * 1024];
		int read = dis.read(b);
		long total = 0;
		while(read > 0) {
			total += read;
			read = dis.read(b);
	//		System.out.println(total/1024/1024);
		}
		long stop = System.currentTimeMillis();
		long use = stop - start;
		double rate = 1000.0 * total / (use * 1024 * 1024);
		System.out.println("total: " + total +". use: " + use + ". rate:M/s:" + rate );		
	}
}


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值