美文网首页性能压测
locust与boomer对非HTTP协议简单压测

locust与boomer对非HTTP协议简单压测

作者: 乐观的星辰 | 来源:发表于2020-01-09 11:41 被阅读0次

boomer: https://github.com/myzhan/boomer

一:dummy.py

from locustimport Locust, TaskSet, task

class MyTaskSet(TaskSet):

@task(20)

def hello(self):

pass

class Dummy(Locust):

task_set= MyTaskSet

原封不动

二:run_locust.go

package main

import boomer "../boomer"

//import boomer "github.com/myzhan/boomer"

import (

"log"

"net"

"net/http"

"time"

"fmt"

)

func now()int64 {

return time.Now().UnixNano() /int64(time.Millisecond)

}

func test_http() {

/*

boomer.Events.Publish("request_failure", type, name, 处理时间, 错误信息)

*/

  startTime :=now()

resp, err :=http.Get("https://www.baidu.com")

defer resp.Body.Close()

endTime :=now()

if err !=nil {

boomer.Events.Publish("request_failure", "demo", "http", 0.0, err.Error())

}else {

boomer.Events.Publish("request_success", "demo", "http", float64(endTime-startTime), resp.ContentLength)

}

}

func test_dns() {

/*

一个简单的 DNS查询操作

*/

  startTime :=now()

time.Sleep(200*time.Millisecond)

addrs, err :=net.LookupHost("testdns.com")

endTime :=now()

//log.Println("resolving baidu.com.. cost time: ", float64(endTime-startTime))

  if err !=nil {

boomer.Events.Publish("request_failure", "dns", "dns", 0.0, err.Error())

}else {

boomer.Events.Publish("request_success", "dns", "dns", float64(endTime-startTime), int64(len(addrs)))

}

}

func test_hello(){

log.Println("ok")

fmt.Println("ok")

}

func main() {

task := &boomer.Task{

Name:"dns",

      Weight:10,

      Fn:test_dns,

  }

//

//task_hello := &boomer.Task{

// Name: "hello_1",

// Weight: 10,

// Fn: test_hello,

//}

//task_http := &boomer.Task{

// Name: "http",

// Weight: 10,

// Fn: test_http,

//}

/*

通知 boomer 去执行自定义函数,支持多个

boomer.Run(task1, task2, task3)

*/

  boomer.Run(task)

}

环境安装:略

build 文件:

    go build -o b.out ./run_locust.go

运行:

    ./b.out --run-tasks dns

结果:

    xiaobindeMacBook-Pro:go_hello xiaobin$ ./b.out --run-tasks dns

    2020/01/09 11:35:57 Running dns

运行帮助:

    ./b.out --help

结果:

    xiaobindeMacBook-Pro:go_hello xiaobin$ ./b.out --help

Usage of ./b.out:

  -cpu-profile string

        Enable CPU profiling.

  -cpu-profile-duration duration

        CPU profile duration. (default 30s)

  -master-host string

        Host or IP address of locust master for distributed load testing. (default "127.0.0.1")

  -master-port int

        The port to connect to that is used by the locust master for distributed load testing. (default 5557)

  -max-rps int

        Max RPS that boomer can generate, disabled by default.

  -mem-profile string

        Enable memory profiling.

  -mem-profile-duration duration

        Memory profile duration. (default 30s)

  -request-increase-rate string

        Request increase rate, disabled by default. (default "-1")

  -run-tasks string

        Run tasks without connecting to the master, multiply tasks is separated by comma. Usually, it's for debug purpose.

三:运行

    locust -f ./dummy.py --master  . -- 启动master

    ./b.out  . -- 启动slave,看help都是默认值就好本地都话

四:结果

相关文章

网友评论

    本文标题:locust与boomer对非HTTP协议简单压测

    本文链接:https://www.haomeiwen.com/subject/nmlyactx.html