首页 文章 精选 留言 我的

精选列表

搜索[数据库连接池],共10000篇文章
优秀的个人博客,低调大师

性能测试工具操作数据库(十一)-Jmeter与Hbase

版权声明:本文为博主原创文章,未经博主允许不得转载。欢迎访问我的博客 https://blog.csdn.net/smooth00/article/details/74279856 由于在网上找不到Jmeter连接Hbase的源文件或是插件,所以本文只是通过Jmeter的BeanShell来调用和调试Hbase的远程连接操作,具体性能测试时,需要怎么应用(比如通过Java Request等方式),等具体开展测试时再进行灵活扩展和调整。 关键的是要引用正确的Hbase jar包(还要保证版本的兼容,Hbase1.0开始就要求JDK1.7及以上,而且Jmeter引用的Hbase Jar包最好是与服务端的Hbase一致,否则也会出现兼容性问题)。以下的测试代码都是在Jmeter3.1+JDK1.8环境下进行的。 1、下载Hbase Jar包,可以到官网下载整个包,获取其中的lib jar包:http://archive.apache.org/dist/hbase/,也可以下载我为本次测试所整理好的jar包(性能测试工具所引用的hbase依赖包) 2、在Jmeter的测试计划里把所有Jar包添加到classpath中(我不习惯把Jar包直接扔到Jmeter目录的lib\ext下,不方便区分管理) 3、将hadoop-common-2.2.0-bin-master文件目录放到Jmeter的bin目录下,主要是Windows下调用Hadoop组件,如果没有winutils.exe会报错(可以到网上下载这个包,上面提供的性能测试工具所引用的hbase依赖包里也有)。 4、在Jmeter中建立线程组,和建一个BeanShell Sampler,直接将以下代码复制上去进行调试(注意要配好zookeeper连接地址和端口) import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Get; 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.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; 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.TableName; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.ZooKeeperConnectionException; import java.io.File; public class HbaseTest { String tableName="student"; Configuration configuration=null; public void SetConfiguration() { configuration = HBaseConfiguration.create(); //config.set("hbase.zookeeper.quorum", "hellotest");//单机 configuration.set("hbase.zookeeper.quorum", "agent01.org.cn,agent02.org.cn,master.org.cn"); //包括三个节点的zookeeper地址(也可以是Host IP),第一个是主节点 configuration.set("hbase.zookeeper.property.clientPort", "2181");// zookeeper端口 configuration.set("hbase.regionserver.port", "16020"); configuration.set("zookeeper.znode.parent", "/hbase-unsecure"); configuration.set("hbase.rootdir", "hdfs://master.org.cn:8020/apps/hbase/data"); //connection = ConnectionFactory.createConnection(config); } /** * create a new Table * @param configuration Configuration * @param tableName String,the new Table's name * */ public static void createTable(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin = new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ admin.disableTable(tableName); admin.deleteTable(tableName); System.out.println(tableName+"is exist ,delete ......"); log.info(tableName+"is exist ,delete ......"); } HTableDescriptor tableDescriptor=new HTableDescriptor(TableName.valueOf(tableName)); tableDescriptor.addFamily(new HColumnDescriptor("info")); tableDescriptor.addFamily(new HColumnDescriptor("address")); admin.createTable(tableDescriptor); System.out.println("end create table"); log.info("end create table"); } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Delete the existing table * @param configuration Configuration * @param tableName String,Table's name * */ public static void dropTable(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin = new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ admin.disableTable(tableName); admin.deleteTable(tableName); System.out.println(tableName+"delete success!"); log.info(tableName+"delete success!"); }else{ System.out.println(tableName+"Table does not exist!"); log.info(tableName+"Table does not exist!"); } } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * insert a data * @param configuration Configuration * @param tableName String,Table's name * */ public static void addData(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin = new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ HTable table=new HTable(configuration, tableName); Put put=new Put(Bytes.toBytes("zhangsan")); put.add(Bytes.toBytes("info"), Bytes.toBytes("age"), Bytes.toBytes("28")); table.put(put); System.out.println("add success!"); log.info("add success!"); }else{ System.out.println(tableName+"Table does not exist!"); log.info(tableName+"Table does not exist!"); } } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Delete a data * @param configuration Configuration * @param tableName String,Table's name * */ public static void deleteDate(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin=new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ HTable table=new HTable(configuration, tableName); Delete delete=new Delete(Bytes.toBytes("zhangsan")); table.delete(delete); System.out.println("delete success!"); log.info("delete success!"); }else{ System.out.println("Table does not exist!"); } } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * get a data * @param configuration Configuration * @param tableName String,Table's name * */ public static void getData(Configuration configuration,String tableName){ HTable table; try { table = new HTable(configuration, tableName); Get get=new Get(Bytes.toBytes("zhangsan")); Result result=table.get(get); for(Cell cell:result.rawCells()){ System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" "); System.out.println("Timetamp:"+cell.getTimestamp()+" "); System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" "); System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" "); System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" "); log.info("RowName:"+new String(CellUtil.cloneRow(cell))+" "); log.info("Timetamp:"+cell.getTimestamp()+" "); log.info("column Family:"+new String(CellUtil.cloneFamily(cell))+" "); log.info("row Name:"+new String(CellUtil.cloneQualifier(cell))+" "); log.info("value:"+new String(CellUtil.cloneValue(cell))+" "); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * insert all data * @param configuration Configuration * @param tableName String,Table's name * */ public static void getAllData(Configuration configuration,String tableName){ HTable table; try { table=new HTable(configuration, tableName); Scan scan=new Scan(); ResultScanner results=table.getScanner(scan); for (Result result = results.next(); result != null; result = results.next()) { // print out the row we found and the columns we were looking for for(Cell cell:result.rawCells()){ System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" "); System.out.println("Timetamp:"+cell.getTimestamp()+" "); System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" "); System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" "); System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" "); log.info("RowName:"+new String(CellUtil.cloneRow(cell))+" "); log.info("Timetamp:"+cell.getTimestamp()+" "); log.info("column Family:"+new String(CellUtil.cloneFamily(cell))+" "); log.info("row Name:"+new String(CellUtil.cloneQualifier(cell))+" "); log.info("value:"+new String(CellUtil.cloneValue(cell))+" "); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public boolean runActions(){ File directory = new File("."); System.setProperty("hadoop.home.dir", directory.getCanonicalPath()+"\\hadoop-common-2.2.0-bin-master"); SetConfiguration(); createTable(configuration, tableName); addData(configuration, tableName); getData(configuration, tableName); getAllData(configuration, tableName); deleteDate(configuration, tableName); dropTable(configuration, tableName); return true; } } boolean runFlag=new HbaseTest().runActions(); log.info("runFlag:"+runFlag);以上代码中,加了log.info,用来调试代码以验证代码是否执行成功 5、在线程组中加上查看结果树、Summary Report、Debug Sampler,以全运行时查看成功情况。通过点击Jmeter右上方的三角!号(如果代码报错也能看能看到提示),可以查看代码运行日志(这是调试Java代码比较方便的工具),运行结果如下: 6、可以将以上的测试代码保存成java(或者可以打成jar包再用),直接通过jmerter进行引用和测试 7、相对来讲,Jmeter不适合调试Java代码,因为报一段长长的错误日志后,可能报错的最后一句话才能看出错误所在,所以以上代码也可以等在Java开发工具中调测通过后,再移植过来,然后再进一步调试和修改一些兼容性的错误。

