goのweb frameworkについて調べる

## goの web frameworkについてあまり知らなかったので、調べてみた。

こちらをご参考にさせていただきました。
http://qiita.com/jumbOS5/items/45f86db15a5a6c8a0622

　- ベンチマークの参考は　[go-http-routing-benchmark] (https://github.com/vishr/go-http-routing-benchmark) (routers.goのL36をecho.v1にすれば動作することを確認),[web-framework-benchmark] (https://github.com/vishr/web-framework-benchmark)を使用。
 
 web-framework-benchmarkを動かすには [glide](https://github.com/Masterminds/glide)その他,bench.shで記載のあるライブラリが必要。[wrk](https://github.com/wg/wrk/wiki/Installing-Wrk-on-Linux)というコマンドが内部で叩かれるのでそれも必要。

| frame work       |       github star |触った感じ|
|:-----------------|------------------:|--:|
| [echo](https://echo.labstack.com/)|4686 |少ない行で簡単に書ける。|
| [gin](https://github.com/gin-gonic/gin) |6829 |少ない行で簡単に書ける。|
| [martini](https://github.com/go-martini/martini)|8257 |ドキュメントが充実している,少ない行で簡単に書ける。周辺機能(ミドルウェア)が充実している。|
|[beego](https://github.com/astaxie/beego)|7337|少ない行で簡単に書ける。|
|[goji](https://github.com/zenazn/goji)|3097|issueが少ない。作りがシンプル。|
他はこんな感じだった
bone 909
gocraft 1068
goji 3095
gorilla 2467
kami 165

## benchmarkツールでの結果

下記の環境で動作確認(仮想環境なので性能判定としてはイマイチ)

- 環境
 - Ubuntu 14.04 LTS
 - go 1.6
 - Intel(R) Core(TM)2 Duo CPU     P8800  @ 2.66GHz
 - memory 4GB

### web-framework-benchmark

```
## beego
benchmarking beego...
Running 10s test @ http://localhost:8080/teams/x-men/members/wolverine
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    28.29ms   52.61ms 486.37ms   89.10%
    Req/Sec     3.84k     1.76k    8.64k    64.62%
  75967 requests in 10.06s, 10.50MB read
Requests/sec:   7548.68
Transfer/sec:      1.04MB

benchmarking with pipleline...
Running 10s test @ http://localhost:8080
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   203.45ms  154.99ms 895.34ms   68.75%
    Req/Sec     5.66k     2.89k   12.07k    62.77%
  109792 requests in 10.11s, 15.18MB read
Requests/sec:  10864.86
Transfer/sec:      1.50MB
stopping beego (20432)...
./bench.sh: line 7: 20432 Killed                  ./server

## echo/standard
benchmarking echo/standard...
Running 10s test @ http://localhost:8080/teams/x-men/members/wolverine
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    30.74ms   51.64ms 443.29ms   86.75%
    Req/Sec     4.14k     1.81k    8.36k    66.67%
  81687 requests in 10.08s, 11.30MB read
Requests/sec:   8107.75
Transfer/sec:      1.12MB

benchmarking with pipleline...
Running 10s test @ http://localhost:8080
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   234.64ms  181.69ms   1.10s    69.73%
    Req/Sec     5.06k     2.78k   11.63k    64.17%
  97796 requests in 10.07s, 13.52MB read
Requests/sec:   9714.00
Transfer/sec:      1.34MB
stopping echo/standard (20469)...
./bench.sh: line 7: 20469 Killed                  ./server

## echo/fasthttp
benchmarking echo/fasthttp...
Running 10s test @ http://localhost:8080/teams/x-men/members/wolverine
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    21.26ms   42.32ms 321.26ms   89.58%
    Req/Sec     3.26k     1.55k    7.48k    65.05%
  62771 requests in 10.07s, 9.76MB read
Requests/sec:   6233.91
Transfer/sec:      0.97MB

benchmarking with pipleline...
Running 10s test @ http://localhost:8080
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   188.73ms  140.97ms 747.07ms   65.19%
    Req/Sec    24.82k    16.46k   60.52k    58.54%
  448086 requests in 10.10s, 69.65MB read
Requests/sec:  44346.54
Transfer/sec:      6.89MB
stopping echo/fasthttp (20500)...
./bench.sh: line 7: 20500 Killed                  ./server

## gin
benchmarking gin...
Running 10s test @ http://localhost:8080/teams/x-men/members/wolverine
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    57.73ms   92.79ms 610.68ms   85.26%
    Req/Sec     3.05k     1.73k    7.16k    63.83%
  59049 requests in 10.06s, 8.17MB read
Requests/sec:   5869.92
Transfer/sec:    831.19KB

benchmarking with pipleline...
Running 10s test @ http://localhost:8080
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   219.39ms  161.98ms   1.00s    66.63%
    Req/Sec     5.35k     2.98k   12.61k    64.25%
  101387 requests in 10.06s, 14.02MB read
Requests/sec:  10079.35
Transfer/sec:      1.39MB
stopping gin (20530)...
./bench.sh: line 7: 20530 Killed                  ./server

## goji
benchmarking goji...
Running 10s test @ http://localhost:8080/teams/x-men/members/wolverine
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    30.56ms   50.54ms 391.85ms   86.29%
    Req/Sec     3.33k     1.80k    8.27k    59.79%
  65927 requests in 10.09s, 9.12MB read
Requests/sec:   6535.60
Transfer/sec:      0.90MB

benchmarking with pipleline...
Running 10s test @ http://localhost:8080
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   259.73ms  197.36ms   1.59s    68.93%
    Req/Sec     5.00k     3.05k   11.68k    60.00%
  95654 requests in 10.05s, 13.23MB read
Requests/sec:   9513.19
Transfer/sec:      1.32MB
stopping goji (20558)...
./bench.sh: line 7: 20558 Killed                  ./server

## martini
benchmarking martini...
Running 10s test @ http://localhost:8080/teams/x-men/members/wolverine
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    48.80ms   76.59ms 585.97ms   85.53%
    Req/Sec     2.80k     1.50k    6.04k    64.17%
  54224 requests in 10.09s, 7.50MB read
Requests/sec:   5373.82
Transfer/sec:    760.94KB

benchmarking with pipleline...
Running 10s test @ http://localhost:8080
  2 threads and 20 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency   228.92ms  166.95ms 968.45ms   67.61%
    Req/Sec     3.56k     1.76k    7.95k    66.49%
  69365 requests in 10.04s, 9.59MB read
Requests/sec:   6908.24
Transfer/sec:      0.96MB
stopping martini (20586)...
./bench.sh: line 7: 20586 Killed                  ./server
```

### go-http-routing-benchmarkでの結果
ベンチ項目が多くかつ時間もかかるので、一部割愛。

```
$ go test -bench=.
#GithubAPI Routes: 203
   Ace: 48768 Bytes
   Bear: 161496 Bytes
   Beego: 146328 Bytes
   Bone: 97696 Bytes
   Denco: 36440 Bytes
   Echo: 76328 Bytes
   Gin: 52464 Bytes
   GocraftWeb: 95304 Bytes
   Goji: 86104 Bytes
   Gojiv2: 144408 Bytes
   GoJsonRest: 134136 Bytes
   GoRestful: 1395608 Bytes
   GorillaMux: 1494816 Bytes
   HttpRouter: 37464 Bytes
   HttpTreeMux: 78736 Bytes
   Kocha: 785120 Bytes
   LARS: 49056 Bytes
   Macaron: 129304 Bytes
   Martini: 556192 Bytes
   Pat: 21200 Bytes
   Possum: 83408 Bytes
   R2router: 47104 Bytes
   Revel: 141296 Bytes
   Rivet: 42840 Bytes
   Tango: 54584 Bytes
   TigerTonic: 96032 Bytes
   Traffic: 1053744 Bytes
   Vulcan: 464976 Bytes

#GPlusAPI Routes: 13
   Ace: 3600 Bytes
   Bear: 7112 Bytes
   Beego: 9712 Bytes
   Bone: 6448 Bytes
   Denco: 3256 Bytes
   Echo: 7128 Bytes
   Gin: 3856 Bytes
   GocraftWeb: 7496 Bytes
   Goji: 2912 Bytes
   Gojiv2: 7376 Bytes
   GoJsonRest: 11400 Bytes
   GoRestful: 87608 Bytes
   GorillaMux: 71072 Bytes
   HttpRouter: 2712 Bytes
   HttpTreeMux: 7376 Bytes
   Kocha: 128880 Bytes
   LARS: 3664 Bytes
   Macaron: 8448 Bytes
   Martini: 23936 Bytes
   Pat: 1856 Bytes
   Possum: 7248 Bytes
   R2router: 3928 Bytes
   Revel: 10768 Bytes
   Rivet: 3064 Bytes
   Tango: 4912 Bytes
   TigerTonic: 9408 Bytes
   Traffic: 49472 Bytes
   Vulcan: 25496 Bytes

#ParseAPI Routes: 26
   Ace: 6592 Bytes
   Bear: 12320 Bytes
   Beego: 18416 Bytes
   Bone: 10992 Bytes
   Denco: 4184 Bytes
   Echo: 8048 Bytes
   Gin: 6816 Bytes
   GocraftWeb: 12800 Bytes
   Goji: 5232 Bytes
   Gojiv2: 14464 Bytes
   GoJsonRest: 14088 Bytes
   GoRestful: 126216 Bytes
   GorillaMux: 122184 Bytes
   HttpRouter: 4976 Bytes
   HttpTreeMux: 7784 Bytes
   Kocha: 181712 Bytes
   LARS: 6656 Bytes
   Macaron: 13232 Bytes
   Martini: 45952 Bytes
   Pat: 2560 Bytes
   Possum: 9200 Bytes
   R2router: 7056 Bytes
   Revel: 15488 Bytes
   Rivet: 5680 Bytes
   Tango: 8664 Bytes
   TigerTonic: 9840 Bytes
   Traffic: 93480 Bytes
   Vulcan: 44504 Bytes

#Static Routes: 157
   HttpServeMux: 18784 Bytes
   Ace: 30080 Bytes
   Bear: 30216 Bytes
   Beego: 93768 Bytes
   Bone: 37872 Bytes
   Denco: 10272 Bytes
   Echo: 61024 Bytes
   Gin: 30400 Bytes
   GocraftWeb: 55048 Bytes
   Goji: 27200 Bytes
   Gojiv2: 104464 Bytes
   GoJsonRest: 135768 Bytes
   GoRestful: 908200 Bytes
   GorillaMux: 668496 Bytes
   HttpRouter: 21128 Bytes
   HttpTreeMux: 73384 Bytes
   Kocha: 114960 Bytes
   LARS: 30144 Bytes
   Macaron: 35136 Bytes
   Martini: 308784 Bytes
   Pat: 20464 Bytes
   Possum: 90368 Bytes
   R2router: 23712 Bytes
   Revel: 92768 Bytes
   Rivet: 23880 Bytes
   Tango: 28008 Bytes
   TigerTonic: 79904 Bytes
   Traffic: 624416 Bytes
   Vulcan: 368728 Bytes
```

ここまでやってみてやはり使いどころによって選ぶフレームワークが変わってくると思った。
まだそれぞれの特徴を掴み取れていないので,どれが使いやすいか引き続き調べてみようと思う。