Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize bench #162

Merged
merged 3 commits into from Jan 14, 2020
Merged

Customize bench #162

merged 3 commits into from Jan 14, 2020

Conversation

guonaihong
Copy link
Owner

@guonaihong guonaihong commented Jan 14, 2020

see #151
压测模式支持回调函数,这样可以生成每次不一样的request请求

package main

import (
    "fmt"
    "github.com/google/uuid"
    "github.com/guonaihong/gout"
    "github.com/guonaihong/gout/filter"
    "sync/atomic"
)

func main() {
    i := int32(0)

    err := filter.NewBench().
        Concurrent(30). //开30个go程
        Number(30000).  //压测30000次
        Loop(func(c *gout.Context) error {

			// 下面的代码,每次生成不一样的http body 用于压测
            uid := uuid.New()  //生成uuid
            id := atomic.AddInt32(&i, 1) //生成id, 可以理解为++i,线程安全版本

            c.POST(":1234").SetJSON(gout.H{"sid": uid.String(),
                "appkey": fmt.Sprintf("ak:%d", id),
                "text":   fmt.Sprintf("test text :%d", id)})
            return nil

        }).Do()

    if err != nil {
        fmt.Printf("err = %v\n", err)
    }
}

@codecov-io
Copy link

codecov-io commented Jan 14, 2020

Codecov Report

Merging #162 into master will increase coverage by 0.64%.
The diff coverage is 90.69%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #162      +/-   ##
==========================================
+ Coverage   89.46%   90.11%   +0.64%     
==========================================
  Files          40       39       -1     
  Lines        1671     1689      +18     
==========================================
+ Hits         1495     1522      +27     
+ Misses        128      123       -5     
+ Partials       48       44       -4
Impacted Files Coverage Δ
filter/retry.go 100% <ø> (+3.57%) ⬆️
filter/init.go 100% <ø> (ø) ⬆️
bench/report.go 92.9% <100%> (ø) ⬆️
core/core.go 100% <100%> (ø) ⬆️
filter/bench.go 91.48% <83.33%> (-1.62%) ⬇️
bench/task.go 87.8% <0%> (+1.21%) ⬆️
export/curl.go 100% <0%> (+28.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 307d098...2269b48. Read the comment docs.

@guonaihong guonaihong merged commit 0b5509b into master Jan 14, 2020
@guonaihong guonaihong deleted the customize-bench branch January 14, 2020 15:12
@guonaihong guonaihong mentioned this pull request Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants