使用loadrunner和HttpClient对163网站进行性能测试实验

xiaoxiao2021-03-01  8

使用loadrunner和HttpClient对163网站进行性能测试实验

-ldfu

1.在eclipse中使用httpclient连接www.163.com网站,如果返回结果OK则判断loadrunner事务成功否则事务失败。这是我写的java代码如下:

/ *

LoadRunner Java script

author:luodongfu

*/

import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;

import lrapi.lr;

import org.apache.http.HttpEntity;import org.apache.http.HttpResponse;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;

public class Actions{public int init() { return 0;}//end of init

public int action() { HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet("http://www.163.com/"); lr.log_message("executing request " + httpget.getURI()); lr.think_time(3); lr.rendezvous("requestTaobao"); lr.start_transaction("client taobao request"); HttpResponse response=null; try { response = httpclient.execute(httpget); } catch (Exception e) { lr.output_message(e.getMessage()); } lr.output_message("当前loadrunner请求IP:"+lr.get_host_name()+";控制器IP:"+lr.get_master_host_name()); lr.output_message("当前虚拟用户ID:"+lr.get_vuser_id()); lr.output_message("----------------------------------------"); lr.output_message(response.getStatusLine().toString()); lr.output_message("----------------------------------------");

HttpEntity entity = response.getEntity(); BufferedReader reader=null; if (entity != null) { lr.end_transaction("client taobao request", lr.PASS); try { reader = new BufferedReader( new InputStreamReader(entity.getContent())); String line=reader.readLine(); while(line!=null) { lr.output_message(reader.readLine()); line=reader.readLine(); } } catch (Exception e) { lr.output_message(e.getMessage()); } finally { try { reader.close(); } catch (IOException e) { } } } else { lr.end_transaction("client taobao request", lr.FAIL); }

return 0;}//end of action

public int end() { return 0;}//end of end}

2.使用loadrunner创建java vuser代码,将刚才在eclipse创建代码拷贝过来就可以了

3.设置loadrunner运行参数,这里最重要的设置java虚拟机的classpath;

5.在loadrunner中编译我们刚才拷贝的代码

6.运行我们的jvuser代码,结果没有问题,有163返回的东东了

7.创建场景,将一个人的量力变成你20个人的力量,20用户去请求

8.这里我们使用手工场景,最大用户为20

9.设置用户增加减少步数:

11.增加需要监控的参数图,开始监控,呵呵:

12.分析结果,准备分析性能了呵呵:

这个是随用户增加以及事务响应时间

剩下的事情就是我们开始分析了

相关资源:loadrunner性能测试用例模板
转载请注明原文地址: https://www.6miu.com/read-4150349.html

最新回复(0)