51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2017|回复: 2
打印 上一主题 下一主题

性能测试 - Locust dubbo client

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2019-3-22 16:32:51 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Locust dubbo客户端实现
  1. # _*_ coding:utf-8 _*_

  2. '''
  3. Locust dubbo client
  4. Max.Bai
  5. 2018-08
  6. '''


  7. import time
  8. import random
  9. import json
  10. import socket
  11. import dubbo_telnet
  12. import requests
  13. from locust import Locust, TaskSet, events, task


  14. class DubboClient(object):
  15.     def __init__(self, host, port):
  16.         self.conn = dubbo_telnet.connect(host, port)
  17.         self.conn.set_connect_timeout(10)

  18.     def do(self,msg):
  19.         start_time = time.time()
  20.         try:
  21.             self.conn.do(msg)
  22.         except Exception as e:
  23.             total_time = int((time.time() - start_time) * 1000)
  24.             events.request_failure.fire(request_type="dubbo", name="start", response_time=total_time, exception=e)
  25.         else:
  26.             total_time = int((time.time() - start_time) * 1000)
  27.             events.request_success.fire(request_type="dubbo", name="start", response_time=total_time, response_length=0)



  28. class DubboLocust(Locust):
  29.     """
  30.     This is the abstract Locust class which should be subclassed. It provides an dubbo client
  31.     that can be used to make dubbo requests that will be tracked in Locust's statistics.
  32.     """
  33.     def __init__(self, *args, **kwargs):
  34.         super(DubboLocust, self).__init__(*args, **kwargs)
  35.         self.client = DubboClient(self.host, self.port)



  36. class TestUser(DubboLocust):

  37.     host = "119.29.67.113"
  38.     port = 20904
  39.     min_wait = 2000
  40.     max_wait = 2000

  41.     class task_set(TaskSet):
  42.         @task
  43.         def send_data1(self):
  44.             msg = 'invoke com.abc.com.base.service.faceattendance.abcService.action("parm1", "parm2", "parm3")'
  45.             response = self.client.do(msg)
  46.             print "recv:%s"%str(response)


  47. if __name__ == "__main__":
  48.     user = TestUser()
  49.     user.run()
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏1
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-22 03:24 , Processed in 0.065554 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表