Jmeter實現dubbo接口壓測案例


當前項目中重構了消息服務,需要對消息服務接口做性能壓測,評估消息服務的性能情況

通過和開發對接,目前消息服務是通過dubbo接口對內提供服務,所以才有了這邊文章的記錄

最初的壓測這個dubbo接口有三種思路:

1.第一種就是基於業務,比如注冊業務,注冊成功后,會發送短信消息到用戶手機,通過業務調用消息服務,最容易實現,但是業務瓶頸最大導致測試結果不准

2.第二種是通過將dubbo接口上面做一層包裝,提供一個http接口訪問dubbo接口,需要提供二次開發,需要時間,而且高並發下,需要部署在tomcat容器內部

3.就是直接壓測dubbo接口,這種測試的結果最准確,目前有開源的jmeter plguin sampler插件使用

下面講解怎么使用jmeter-plugins-dubbo做接口測試

 

第一步:

源碼下載:https://github.com/dubbo/jmeter-plugins-dubbo

https://github.com/ningyu1/jmeter-plugins-dubbo/tree/master/dist   jar下載地址

注意:

jmeter-plugins-dubbo使用

下載提供2種版本:

A. 第一種版本是jmeter-plugins-dubbo-1.3.8-jar-with-dependencies.jar類似帶有with-dependencies的jar是包含一些基礎包,建議下載這個

B. 第二種是不帶依賴包的版本,例如jmeter-plugins-dubbo-1.3.8-SNAPSHOT.jar。然后獲取以下依賴包,將它們放到jmeter安裝目錄下的lib/ext。如果是項目中使用報錯,或者dubbo版本不是2.X版本的,建議下載這個

gson-2.8.2.jar

dubbo-2.8.4.jar  

javassist-3.21.0-GA.jar

jline-0.9.94.jar

log4j-over-slf4j-1.7.5.jar

netty-3.7.0.Final.jar

slf4j-api-1.7.5.jar

zkclient-0.2.jar

zookeeper-3.4.9.jar

 

第二步:

將下載的https://raw.githubusercontent.com/ningyu1/jmeter-plugins-dubbo/master/dist/jmeter-plugins-dubbo-1.3.8.jar

放在jar文件JMETER_HOME/lib/ext目錄下

然后啟動Jmeter

添加Dubbo Sampler配置如下

直接調用后,報錯如下:

2019-01-17 14:22:49,051 ERROR i.g.n.j.p.d.s.DubboSample: RpcException:

