經(jīng)典的自然是loadrunner,可以進(jìn)行并發(fā)壓力測(cè)試,很實(shí)用,可以模擬多IP,多用戶同時(shí)運(yùn)行,可以設(shè)置運(yùn)行間隔,可以參考下相關(guān)的文檔,建議去csdn上下一個(gè)相關(guān)的教程
成都創(chuàng)新互聯(lián)公司成立與2013年,先為四平等服務(wù)建站,四平等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為四平企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。
選我吧。。絕對(duì)短小精悍!
思路:
壓力測(cè)試原理有兩種,一種是連接測(cè)試,一種是負(fù)載測(cè)試
1,連接測(cè)試,就是多線程,不停的請(qǐng)求直到服務(wù)器死機(jī)或達(dá)到預(yù)期效果即可!
2,負(fù)載測(cè)試,就是一個(gè)線程的多步操作,每個(gè)線程占用服務(wù)器cpu 內(nèi)存是否符合節(jié)能高效的標(biāo)準(zhǔn),如果不是,那就優(yōu)化吧
所有測(cè)試以額定用戶(最大用戶)為基礎(chǔ)
import?java.io.BufferedReader;
import?java.io.File;
import?java.io.FileInputStream;
import?java.io.InputStreamReader;
import?java.io.PrintWriter;
import?java.net.HttpURLConnection;
import?java.net.URL;
import?java.util.HashMap;
import?java.util.Map;
import?java.util.concurrent.ExecutorService;
import?java.util.concurrent.Executors;
import?java.util.concurrent.Semaphore;
public?class?ConcurrentTest?{
private?static?int?thread_num?=?200;
private?static?int?client_num?=?460;
private?static?Map?keywordMap?=?new?HashMap();
static?{
try?{
InputStreamReader?isr?=?new?InputStreamReader(new?FileInputStream(
new?File("clicks.txt")),?"GBK");
BufferedReader?buffer?=?new?BufferedReader(isr);
String?line?=?"";
while?((line?=?buffer.readLine())?!=?null)?{
keywordMap.put(line.substring(0,?line.lastIndexOf(":")),?"");
}
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
public?static?void?main(String[]?args)?{
int?size?=?keywordMap.size();
//?TODO?Auto-generated?method?stub
ExecutorService?exec?=?Executors.newCachedThreadPool();
//?50個(gè)線程可以同時(shí)訪問
final?Semaphore?semp?=?new?Semaphore(thread_num);
//?模擬2000個(gè)客戶端訪問
for?(int?index?=?0;?index??client_num;?index++)?{
final?int?NO?=?index;
Runnable?run?=?new?Runnable()?{
public?void?run()?{
try?{
//?獲取許可
semp.acquire();
System.out.println("Thread:"?+?NO);
String?host?=?"?";
String?para?=?"method=getQueryResultpageNum=1pageSize=5"
+?"queryKeyWord="
+?getRandomSearchKey(NO)
+?"questionID=-1questionIdPath=-1searchType=1"
+?"proLine=proSeries=proType="?+?NO;
System.out.println(host?+?para);
URL?url?=?new?URL(host);//?此處填寫供測(cè)試的url
HttpURLConnection?connection?=?(HttpURLConnection)?url
.openConnection();
//?connection.setRequestMethod("POST");
//?connection.setRequestProperty("Proxy-Connection",
//?"Keep-Alive");
connection.setDoOutput(true);
connection.setDoInput(true);
PrintWriter?out?=?new?PrintWriter(connection
.getOutputStream());
out.print(para);
out.flush();
out.close();
BufferedReader?in?=?new?BufferedReader(
new?InputStreamReader(connection
.getInputStream()));
String?line?=?"";
String?result?=?"";
while?((line?=?in.readLine())?!=?null)?{
result?+=?line;
}
//?System.out.println(result);
//?Thread.sleep((long)?(Math.random())?*?1000);
//?釋放
System.out.println("第:"?+?NO?+?"?個(gè)");
semp.release();
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
};
exec.execute(run);
}
//?退出線程池
exec.shutdown();
}
private?static?String?getRandomSearchKey(final?int?no)?{
String?ret?=?"";
int?size?=?keywordMap.size();
//?int?wanna?=?(int)?(Math.random())?*?(size?-?1);
ret?=?(keywordMap.entrySet().toArray())[no].toString();
ret?=?ret.substring(0,?ret.lastIndexOf("="));
System.out.println("\t"?+?ret);
return?ret;
}
}
使用loadrunner,進(jìn)行壓力測(cè)試,有比較詳細(xì)的測(cè)試結(jié)果,
就是配置和使用loadrunner比較麻煩,不過網(wǎng)上有詳細(xì)的教程,去下載一個(gè)吧,
自己寫循環(huán)去測(cè)試,極不準(zhǔn)確