这篇文章主要介绍“python单链路性能测试实例分析”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“python单链路性能测试实例分析”文章能帮助大家解决问题。
场景就是老师登录,首先会请求一个知识点列表,然后通过知识点属性筛选推荐课程列表,在对课程列表中的数据进行收藏和取消收藏,在获取自己当前知识点下的课程列表(包含原创和收藏)。
本次依然采取固定线程的压测模型,本人预估线程200左右,测试用户600备用,列表页保证2页数据。
每个线程绑定一个用户,然后用户开始循环链路执行步骤,执行一次当做一次Q
。单次Q
包含9次HTTP
接口请求(放弃了Socket
接口,以后有需求再添加Socket
接口到链路中),其中3次修改操作,6次查询操作。
具体的逻辑通过内部静态类实现,然后多一个K
类,用来存储每次获取的知识点属性,方便调用。由于接口请求方法都是用基础数据类型和String
作为参数,所以调用时候会显得有点啰嗦。但无伤大雅,脚本写出来,本来就是用完就扔到仓库里面,改天再用再优化。
package com.okayqa.composer.performance.resource1_4
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.funtester.base.bean.AbstractBean
import com.funtester.base.constaint.ThreadLimitTimesCount
import com.funtester.frame.execute.Concurrent
import com.funtester.httpclient.ClientManage
import com.funtester.utils.ArgsUtil
import com.okayqa.composer.base.OkayBase
import com.okayqa.composer.function.Mirro
import com.okayqa.composer.function.OKClass
class Login_collect_uncollect extends OkayBase {
public static void main(String[] args) {
ClientManage.init(10, 5, 0, "", 0)
def util = new ArgsUtil(args)
def thread = util.getIntOrdefault(0, 30)
def times = util.getIntOrdefault(1, 40)
def tasks = []
thread.times {
tasks << new FunTester(it, times)
}
new Concurrent(tasks, "资源库1.4登录>查询>收藏>取消收藏链路压测").start()
allOver()
}
private static class FunTester extends ThreadLimitTimesCount<Integer> {
OkayBase base
def mirro
def clazz
FunTester(Integer integer, int times) {
super(integer, times, null)
}
@Override
void before() {
super.before()
base = getBase(t)
mirro = new Mirro(base)
clazz = new OKClass(base)
}
@Override
protected void doing() throws Exception {
def klist = mirro.getKList()</code><code> mirro.getKList()
def karray = klist.getJSONArray("data")
K ks
karray.each {
JSONObject parse = JSON.parse(JSON.toJSONString(it))
if (ks == null) {
def level = parse.getIntValue("node_level")
def type = parse.getIntValue("ktype")
def id = parse.getIntValue("id")
ks = new K(id, type, level)
}
}
JSONObject response = clazz.recommend(ks.id, ks.type, ks.level)</code><code> clazz.recommend(ks.id, ks.type, ks.level) clazz.recommend(ks.id, ks.type, ks.level)
def minis = []
int i = 0
response.getJSONArray("data").each {
if (i++ < 2) {
JSONObject parse = JSON.parse(JSON.toJSONString(it))
int value = parse.getIntValue("minicourse_id")
minis << value
}
}
clazz.unCollect(random(minis))
mirro.getMiniCourseListV3(ks.id, ks.type, 0, ks.level) mirro.getMiniCourseListV3(ks.id, ks.type, 0, ks.level)
}
}
private static class K extends AbstractBean {
int id
int type
int level
K(int id, int type, int level) {
this.id = id
this.type = type
this.level = level
}
}
}
其中AbstractBean
类是一个抽象类,用于一些bean
的方法封装,就是为了省事儿。
package com.funtester.base.bean
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.funtester.frame.Save
import com.funtester.frame.SourceCode
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.BeanUtils
/**
* bean的基类
*/
abstract class AbstractBean {
static final Logger logger = LoggerFactory.getLogger(AbstractBean.class)
/**
* 将bean转化为json,为了进行数据处理和打印
*
* @return
*/
JSONObject toJson() {
JSONObject.parseObject(JSONObject.toJSONString(this))
}
/**
* 文本形式保存
*/
def save() {
Save.saveJson(this.toJson(), this.getClass().toString() + SourceCode.getMark());
}
/**
* 控制台打印,使用WARN记录,以便查看
*/
def print() {
logger.warn(this.getClass().toString() + ":" + this.toString());
}
def initFrom(String str) {
JSONObject.parseObject(str, this.getClass())
}
def initFrom(Object str) {
initFrom(JSON.toJSONString(str))
}
def copyFrom(AbstractBean source) {
BeanUtils.copyProperties(source, this)
}
def copyTo(AbstractBean target) {
BeanUtils.copyProperties(this, target)
}
/**
* 这里bean的属性必需是可以访问的,不然会返回空json串
* @return
*/
@Override
String toString() {
JSONObject.toJSONString(this)
}
@Override
protected Object clone() {
initFrom(this)
}
}
~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~ JSON ~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~
> {
> ① . "rt":1665,
> ① . "total":1188,
> ① . "qps":18.018,
> ① . "failRate":0.0,
> ① . "threads":30,
> ① . "startTime":"2021-02-24 16:57:23",
> ① . "endTime":"2021-02-24 16:58:34",
> ① . "errorRate":1.01,
> ① . "executeTotal":1188,
> ① . "mark":"资源库1.4登录>查询>收藏>取消收藏链路压测241657",
> ① . "table":"eJzj5VLAD15sbXm2a8LTXZMN9Uyez9z9dO9Uu2fzl75Yv8ju2ZRtL6b32z3tn/ZsWweE83Lyvhfb1z/t6362tZvT2EChJKMoNaWYgA0KvFy8+F0RlFpckJ9XnKoQkpmbaqVQoVucWpSZmKOQV5qro1Cpm5uakpmYR8gOQq5QyM3MU4AYZWVhYqmQW6yTm1hhZWxoaQxkE9RNjA2UgEfTOoBo1JZRW2hmRSsQ0ccmsBW0tgnVQzS1DatVtLMRn3W0sPXRtCYgAlLtQITXWura/mhaMxCRYC+VXUGyv2nhmkfTGoGI0rCgrsseTWsBImLSIZ1dCA8sOjmMXNfCU9ZAupNYV8MdC4106qdA2vkAniAGq6OJ8AlVi6GB99FgSvTU8BU8egaBg6jsO3iWHwSuoZUPB4EzRn046sNRHw68M0Z9OOrDEe5DABkr1eo="
> }
~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~ JSON ~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~~☢~
关于“python单链路性能测试实例分析”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识,可以关注亿速云行业资讯频道,小编每天都会为大家更新不同的知识点。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。