LoginSignup
11
11

More than 5 years have passed since last update.

Goフレームワークのパフォーマンス比較

Last updated at Posted at 2015-11-07

GoはGoogleによって開発されている言語で主な特徴として並行処理、静的型づけ、シンプルな記述がある。

2009年に誕生したみたいだが、他の言語と同じく既に多くのWebフレームワークがあり、どのフレームワークがパフォーマンスが良いのか調べました。

テスト方法としては
・1,0000件のGETリクエストを飛ばしてjsonで応答を返す
・テスト機種、MacBook Pro (Retina, 15-inch, Mid 2015)、2.8 GHz Intel Core i7、16 GB 1600 MHz DDR
・三回繰り返した平均

下記がテストコードである

performance.go
package main

import (
    "net/http"
    "io/ioutil"
    "time"
    "fmt"
    "flag"
)

func main() {
    start := time.Now()
    var port string
    flag.StringVar(&port, "port", "3000", "文字列を入力します。")
    flag.Parse()

    url := fmt.Sprintf("http://localhost:%s/", port)
    for i := 0; i < 10000; i++ {
        resp, _ := http.Get(url)
        defer resp.Body.Close()
        byteArray, _ := ioutil.ReadAll(resp.Body)
        fmt.Println(string(byteArray))
    }
    end := time.Now().Sub(start)
    fmt.Printf("%s秒", end)
}

テストするフレームワーク

・Revel :0.12.0
・beego :1.5.0
・Gin :
・martini
・goji

結果

フレームワーク 結果
Gin 2.51
goji 2.77
beego 2.88
martini 3.37
Revel 4.47

ginが早いですね、フルスタックなフレームワークでbeegoも早かったのが意外です。

ちなみに早いものだと4分から5分で100万件のリクエストをさばけることになるのですが驚異的ですね、ORMマッパーを入れて検証していないのではっきりした数値はわかりませんが。大幅にインフラコストが削減できそうな気がします。

ソースコードは以下を参照ください
https://github.com/t-fukui/performance_test

11
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11