Loadrunner通过ssh连接linux进行hadoop基准测试
Loadrunner通过ssh连接调用hadoop的测试Jar包进行基准测试,似乎有点讨巧,而且好像实际意义也不是特别大,但是通过这个方法的展示,能够看到Loadrunner的生命力有多大,而且在linux系统测试和开源技术的测试中,也是能够有用武之地,所以本文算是来个抛砖引玉吧。
1、在loadrunner中新建脚本(本文以LoadRunner11为例),要求选择协议类型为Java->Java Vuser
2、在Run-time Settings设置JDK路径,由于LoadRunner11不支持jdk1.8,本次测试是拷贝了一份低版本的JDK1.6,所以路径选择固定路径模式(Use specified JDK),当然也可以将JDK1.6配到环境变量中,LoadRunner就可以直接调了。
3、上网下载个jsch-0.1.41.jar,然后在LoadRunner中加载jsch的jar包
4、在Loadrunner中以Java Vuser协议创建脚本,脚本样例如下:
/** LoadRunner Java script. (Build: _build_number_)* * Script Description: * */
import lrapi.lr;import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Vector; import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import java.io.InputStream;public class Actions
{private String ipAddress; private String username; private String password; public static final int DEFAULT_SSH_PORT = 22; private Vector<String> stdout; private Session session=null;private Channel channel=null;public void SSHCommandExecutor(final String ipAddress, final String username, final String password) { this.ipAddress = ipAddress; this.username = username; this.password = password; stdout = new Vector<String>();JSch jsch = new JSch(); try{session = jsch.getSession(username, ipAddress, DEFAULT_SSH_PORT); session.setPassword(password);session.setConfig("StrictHostKeyChecking", "no");//session.setUserInfo(userInfo); session.connect(); // Create and connect channel. channel = session.openChannel("exec");} catch (JSchException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); }} public int CommandExecute(final String command) { int returnCode = 0; try { ((ChannelExec) channel).setCommand(command); channel.setInputStream(null); BufferedReader input = new BufferedReader(new InputStreamReader(channel .getInputStream())); channel.connect(); System.out.println("The remote command is: " + command); // Get the output of remote command. String line; while ((line = input.readLine()) != null) { stdout.add(line); } input.close(); // Get the return code only after the channel is closed. if (channel.isClosed()) { returnCode = channel.getExitStatus(); } // Disconnect the channel and session. //channel.disconnect(); //session.disconnect(); } catch (JSchException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } return returnCode; } public int init() throws Throwable {SSHCommandExecutor("172.17.2.12", "root", "123456");return 0;}//end of initpublic int action() throws Throwable {lr.start_transaction("exe_command");//----------------------------------------写入2个1M的文件---------------------------------/*String commandStr="yarn jar /usr/hdp/2.3.2.0-2950/hadoop-mapreduce/hadoop-mapreduce-client-jobclient-2.7.1.2.3.2.0-2950-tests.jar TestDFSIO -write -nrFiles 2 -fileSize 1";String commandLog="cat -b /root/TestDFSIO_results.log |tail -n10";*///--------------------------------------------TestDFSIO -clean---------------------------//---------------------使用12个mapper和6个reducer来创建12个文件----------------------------String commandStr="yarn jar /usr/hdp/2.3.2.0-2950/hadoop-mapreduce/hadoop-mapreduce-client-jobclient-2.7.1.2.3.2.0-2950-tests.jar nnbench \\";commandStr+="\n -operation create_write -maps 12 -reduces 6 -blockSize 1 \\";commandStr+="\n -bytesToWrite 0 -numberOfFiles 12 -replicationFactorPerFile 3 \\";commandStr+="\n -readFileAfterOpen true -baseDir /benchmarks/NNBench-`hostname -s`";String commandLog="cat -b /root/NNBench_results.log |tail -n30";// ---------------------------------------------------------------------------------------// ------------------------------重复运行一个小作业10次,每次使用2个maps和1个reduces---------/*String commandStr="yarn jar /usr/hdp/2.3.2.0-2950/hadoop-mapreduce/hadoop-mapreduce-client-jobclient-2.7.1.2.3.2.0-2950-tests.jar mrbench -numRuns 10 -maps 2 -reduces 1";String commandLog="";//无日志文件,属于动态输出日志*///----------------------------------------------------------------------------------------CommandExecute(commandStr+" \n "+commandLog);//commandStr表示运行hadoop的命令,commandLog表示要输出的日志for (String str : stdout) { System.out.println(str); }lr.end_transaction("exe_command", lr.AUTO);return 0;}//end of actionpublic int end() throws Throwable {try{channel.disconnect();session.disconnect();}catch(Exception e){System.out.println(e);}return 0;}//end of end
}
以上脚本的核心部分是CommandExecute,通过ssh连接linux执行shell命令,一般情况下运行成功后会输出运行日志,但是hadoop基础测试包的调用有些日志是写到后台中的,所以可以通过加上cat -b /root/NNBench_results.log |tail -n30这样的命令(具体需要准确知道日志文件的所在路径),来输出当前执行成功后的日志(比如NNBench测试输出的最后30行就是当前日志)。
5、运行脚本,测试通过的输出如下所示:
6、对于Loadrunner通过C的方式远程连接linux,也是有方法的,具体可以参考别人的文章:
http://blog.csdn.net/hualusiyu/article/details/8530319
Loadrunner通过ssh连接linux进行hadoop基准测试相关推荐
- java使用ssh连接Linux并执行命令
maven pom.xml配置:<dependency><groupId>com.jcraft</groupId><artifactId>jsch< ...
- Python ssh连接Linux服务器报Incompatible ssh peer (no acceptable kex algorithm) 解决方法
Python ssh连接Linux服务器报Incompatible ssh peer (no acceptable kex algorithm) 解决方法 参考文章: (1)Python ssh连接L ...
- linux ssh抓包,如何在SSH连接Linux系统的环境下使用wireshark抓包?
TSINGSEE青犀视频云边端架构EasyNVR.EasyDSS.EasyGBS等都是有两种操作系统的版本,一种是linux,一种是windows.而大多数开发者用户都会使用linux版本进行安装. ...
- SSH连接Linux CentOS7-Putty篇
SSH连接Linux CentOS7-Putty篇 这是第一次使用Putty 利用SSH连接Linux.如果你想学习如何使用配置私钥在本地连接Linux服务器, 可以仔细阅读这篇文章,了解一下有关本地 ...
- wireshark linux远程,如何在SSH连接Linux的环境下使用wireshark抓包云边端架构?
原标题:如何在SSH连接Linux的环境下使用wireshark抓包云边端架构? TSINGSEE青犀视频云边端架构EasyNVR.EasyDSS.EasyGBS等都是有两种操作系统的版本,一种是li ...
- SSH连接linux时,长时间不操作就断开的解决方案(增强版)
SSH连接linux时,长时间不操作就断开的解决方案(增强版) 参考文章: (1)SSH连接linux时,长时间不操作就断开的解决方案(增强版) (2)https://www.cnblogs.com/ ...
- ssh连接Linux很慢,且ssh传输文件很慢的解决方案
ssh连接Linux很慢,且ssh传输文件很慢的解决方案 网上关于该问题的常用解决方法是(主要就是修改配置文件/etc/ssh/sshd_config): (1)修改"UseDNS" ...
- java实现连接linux,JAVA实现远道SSH连接linux并执行命令
JAVA实现远程SSH连接linux并执行命令 package com.codeconch.ssh; import java.io.BufferedReader; import java.io.IOE ...
- Window平台的eclipse连接linux的hadoop集群
前提条件:之前已经在VM上虚拟了三台linux,并且安装了hadoop集群 feixu-master, feixu-slave1, feixu-slave2, feixu-slave3 需求: 为了开 ...
最新文章
- 07-CA/TA编程:rsakey demo
- Spring Boot-@ImportResource注解
- TortoiseSVN版本管理的注意点
- Python+Selenium+Firefox配置,及可以启动浏览器,不能自动输入地址
- “精钢云”落地:鞍钢携手金山云推动中国制造
- HDU1215 七夕节【水题】
- ubuntu怎么设置linux的ip地址,linux,ubuntu设置ip
- 三层交换机VLAN间路由
- csss中box-sizing的问题 元素在另一个元素中框框包含的问题
- 安卓没有第三方rec获取root教程,成功率90%
- DIY_实现光敏电阻传感器简单控制LED
- 初步观察UE蓝图的“Branch节点”,这个最简单的K2Node的代码
- 神奇的Navigator对象
- /MD 与 /MT、/MTD与/MDD的区别
- Excel怎么快速截取图片?
- HuskyLens人工智能摄像头
- [韩国KBS][伟大的遗产]
- 判断Checkbox选中两种方法
- 分布式事务实现原理【BAT 面试题宝库附详尽答案解析】
- Python识别身份证号码并检查是否合法(pysseract,dlib,opencv)
热门文章
- 【mDNS】本地DNS解析协议
- WebApp本地存储 (离线缓存策略策略)
- getDimension,getDimensionPixelOffset和getDimensionPixelSize的一点说明
- DotNetTextBox V2.0 Web Control(ASP.NET2.0 增强型TextBox控件,完全支持AJAX.NET)
- 微信浏览器禁止app下载链接的两种处理方法
- (一)Linux基础(1)
- 浅谈Mybatis的一级缓存和二级缓存
- 怎么解决64位Access与32位不能同时安装的问题
- 获取ini内容 GetPrivateProfileString GetPrivateProfileInt
- poj2976 Dropping tests(01分数规划 好题)