1. 程式人生 > >jmeter 壓測dubbo介面

jmeter 壓測dubbo介面

測試內容:

還原 dubbo 執行緒池耗盡的情況,定位是服務端還是消費端問題。

jmeter 測試程式碼:

RiskcoreThreatMetrix.java

  1. package riskcoreService;
  2. import com.test.riskcore.api.ThreatMetrixService;
  3. import com.test.riskcore.api.result.Result;
  4. import org.apache.jmeter.config.Arguments;
  5. import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient
    ;
  6. import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext;
  7. import org.apache.jmeter.samplers.SampleResult;
  8. import org.springframework.context.ApplicationContext;
  9. import org.springframework.context.support.ClassPathXmlApplicationContext;
  10. publicclassRiskcoreThreatMetrixextendsAbstractJavaSamplerClient
    {
  11. //載入 RechargeService
  12. privateApplicationContext context =newClassPathXmlApplicationContext("classpath:dubbo-client.xml");
  13. privateThreatMetrixService threatMetrixService =(ThreatMetrixService) context.getBean("threatMetrixService");
  14. //初始化操作
  15. @Override
  16. publicvoid setupTest(JavaSamplerContext arg0){
  17. }
  18. public org.apache
    .log.Logger getLogger(){
  19. returnsuper.getLogger();
  20. }
  21. /**
  22. * 設定預設值
  23. *
  24. * @return
  25. */
  26. @Override
  27. publicArguments getDefaultParameters(){
  28. returnnull;
  29. }
  30. publicSampleResult runTest(JavaSamplerContext javaSamplerContext){
  31. SampleResult sr =newSampleResult();
  32. sr.setSampleLabel("測試 dubbo 呼叫!!");
  33. sr.sampleStart();
  34. try{
  35. Result<String> result = threatMetrixService.getThreatMetrix();
  36. sr.setSuccessful(result.isSuccess());
  37. sr.setResponseMessage(result.getModel());
  38. sr.setResponseData("序列碼:"+ result.getModel(),null);
  39. }catch(Exception e){
  40. sr.setSuccessful(false);
  41. sr.setResponseData("dubbo 調取異常",null);
  42. getLogger().error(e.toString()+"====="+ e.getMessage()+"=====");
  43. e.printStackTrace();
  44. }finally{
  45. sr.setDataType(SampleResult.TEXT);
  46. sr.sampleEnd();
  47. }
  48. return sr;
  49. }
  50. @Override
  51. publicvoid teardownTest(JavaSamplerContext arg0){
  52. }
  53. /* 單元測試功能 */
  54. // public static void main(String[] args) {
  55. // Arguments arguments = new Arguments();
  56. //
  57. // JavaSamplerContext javaSamplerContex = new JavaSamplerContext(arguments);
  58. // RiskcoreThreatMetrix jMeter = new RiskcoreThreatMetrix();
  59. // jMeter.runTest(javaSamplerContex);
  60. // }
  61. }

測試說明:

jmeter 設定

執行緒數設定 80 個執行緒


定時器, 10 個執行緒一組同時併發


結果察看

測試結果日誌

消費者報錯: 業務日誌中


伺服器報錯: 伺服器日誌中