com.alibaba.dubbo.rpc.RpcException: Failfast invoke providers dubbo://172.20.20.115:6001/com.neo.xnol.uaccount.facade.UserPersonQueryFacade?accepts=1024&accesslog=true&anyhost=true&application=DubboSample&async=false&charset=UTF-8&check=false&cluster=failfast&connections=100&default.cluster=failfast&default.delay=-1&default.loadbalance=leastactive&default.timeout=30000&default.version=2.0.0&delay=-1&dubbo=1.2.1-SNAPSHOT&generic=true&interface=com.neo.xnol.uaccount.facade.UserPersonQueryFacade&loadbalance=leastactive&methods=isPaymentPwdExist,getByMobile,getIdListByBirthday,isRealNameAuthByUserName,isRealNameAuth,isMobileExist,getTotalRegisteCount,getUserIdByRegisteTime,getByUserNameOrMobileOrEmail,isUserNameExist,getById,getByUserNameList,getUserForDistributed,getByIdCardNo,existElectronicSign,getByUserName,getByUserIdList,getUserByBeginIdAndCount,getByIdOrUserNameOrMobileOrEmail,getByEmail,getByUserNo,checkUserExist,isEmailExist,countUserRegister,getUserWithIDCardDistributed,getByUserNameOrMobile,isIdCardNoExist,getListByBeginIdAndCount&pid=87444&protocol=dubbo&register.ip=172.20.17.65&remote.timestamp=1547636861571&retries=0&revision=2.130.0-SNAPSHOT&side=consumer&timeout=30000&timestamp=1547706009472&version=2.0.0 LeastActiveLoadBalance select from all providers [com.alibaba.dubbo.registry.integration.RegistryDirectory$InvokerDelegate@611a4f9e] for service com.alibaba.dubbo.rpc.service.GenericService method $invoke on consumer 172.20.17.65 use dubbo version 1.3.8-jar-with-dependencies, but no luck to perform the invocation. Last error is: Failed to invoke remote method: $invoke, provider: dubbo://172.20.20.115:6001/com.neo.xnol.uaccount.facade.UserPersonQueryFacade?accepts=1024&accesslog=true&anyhost=true&application=DubboSample&async=false&charset=UTF-8&check=false&cluster=failfast&connections=100&default.cluster=failfast&default.delay=-1&default.loadbalance=leastactive&default.timeout=30000&default.version=2.0.0&delay=-1&dubbo=1.2.1-SNAPSHOT&generic=true&interface=com.neo.xnol.uaccount.facade.UserPersonQueryFacade&loadbalance=leastactive&methods=isPaymentPwdExist,getByMobile,getIdListByBirthday,isRealNameAuthByUserName,isRealNameAuth,isMobileExist,getTotalRegisteCount,getUserIdByRegisteTime,getByUserNameOrMobileOrEmail,isUserNameExist,getById,getByUserNameList,getUserForDistributed,getByIdCardNo,existElectronicSign,getByUserName,getByUserIdList,getUserByBeginIdAndCount,getByIdOrUserNameOrMobileOrEmail,getByEmail,getByUserNo,checkUserExist,isEmailExist,countUserRegister,getUserWithIDCardDistributed,getByUserNameOrMobile,isIdCardNoExist,getListByBeginIdAndCount&pid=87444&protocol=dubbo&register.ip=172.20.17.65&remote.timestamp=1547636861571&retries=0&revision=2.130.0-SNAPSHOT&side=consumer&timeout=30000&timestamp=1547706009472&version=2.0.0, cause: ooh.bravo.zodiac.rpc.RpcException: Failed to invoke remote proxy method $invoke to registry://s1.af88.com.cn:2181/ooh.bravo.zodiac.registry.RegistryService?application=User_RPC_Server&backup=s2.af88.com.cn:2181,s3.af88.com.cn:2181&dubbo=1.2.1-SNAPSHOT&export=dubbo://172.20.20.115:6001/com.neo.xnol.uaccount.facade.UserPersonQueryFacade?accepts=1024&accesslog=true&anyhost=true&application=User_RPC_Server&charset=UTF-8&default.cluster=failfast&default.delay=-1&default.loadbalance=leastactive&default.timeout=30000&default.version=2.0.0&delay=-1&dubbo=1.2.1-SNAPSHOT&interface=com.neo.xnol.uaccount.facade.UserPersonQueryFacade&methods=isPaymentPwdExist,getByMobile,getIdListByBirthday,isRealNameAuthByUserName,isRealNameAuth,isMobileExist,getTotalRegisteCount,getUserIdByRegisteTime,getByUserNameOrMobileOrEmail,isUserNameExist,getById,getByUserNameList,getUserForDistributed,getByIdCardNo,existElectronicSign,getByUserName,getByUserIdList,getUserByBeginIdAndCount,getByIdOrUserNameOrMobileOrEmail,getByEmail,getByUserNo,checkUserExist,isEmailExist,countUserRegister,getUserWithIDCardDistributed,getByUserNameOrMobile,isIdCardNoExist,getListByBeginIdAndCount&monitor=dubbo://s1.af88.com.cn:2181/ooh.bravo.zodiac.registry.RegistryService?application=User_RPC_Server&backup=s2.af88.com.cn:2181,s3.af88.com.cn:2181&dubbo=1.2.1-SNAPSHOT&file=/data/dubbo/cache/user_app_remoting.cache&pid=56&protocol=registry&refer=dubbo=1.2.1-SNAPSHOT&interface=ooh.bravo.zodiac.monitor.MonitorService&pid=56&timestamp=1547636861608&registry=zookeeper&timestamp=1547636861571&version=0.0.1&pid=56&revision=2.130.0-SNAPSHOT&side=provider&timestamp=1547636861571&file=/data/dubbo/cache/user_app_remoting.cache&pid=56&registry=zookeeper&timestamp=1547636861571&version=0.0.1, cause: Not found method "$invoke" in class com.neo.xnol.uaccount.facade.UserPersonQueryFacadeImpl.

