[] Using locust locust + boomer to achieve pressure sensing interface

background

Before long, consider a stand-alone implementation capacity, pressure measurement work done using locust company SMS gateway, and later found a golang version of the locust, the performance version of python is 5 to ten times, but never had the chance to use.

Recently the company wanted to do a performance test platform, technology selection and development of the language requirement is consistent, that is golang, so I think a boomer, boomer record of using paper.

Environment Installation

Development environment installation
Python 3.7 slightly
locust 0.11.0 pip install locustio
golang slightly
boomer go get github.com/myzhan/boomer

Note : The latest version of the boomer compatible goczmq, locust you need to upgrade to a higher version to complete compatibility.

Scripting

master

This part of the code is not important, as long as the start line.

from locust import Locust, TaskSet, task


class MyTaskSet(TaskSet):
    @task(20)
    def hello(self):
        pass


class Dummy(Locust):
    task_set = MyTaskSet

slave node (golang / boomer)

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
    "time"

    "github.com/myzhan/boomer"
)

func getDemo() {
    start := time.Now()
    resp, err := http.Get("http://httpbin.org/get?name=Detector")

    if err != nil {
        log.Println(err)
        return
    }
    defer resp.Body.Close()
    fmt.Println(resp.Status)
    elapsed := time.Since(start)
    if resp.Status == "200 OK" {
        boomer.RecordSuccess("http", "sostreq", elapsed.Nanoseconds()/int64(time.Millisecond), int64(10))
    } else {
        boomer.RecordFailure("http", "sostreq", elapsed.Nanoseconds()/int64(time.Millisecond), "sostreq not equal")
    }
}

func postDemo() {
    start := time.Now()

    info := make(map[string]interface{})
    info["name"] = "Detector"
    info["age"] = 15
    info["loc"] = "深圳"
    // 将map解析未[]byte类型
    bytesData, _ := json.Marshal(info)
    // 将解析之后的数据转为*Reader类型
    reader := bytes.NewReader(bytesData)
    resp, _ := http.Post("http://httpbin.org/post",
        "application/json",
        reader)
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
    elapsed := time.Since(start)
    if resp.Status == "200 OK" {
        boomer.RecordSuccess("http", "sostreq", elapsed.Nanoseconds()/int64(time.Millisecond), int64(10))
    } else {
        boomer.RecordFailure("http", "sostreq", elapsed.Nanoseconds()/int64(time.Millisecond), "sostreq not equal")
    }
}

func main() {
    task1 := &boomer.Task{
        Name: "sostreq",
        // The weight is used to distribute goroutines over multiple tasks.
        Weight: 20,
        Fn:     getDemo,
    }

    task2 := &boomer.Task{
        Name: "sostreq",
        // The weight is used to distribute goroutines over multiple tasks.
        Weight: 10,
        Fn:     postDemo,
    }
    boomer.Run(task1, task2)
}

problem

Failed to execute dot. Is Graphviz installed? Error: exec: "dot": executable file not found in $PATH

Guess you like

Origin www.cnblogs.com/Detector/p/11469233.html