Loadrunner通过ssh连接linux进行hadoop基准测试

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: Loadrunner通过ssh连接调用hadoop的测试Jar包进行基准测试,似乎有点讨巧,而且好像实际意义也不是特别大,但是通过这个方法的展示,能够看到Loadrunner的生命力有多大,而且在linux系统测试和开源技术的测试中,也是能够有用武之地,所以本文算是来个抛砖引玉吧。
版权声明:本文为博主原创文章,未经博主允许不得转载。欢迎访问我的博客 https://blog.csdn.net/smooth00/article/details/73796622

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 init

	public 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 action

	public 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


相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
18天前
|
监控 安全 Linux
如何利用Kali Linux进行网站渗透测试:最常用工具详解
如何利用Kali Linux进行网站渗透测试:最常用工具详解
53 6
|
18天前
|
安全 Linux 测试技术
Kali Linux预装的自动化渗透测试工具
Kali Linux预装的自动化渗透测试工具
28 2
|
23天前
|
NoSQL Linux Android开发
内核实验(三):编写简单Linux内核模块,使用Qemu加载ko做测试
本文介绍了如何在QEMU中挂载虚拟分区、创建和编译简单的Linux内核模块,并在QEMU虚拟机中加载和测试这些内核模块,包括创建虚拟分区、编写内核模块代码、编译、部署以及在QEMU中的加载和测试过程。
81 0
内核实验(三):编写简单Linux内核模块,使用Qemu加载ko做测试
|
23天前
|
Linux 网络安全
Linux开启ssh
Linux开启ssh
31 0
|
23天前
|
Linux 网络安全 网络架构
如何处理在学校Linux连接不上服务器
如何处理在学校Linux连接不上服务器
34 0
|
28天前
|
缓存 NoSQL Linux
【Azure Redis 缓存】Linux VM使用6380端口(SSL方式)连接Azure Redis (redis-cli & stunnel)
【Azure Redis 缓存】Linux VM使用6380端口(SSL方式)连接Azure Redis (redis-cli & stunnel)
|
28天前
|
网络协议 Linux
在Linux中,如何查看 http 的并发请求数与其 TCP 连接状态?
在Linux中,如何查看 http 的并发请求数与其 TCP 连接状态?
|
28天前
|
安全 Linux 网络安全
在Linux中,使用rsync同步数据时,假如采用的是ssh方式,并且目标机器的sshd端端并不是默认的22端口,该如何做?
在Linux中,使用rsync同步数据时,假如采用的是ssh方式,并且目标机器的sshd端端并不是默认的22端口,该如何做?
|
8天前
|
移动开发 JSON Java
Jmeter实现WebSocket协议的接口测试方法
WebSocket协议是HTML5的一种新协议,实现了浏览器与服务器之间的全双工通信。通过简单的握手动作,双方可直接传输数据。其优势包括极小的头部开销和服务器推送功能。使用JMeter进行WebSocket接口和性能测试时,需安装特定插件并配置相关参数,如服务器地址、端口号等,还可通过CSV文件实现参数化,以满足不同测试需求。
53 7
Jmeter实现WebSocket协议的接口测试方法
|
8天前
|
JSON 移动开发 监控
快速上手|HTTP 接口功能自动化测试
HTTP接口功能测试对于确保Web应用和H5应用的数据正确性至关重要。这类测试主要针对后台HTTP接口,通过构造不同参数输入值并获取JSON格式的输出结果来进行验证。HTTP协议基于TCP连接,包括请求与响应模式。请求由请求行、消息报头和请求正文组成,响应则包含状态行、消息报头及响应正文。常用的请求方法有GET、POST等,而响应状态码如2xx代表成功。测试过程使用Python语言和pycurl模块调用接口,并通过断言机制比对实际与预期结果,确保功能正确性。
35 3
快速上手|HTTP 接口功能自动化测试