您的位置:軟件測(cè)試 > 開源軟件測(cè)試 > 開源性能測(cè)試工具 > Jmeter
使用JMeter的Java請(qǐng)求功能測(cè)試Hetty性能
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2013/11/22 17:30:39 ] 推薦標(biāo)簽:
  1JMeter介紹
  JMeter是Apache組織的開放源代碼項(xiàng)目,它是功能和性能測(cè)試的工具,的用java實(shí)現(xiàn)。JMeter可以用于測(cè)試靜態(tài)或者動(dòng)態(tài)資源的性能(文件、Servlets、Perl腳本、java對(duì)象、數(shù)據(jù)庫(kù)和查詢、ftp服務(wù)器或者其他的資源)。JMeter用于模擬在服務(wù)器、網(wǎng)絡(luò)或者其他對(duì)象上附加高負(fù)載以測(cè)試他們提供服務(wù)的受壓能力,或者分析他們提供的服務(wù)在不同負(fù)載條件下的總性能情況。
  2.啟動(dòng)JMeter
  進(jìn)入JMeter的bin目錄,然后執(zhí)行:
  sudo ./jmeter.sh
  3.原始的測(cè)試方法
在沒有使用JMeter前,我對(duì)hetty的性能測(cè)試,都是通過(guò)自己寫多線程代碼去完成的,相當(dāng)苦逼,相當(dāng)麻煩,不過(guò)也能鍛煉自己的編碼能力,我先貼出比較原始的測(cè)試方法,如下:
public class RpcHessianClient {
public static void main(String[] args) {
String url = "http://localhost:8081/apis/hello";
HessianProxyFactory factory = new HessianProxyFactory();
ExecutorService es = Executors.newFixedThreadPool(10);
int size = 1000000;
final CountDownLatch cdl = new CountDownLatch(size);
try {
long start = System.currentTimeMillis();
factory.setUser("client1");
factory.setPassword("client1");
factory.setOverloadEnabled(true);
final Hello basic = (Hello) factory.create(Hello.class,
url);
for (int i = 0; i < size; i++) {
es.submit(new Runnable() {
@Override
public void run() {
String u=basic.hello("guolei");
//System.out.println(u);
cdl.countDown();
}
});
}
cdl.await();
long time = System.currentTimeMillis() - start;
System.out.println("SayHello:");
System.out.println("耗時(shí):" + (double) time / 1000 + " s");
System.out.println("平均:" + ((double) time) / size +" ms");
System.out.println("TPS:" + (double) size / ((double) time / 1000));
// System.out.println("Hello, " + s.getMail());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
es.shutdown();
}
}
上一頁(yè)123下一頁(yè)
軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd