首页 > 其他分享 >Locust性能测试设置持续时间(web-UI)

Locust性能测试设置持续时间(web-UI)

时间:2024-04-30 16:33:06浏览次数:13  
标签:web locust self Locust t1 UI startTime time print

jemter的线程组可以设置调度器的持续时间,这样如压测1分钟,半小时,一个小时就非常方便

 但我们想要设定locust持续运行时间,web-UI 页面是不支持的。解决办法有2个,主要讲第二个:

1、通过命令行的方式来启动,我们可以配置locust启动配置参数,参考 https://blog.csdn.net/weixin_45805339/article/details/121167157   https://blog.csdn.net/arron_12/article/details/130086390

核心配置如下,然后通过命令行 后台运行,时间到了停止。

locustfile = LocustScripts/taskCenter/api_xxx_query.py #功能脚本文件路径
logfile = Logs/infoLog.log # 日志文件路径
loglevel = debug # 日志等级
web-port = 8089 #web页面端口,设置默认时间可忽略该端口
host = https://xxxtest.com #待测服务器地址
headless = true # # 禁用web界面,并立即开始测试。使用-u和-t来控制用户数量和运行时间
user = 1 # 并发用户的峰值数
spawn-rate = 1 # 生成用户的速率(用户每秒)。主要与-headless或-autostart一起使用
run-time = 10s # locust运行时间 (300s、20m、3h、1h30m)

2、那么我们想在web-UI上点,又不想整配置,还想设置持续时间,怎么办?(我喜欢)

整个思路:首先需要一个计时器,简单点,读秒的那种

# 秒表计时,到时间返回t1
def time_meter(sec):
    t1=0
    while True:
        startTime=time.time()
        print(startTime)
        print('开始')
        while True:
            t1=round(time.time()-startTime,0)
            print('计时:' + str(t1) + '秒')
            time.sleep(1)
            if t1==sec:
                print('我要整点啥')
                break
        break
    return t1
print((time_meter(20)))

几行拙劣的代码搞定。

运行结果:

 然后整点啥呢?到时间停止运行locust,查看api文档,get http://localhost:8089/stop 就能停止

# 秒表计时,到时间返回t1
def time_meter(sec):
    t1=0
    while True:
        startTime=time.time()
        print(startTime)
        print('开始')
        while True:
            t1=round(time.time()-startTime,0)
            print('计时:' + str(t1) + '秒')
            time.sleep(1)
            if t1==sec:
                res = requests.get('http://localhost:8089/stop')
                break
        break
    return t1
print((time_meter(5)))

最后为了简单的操作,当然是让我们的老朋友tkinter来包装下

class locust_Program(Frame):
    def __init__(self,master=None):
        super().__init__(master)
        self.master=master
        self.pack()
        self.createWidget()

    def createWidget(self):
        #标签:locust压测时间
        self.lable_title=Label(self,text='locust压测时间',bg="light gray",fg='black',anchor='w',width=40,font=('宋体',10,'bold'))
        self.lable_title.grid(row=0,column=0,sticky="w",columnspan=4,padx=5,pady=5)

        self.lable_stamp = Label(self, text='设置压测时间/秒')
        self.lable_stamp.grid(row=3, column=0)

        self.lable_res = Label(self, text='运行结果')
        self.lable_res.grid(row=3, column=3)

        self.inputValue=StringVar()
        self.entry_res=Entry(self,textvariable=self.inputValue,width=10)
        self.entry_res.grid(row=4, column=0,padx=5,pady=5)

        self.btn01 = Button(self, text='开始', bg='green',fg='white',width=10,command=self.beginTime)
        self.btn01.grid(row=4, column=1)

        self.result_time=Text(self,width=15,height=2)
        # self.result_time.insert(2.3, f'请稍等{self.inputValue.get()}秒')
        self.result_time.grid(row=4, column=3,padx=5,pady=5)

    def beginTime(self):
        result=0
        try:
            sec=self.inputValue.get()
            result = self.time_meter(sec)
        except:
            messagebox.showerror(title='错误',message='请输入数字!')
        self.result_time.delete(1.0, END)
        self.result_time.insert(INSERT,'压测完成,已持续压测'+str(result)+'秒')

    # 计时器
    def time_meter(self,second):
        t1=0
        while True:
            startTime=time.time()
            print(startTime)
            print('开始')
            second=float(second)
            while True:
                t1=round(time.time()-startTime,0)
                print('计时:' + str(t1) + '秒')
                time.sleep(1)
                try:
                    if t1==second:
                        res = requests.get('http://localhost:8089/stop')
                        break
                except Exception as error:
                    messagebox.showerror(title='错误', message=error)
                    break
            break
        return t1

root=Tk()
root.title('locust压测小程序')
root.geometry('350x150+500+150')
app = locust_Program(master=root)
root.mainloop()

运行小程序

开始使用,设置压测时间(手点的慢,可以多设置1秒,老夫十年功能手速点点点,无视那几毫秒),点击开始。设置locust并发数,启动用户数,Start swarming

 

 

标签:web,locust,self,Locust,t1,UI,startTime,time,print
From: https://www.cnblogs.com/zhaoboyuanyuan/p/18168278

相关文章

  • 'org.springframework.web.filter.CharacterEncodingFilter' is not assignable to 'j
    问题描述:在写SSM项目中,配置前端控制器的时候发现错误'org.springframework.web.filter.CharacterEncodingFilter'isnotassignableto'javax.servlet.Filter,jakarta.servlet.Filter'一直爆红解决思路:在您的错误消息中,指出了org.springframework.web.filter.CharacterEn......
  • Web Audio API 第6章 高级主题
    高级主题这一章涵盖了非常重要的主题,但比本书的其他部分稍微复杂一些。我们会深入对声音添加音效,完全不通过任何音频缓冲来计算合成音效,模拟不同声音环境的效果,还有关于空3D空间音频。重要理论:双二阶滤波器一个滤波可以增强或减弱声音频谱的某些部分。直观地,在频域上它可......
  • 【moectf】web.http
    用wsrx打开靶机根据任务描述得到moectf{basic_http_knowledge_oen0w64iYZqSeT6BT8c9OgFTV-KNMT6g}......
  • spring-web-mvc项目运行报错:java.lang.NoClassDefFoundError: org/apache/catalina/We
    使用idea运行spring-web-mvc项目时,报错如下:错误:无法初始化主类com.itranswarp.learnjava1.AppConfig原因:java.lang.NoClassDefFoundError:org/apache/catalina/WebResourceRoot 首先,保证当前项目在独立的项目中打开,不要在多个项目中运行。导入Maven工程要选择:File......
  • Could not find module '.../libtorchaudio_ffmpeg.pyd' | RuntimeError: StreamRea
    Windows中使用torchaudio.io.StreamReader时报错:FileNotFoundError:Couldnotfindmodule'D:\software\miniconda3\envs\pytorch\Lib\site-packages\torchaudio\lib\libtorchaudio_ffmpeg.pyd'(oroneofitsdependencies).Tryusingthefullpathwith......
  • Spring WebFlow 远程代码执行漏洞(CVE-2017-4971)
    SpringWebFlow远程代码执行漏洞(CVE-2017-4971)SpringWebFlow是一个适用于开发基于流程的应用程序的框架(如购物逻辑),可以将流程的定义和实现流程行为的类和视图分离开来。在其2.4.x版本中,如果我们控制了数据绑定时的field,将导致一个SpEL表达式注入漏洞,最终造成任意命令执行。......
  • m基于Yolov2深度学习网络的智能零售柜商品识别系统matlab仿真,带GUI界面
    1.算法仿真效果matlab2022a仿真结果如下:  2.算法涉及理论知识概要       YOLO(YouOnlyLookOnce)是一种实时的目标检测算法,YOLOv2则是其改进版本,由JosephRedmon和AliFarhadi于2016年提出。YOLOv2采用了端到端的方式直接从整幅图像预测边界框和类别概率,极大......
  • [转帖]WEB请求处理三:Servlet容器请求处理
    https://www.jianshu.com/p/571c474279af 0系列目录#WEB请求处理WEB请求处理一:浏览器请求发起处理WEB请求处理二:Nginx请求反向代理本篇文章将给大家讲述Servlet容器中请求处理的过程,在给本篇文章起标题时,一直在“应用服务器”与“Servlet容器”这两者之间......
  • golang将uint32与byte[]互转
    packagemainimport( "encoding/binary" "fmt")funcmain(){ //一个长度为4的byte切片,表示一个负数 bytes:=[]byte{0xFF,0xFF,0xFF,0xFF} //将byte切片转换为int32 num:=int32(binary.BigEndian.Uint32(bytes)) fmt.Printf("Byte切片转换为Int32:%d......
  • vue3 把quill的base64变成图片地址
      你可以看看https://www.kancloud.cn/liuwave/quill/1434141或者看看别人的文章我的项目是vu3的 template的是这样的<el-form-itemlabel="中文详情"prop="content"><div><quill-editorref="QuillEditor"v-model:content="form.......