Skip to content

Commit

Permalink
Last004 (#119)
Browse files Browse the repository at this point in the history
* v0.0.4版本最后善后修改

* 修改拼写错误
  • Loading branch information
guonaihong committed Dec 8, 2019
1 parent 1a8055f commit 03c4a7f
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 10 deletions.
15 changes: 8 additions & 7 deletions README.md
Expand Up @@ -9,7 +9,6 @@ gout 是go写的http 客户端,为提高工作效率而开发

## 内容
- [安装](#安装)
- [技能树](#技能树)
- [迁移文档](#迁移文档)
- [example](#example)
- [quick start](#quick-start)
Expand Down Expand Up @@ -51,16 +50,12 @@ gout 是go写的http 客户端,为提高工作效率而开发
- [特色功能示例](#特色功能示例)
- [forward gin data](#forward-gin-data)

- [FAQ](#FAQ)

## 安装
```
env GOPATH=`pwd` go get github.com/guonaihong/gout
```
## 技能树
<details>

![gout.png](https://github.com/guonaihong/images/blob/master/gout/gout.png)

</details>

## 迁移文档
主要方便下面的用户迁移到gout
Expand Down Expand Up @@ -1355,3 +1350,9 @@ func main() {
// http client
// curl '127.0.0.1:8080/query?size=10&page=20&ak=test'
```
# FAQ

## gout benchmark性能如何
下面是与apache ab的性能对比 [_example/16d-benchmark-vs-ab.go](_example/16d-benchmark-vs-ab.go)

![gout-vs-ab.png](https://github.com/guonaihong/images/blob/master/gout/gout-vs-ab.png?raw=true)
4 changes: 2 additions & 2 deletions _example/16b-benchmark-duration.go
Expand Up @@ -8,14 +8,14 @@ import (
)

const (
benchTime = 10 * time.Second
benchTime = 4 * time.Second
benchConcurrent = 30
)

func server() {
router := gin.New()
router.POST("/", func(c *gin.Context) {
c.JSON(200, gin.H{"key": "12345"})
c.String(200, "hello world:gout")
})

router.Run()
Expand Down
72 changes: 72 additions & 0 deletions _example/16d-benchmark-vs-ab.go
@@ -0,0 +1,72 @@
package main

import (
"fmt"
"github.com/gin-gonic/gin"
"github.com/guonaihong/gout"
"log"
"os"
"os/exec"
"time"
)

const (
benchCount = 100000
benchConcurrent = 30
)

func server() {
router := gin.New()
router.POST("/", func(c *gin.Context) {
c.String(200, "hello world:gout")
})

router.Run()
}

func runGout() {
fd, err := os.Open("../testdata/voice.pcm")
if err != nil {
fmt.Printf("%s\n", err)
return
}
defer fd.Close()

err = gout.
POST(":8080").
SetBody(fd). //设置请求body内容
Filter(). //打开过滤器
Bench(). //选择bench功能
Concurrent(benchConcurrent). //并发数
Number(benchCount). //压测次数
Do()

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

// sudo apt install apache2-utils
var abCmd = fmt.Sprintf(`ab -c %d -n %d -p ../testdata/voice.pcm http://127.0.0.1:8080/`, benchConcurrent, benchCount)

func runAb() {
out, err := exec.Command("bash", "-c", abCmd).Output()
if err != nil {
log.Fatal("%s\n", err)
}
fmt.Printf("%s\n", out)

}

func main() {
go server()
time.Sleep(300 * time.Millisecond)

// 设为false,可看ab性能
startGout := true
if startGout {
runGout()
} else {
runAb()
}
}
2 changes: 1 addition & 1 deletion _example/go.mod
Expand Up @@ -2,7 +2,7 @@ module main

require (
github.com/gin-gonic/gin v1.4.1-0.20190924141841-9b9f4fab34cc
github.com/guonaihong/gout v0.0.3
github.com/guonaihong/gout v0.0.4
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
)

0 comments on commit 03c4a7f

Please sign in to comment.