优秀的个人博客,低调大师

性能测试工具操作数据库(十二)-Loadrunner与Hbase

版权声明:本文为博主原创文章,未经博主允许不得转载。欢迎访问我的博客 https://blog.csdn.net/smooth00/article/details/74295829 Hbase的测试关键是要引用正确的Hbase jar包(还要保证版本的兼容,Hbase1.0开始就要求JDK1.7及以上,而Loadrunner11不支持JDK1.7,所以本文举例用的是Loadrunner12,另外要保证引用的Hbase Jar包也是与服务端的Hbase版本一致,否则也会出现兼容性问题)。 1、在loadrunner中新建脚本(本文以LoadRunner12.02为例),要求选择协议类型为Java Vuser 2、在Replay-->Runtime Settings设置Java VM路径,由于LoadRunner12对jdk1.8的支持不好,本次测试是拷贝了一份绿色免安装版(32位)的jdk1.7.0_67,所以路径选择固定路径模式(Use the Specified JDK),并设置好JDK1.7的路径。 3、使用Java操作Hbase需要相关的Jar包(可以去官网下载),也可以下载我上传的包(性能测试工具所引用的hbase依赖包),放到include目录或其他目录下,并在Run-time Settings中配置Classpath 4、在Java Vuser脚本中编写Hbase的测试代码(举例如下,具体需要配置好): /* * LoadRunner Java script. (Build: _build_number_) * * Script Description: * */ import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Get; 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.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; import org.apache.hadoop.hbase.client.Scan; 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.TableName; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.ZooKeeperConnectionException; import org.apache.log4j.Logger; import org.apache.log4j.PropertyConfigurator; import org.apache.log4j.xml.DOMConfigurator; import java.io.File; import lrapi.lr; public class Actions { String tableName="student"; Configuration configuration=null; public int init() throws Throwable { //加载日志输出方式 File directory = new File("."); DOMConfigurator.configure(directory.getCanonicalPath()+"\\log4j.xml");//加载log4j.xml文件 //PropertyConfigurator.configure("E:/study/log4j/log4j.properties");//加载.properties文件 Logger log=Logger.getLogger("org.zblog.test"); System.setProperty("hadoop.home.dir", directory.getCanonicalPath()+"\\hadoop-common-2.2.0-bin-master"); configuration = HBaseConfiguration.create(); //config.set("hbase.zookeeper.quorum", "hellotest");//单机 configuration.set("hbase.zookeeper.quorum", "agent01.org.cn,agent02.org.cn,master.org.cn"); // zookeeper地址(包括一个主节点,两个子节点) configuration.set("hbase.zookeeper.property.clientPort", "2181");// zookeeper端口 configuration.set("hbase.regionserver.port", "16020"); configuration.set("zookeeper.znode.parent", "/hbase-unsecure"); configuration.set("hbase.rootdir", "hdfs://master.org.cn:8020/apps/hbase/data"); //connection = ConnectionFactory.createConnection(config); return 0; }//end of init public int action() throws Throwable { createTable(configuration, tableName); addData(configuration, tableName); getData(configuration, tableName); getAllData(configuration, tableName); deleteDate(configuration, tableName); dropTable(configuration, tableName); return 0; }//end of action public int end() throws Throwable { return 0; }//end of end /** * create a new Table * @param configuration Configuration * @param tableName String,the new Table's name * */ public static void createTable(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin = new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ admin.disableTable(tableName); admin.deleteTable(tableName); System.out.println(tableName+"is exist ,delete ......"); } HTableDescriptor tableDescriptor=new HTableDescriptor(TableName.valueOf(tableName)); tableDescriptor.addFamily(new HColumnDescriptor("info")); tableDescriptor.addFamily(new HColumnDescriptor("address")); admin.createTable(tableDescriptor); System.out.println("end create table"); } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Delete the existing table * @param configuration Configuration * @param tableName String,Table's name * */ public static void dropTable(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin = new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ admin.disableTable(tableName); admin.deleteTable(tableName); System.out.println(tableName+"delete success!"); }else{ System.out.println(tableName+"Table does not exist!"); } } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * insert a data * @param configuration Configuration * @param tableName String,Table's name * */ public static void addData(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin = new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ HTable table=new HTable(configuration, tableName); Put put=new Put(Bytes.toBytes("zhangsan")); put.add(Bytes.toBytes("info"), Bytes.toBytes("age"), Bytes.toBytes("28")); table.put(put); System.out.println("add success!"); }else{ System.out.println(tableName+"Table does not exist!"); } } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Delete a data * @param configuration Configuration * @param tableName String,Table's name * */ public static void deleteDate(Configuration configuration,String tableName){ HBaseAdmin admin; try { admin=new HBaseAdmin(configuration); if(admin.tableExists(tableName)){ HTable table=new HTable(configuration, tableName); Delete delete=new Delete(Bytes.toBytes("zhangsan")); table.delete(delete); System.out.println("delete success!"); }else{ System.out.println("Table does not exist!"); } } catch (MasterNotRunningException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ZooKeeperConnectionException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * get a data * @param configuration Configuration * @param tableName String,Table's name * */ public static void getData(Configuration configuration,String tableName){ HTable table; try { table = new HTable(configuration, tableName); Get get=new Get(Bytes.toBytes("zhangsan")); Result result=table.get(get); for(Cell cell:result.rawCells()){ System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" "); System.out.println("Timetamp:"+cell.getTimestamp()+" "); System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" "); System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" "); System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" "); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * insert all data * @param configuration Configuration * @param tableName String,Table's name * */ public static void getAllData(Configuration configuration,String tableName){ HTable table; try { table=new HTable(configuration, tableName); Scan scan=new Scan(); ResultScanner results=table.getScanner(scan); for(Result result:results){ for(Cell cell:result.rawCells()){ System.out.println("RowName:"+new String(CellUtil.cloneRow(cell))+" "); System.out.println("Timetamp:"+cell.getTimestamp()+" "); System.out.println("column Family:"+new String(CellUtil.cloneFamily(cell))+" "); System.out.println("row Name:"+new String(CellUtil.cloneQualifier(cell))+" "); System.out.println("value:"+new String(CellUtil.cloneValue(cell))+" "); } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } 5、保存脚本,同时将Hadoop-common-2.2.0-bin-master文件目录放到脚本的根目录下(因为以上代码写的取文件路径就是脚本根目录),这么做的目的主要是Windows下调用hadoop组件,如果没有winutils.exe就会报错(可以到网上下载这个Hadoop-common-2.2.0-bin-master包,上面提供下载的性能测试工具所引用的hbase依赖包里也有)。 6、运行脚本,通过LoadRunner的Replay Log可以看到数据操作测试执行成功: 7、通过性能测试工具调用Hbase的最大挑战是某些Jar包的缺失和版本的不兼容,所以本文也只能是提供个参考,具体应用的时候需要根据服务端部署的Hadoop版本和开发应用的需要,进行配置和引用相关的Jar包,并通过Loadrunner的Replay调试功能,不断的解决报错问题(是个考验耐心和细心的过程,中间遇到的问题有些可能是需要不断搜索外文网站和一些社区论坛才能找到正确的解释,没办法,开源技术没有现成的资料和使用说明,就得靠自己摸索和不断网上搜索)。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册