jmeter 壓測dubbo介面
阿新 • • 發佈:2019-02-02
測試內容:
還原 dubbo 執行緒池耗盡的情況,定位是服務端還是消費端問題。
jmeter 測試程式碼:
RiskcoreThreatMetrix.java
package riskcoreService;
import com.test.riskcore.api.ThreatMetrixService;
import com.test.riskcore.api.result.Result;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient
import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
import org.apache.jmeter.samplers.SampleResult;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
publicclassRiskcoreThreatMetrixextendsAbstractJavaSamplerClient
//載入 RechargeService
privateApplicationContext context =newClassPathXmlApplicationContext("classpath:dubbo-client.xml");
privateThreatMetrixService threatMetrixService =(ThreatMetrixService) context.getBean("threatMetrixService");
//初始化操作
@Override
publicvoid setupTest(JavaSamplerContext arg0){
}
public org.apache
returnsuper.getLogger();
}
/**
* 設定預設值
*
* @return
*/
@Override
publicArguments getDefaultParameters(){
returnnull;
}
publicSampleResult runTest(JavaSamplerContext javaSamplerContext){
SampleResult sr =newSampleResult();
sr.setSampleLabel("測試 dubbo 呼叫!!");
sr.sampleStart();
try{
Result<String> result = threatMetrixService.getThreatMetrix();
sr.setSuccessful(result.isSuccess());
sr.setResponseMessage(result.getModel());
sr.setResponseData("序列碼:"+ result.getModel(),null);
}catch(Exception e){
sr.setSuccessful(false);
sr.setResponseData("dubbo 調取異常",null);
getLogger().error(e.toString()+"====="+ e.getMessage()+"=====");
e.printStackTrace();
}finally{
sr.setDataType(SampleResult.TEXT);
sr.sampleEnd();
}
return sr;
}
@Override
publicvoid teardownTest(JavaSamplerContext arg0){
}
/* 單元測試功能 */
// public static void main(String[] args) {
// Arguments arguments = new Arguments();
//
// JavaSamplerContext javaSamplerContex = new JavaSamplerContext(arguments);
// RiskcoreThreatMetrix jMeter = new RiskcoreThreatMetrix();
// jMeter.runTest(javaSamplerContex);
// }
}
測試說明:
jmeter 設定
執行緒數設定 80 個執行緒
定時器, 10 個執行緒一組同時併發
結果察看
測試結果日誌
消費者報錯: 業務日誌中
伺服器報錯: 伺服器日誌中