ooh.bravo.zodiac.rpc.RpcException: Failed to invoke remote proxy method $invoke to registry://s1.af88.com.cn:2181/ooh.bravo.zodiac.registry.RegistryService?application=User_RPC_Server&backup=s2.af88.com.cn:2181,s3.af88.com.cn:2181&dubbo=1.2.1-SNAPSHOT&export=dubbo://172.20.20.115:6001/com.neo.xnol.uaccount.facade.UserPersonQueryFacade?accepts=1024&accesslog=true&anyhost=true&application=User_RPC_Server&charset=UTF-8&default.cluster=failfast&default.delay=-1&default.loadbalance=leastactive&default.timeout=30000&default.version=2.0.0&delay=-1&dubbo=1.2.1-SNAPSHOT&interface=com.neo.xnol.uaccount.facade.UserPersonQueryFacade&methods=isPaymentPwdExist,getByMobile,getIdListByBirthday,isRealNameAuthByUserName,isRealNameAuth,isMobileExist,getTotalRegisteCount,getUserIdByRegisteTime,getByUserNameOrMobileOrEmail,isUserNameExist,getById,getByUserNameList,getUserForDistributed,getByIdCardNo,existElectronicSign,getByUserName,getByUserIdList,getUserByBeginIdAndCount,getByIdOrUserNameOrMobileOrEmail,getByEmail,getByUserNo,checkUserExist,isEmailExist,countUserRegister,getUserWithIDCardDistributed,getByUserNameOrMobile,isIdCardNoExist,getListByBeginIdAndCount&monitor=dubbo://s1.af88.com.cn:2181/ooh.bravo.zodiac.registry.RegistryService?application=User_RPC_Server&backup=s2.af88.com.cn:2181,s3.af88.com.cn:2181&dubbo=1.2.1-SNAPSHOT&file=/data/dubbo/cache/user_app_remoting.cache&pid=56&protocol=registry&refer=dubbo=1.2.1-SNAPSHOT&interface=ooh.bravo.zodiac.monitor.MonitorService&pid=56&timestamp=1547636861608&registry=zookeeper&timestamp=1547636861571&version=0.0.1&pid=56&revision=2.130.0-SNAPSHOT&side=provider&timestamp=1547636861571&file=/data/dubbo/cache/user_app_remoting.cache&pid=56&registry=zookeeper&timestamp=1547636861571&version=0.0.1, cause: Not found method "$invoke" in class com.neo.xnol.uaccount.facade.UserPersonQueryFacadeImpl.

at ooh.bravo.zodiac.rpc.proxy.AbstractProxyInvoker.invoke(AbstractProxyInvoker.java:59)

at ooh.bravo.zodiac.rpc.protocol.InvokerWrapper.invoke(InvokerWrapper.java:35)

at ooh.bravo.zodiac.rpc.filter.ExceptionFilter.invoke(ExceptionFilter.java:35)

at ooh.bravo.zodiac.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:78)

at ooh.bravo.zodiac.monitor.support.MonitorFilter.invoke(MonitorFilter.java:40)

at ooh.bravo.zodiac.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:78)

at ooh.bravo.zodiac.rpc.filter.ContextFilter.invoke(ContextFilter.java:36)

at ooh.bravo.zodiac.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:78)

at ooh.bravo.zodiac.rpc.filter.DynamicLinkTrackingFilter.invoke(DynamicLinkTrackingFilter.java:57)

at ooh.bravo.zodiac.rpc.protocol.ProtocolFilterWrapper$1.invoke(ProtocolFilterWrapper.java:78)

 

是不是看到這里已經懵逼了啊。哈哈,既然出現了問題,那么就要學着分析:首先查看這個接口的實際調用的參數咋樣:

通過dubbo默認提供的invoke指令查看:

 

方法也存在,那么繼續查看這個方法的dubbo調用參數

ls -l

url轉碼后:

com.neo.xnol.uaccount.facade.UserPersonQueryFacade -> dubbo://172.20.20.115:6001/com.neo.xnol.uaccount.facade.UserPersonQueryFacade?accepts=1024&accesslog=true&anyhost=true&application=User_RPC_Server&charset=UTF-8&default.cluster=failfast&default.delay=-1&default.loadbalance=leastactive&default.timeout=30000&default.version=2.0.0&delay=-1&dubbo=1.2.1-SNAPSHOT&interface=com.neo.xnol.uaccount.facade.UserPersonQueryFacade&methods=isPaymentPwdExist,getByMobile,getIdListByBirthday,isRealNameAuthByUserName,isRealNameAuth,isMobileExist,getTotalRegisteCount,getUserIdByRegisteTime,getByUserNameOrMobileOrEmail,isUserNameExist,getById,getByUserNameList,getUserForDistributed,getByIdCardNo,existElectronicSign,getByUserName,getByUserIdList,getUserByBeginIdAndCount,getByIdOrUserNameOrMobileOrEmail,getByEmail,getByUserNo,checkUserExist,isEmailExist,countUserRegister,getUserWithIDCardDistributed,getByUserNameOrMobile,isIdCardNoExist,getListByBeginIdAndCount&monitor=dubbo://s1.af88.com.cn:2181/ooh.bravo.zodiac.registry.RegistryService?application=User_RPC_Server&backup=s2.af88.com.cn:2181,s3.af88.com.cn:2181&dubbo=1.2.1-SNAPSHOT&file=/data/dubbo/cache/user_app_remoting.cache&pid=56&protocol=registry&refer=dubbo=1.2.1-SNAPSHOT&interface=ooh.bravo.zodiac.monitor.MonitorService&pid=56&timestamp=1547636861608&registry=zookeeper&timestamp=1547636861571&version=0.0.1&pid=56&revision=2.130.0-SNAPSHOT&side=provider&timestamp=1547636861571

 

通過查看和對比,參數也沒錯,然后嘗試直連,還是報錯:

通過下載這個插件的源碼和項目中的dubbo分析以及報錯日志分析發現插件用的是dubbo的泛化調用, 而報錯日志顯示的是獲取不到泛化對象 ,

通過對比發現是因為項目中的dubbo版本是用的2.5.4,但是在源碼的基礎上做了閹割,去掉了一部分功能,剛好去掉了jmeter插件使用到的dubbo的泛化調用特性,導致一直報錯

通過修改原始插件,通過重寫插件調用dubbo接口的調用方式后問題解決,如果外面的其他引入完整的dubbo源碼項目,基本不會遇見這種問題

重新運行結果:

這個接口實現的業務

 

通過zk連接:

 

問題解決了

 

那么再來看這個消息服務的案例:

 

zk的方式:

 

 

 

 

難點就是這個參數類型怎么獲取呢

簡單吧,哈哈

其他案例:

 

 

常用參數類型匯總

 

首先拿到dubbo接口后,需要判斷dubbo接口是否可用,我們怎么調試呢?可以通過dubbo默認提供的invoke指令調用,案例實戰:

dubbo服務發布之后,我們可以利用telnet命令進行調試、管理。
Dubbo2.0.5以上版本服務提供端口支持telnet命令,下面我以通過實例拋磚引玉一下:

1.連接服務

測試對應IP和端口下的dubbo服務是否連通,cmd命令如下

telnet localhost 20880

正常情況下,進入telnet窗口,鍵入回車進入dubbo命令模式。

2.查看服務列表

查看服務ls

查看服務中的接口

ls

(list services and methods)

ls

顯示服務列表。

ls -l

顯示服務詳細信息列表。

ls XxxService

顯示服務的方法列表。

ls -l XxxService

顯示服務的方法詳細信息列表。

3.調用服務接口

調用接口時,以JSON格式傳入參數(這點很方便 :-D),然后打印返回值和所用時間。

invoke

invoke XxxService.xxxMethod({"prop": "value"})

調用服務的方法。

invoke xxxMethod({"prop": "value"})

調用服務的方法(自動查找包含此方法的服務)。

4.查看服務狀態 

查看服務調用次數,不過比較奇怪的是,我剛才已經調用過一次queryDemoPageList 了,而這里顯示的為0(貌似不太准,有待進一步了解)

count

count XxxService

統計1次服務任意方法的調用情況。

count XxxService 10

統計10次服務任意方法的調用情況。

count XxxService xxxMethod

統計1次服務方法的調用情況。

count XxxService xxxMethod 10

統計10次服務方法的調用情況。

status

status

顯示匯總狀態,該狀態將匯總所有資源的狀態,當全部OK時則顯示OK,只要有一個ERROR則顯示ERROR,只要有一個WARN則顯示WARN。

status -l

顯示狀態列表。

 

比如,當前有個接口,獲取當前系統的注冊用戶數的dubbo接口,我們可以先通過invoke指令驗證

telnet 172.20.20.115 6001  這里說明,172.20.20.115是我們的dubbo服務地址,6001是user服務的端口

接口調用結果

 

參考:

https://blog.csdn.net/cyjs1988/article/details/84258046

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM