From 1af8f319a0339acc46c68e8228b45583afd00bde Mon Sep 17 00:00:00 2001 From: cscatolini Date: Tue, 26 Jul 2016 18:20:25 -0300 Subject: [PATCH] Get clans summary bench tests. --- api/app.go | 41 ++++++++++++++++++++++++----------------- bench/clan_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/api/app.go b/api/app.go index 010c6a7b..3e9c2420 100644 --- a/api/app.go +++ b/api/app.go @@ -25,27 +25,29 @@ import ( // App is a struct that represents a Khan API Application type App struct { - Debug bool - Port int - Host string - ConfigPath string - Errors metrics.EWMA - App *iris.Framework - Db models.DB - Config *viper.Viper - Dispatcher *Dispatcher - Logger zap.Logger + Debug bool + Port int + Host string + ConfigPath string + Errors metrics.EWMA + App *iris.Framework + Db models.DB + Config *viper.Viper + Dispatcher *Dispatcher + Logger zap.Logger + ReadBufferSize int } // GetApp returns a new Khan API Application func GetApp(host string, port int, configPath string, debug bool, logger zap.Logger) *App { app := &App{ - Host: host, - Port: port, - ConfigPath: configPath, - Config: viper.New(), - Debug: debug, - Logger: logger, + Host: host, + Port: port, + ConfigPath: configPath, + Config: viper.New(), + Debug: debug, + Logger: logger, + ReadBufferSize: 30000, } app.Configure() @@ -359,5 +361,10 @@ func (app *App) Start() { defer app.finalizeApp() l.Debug("App started.", zap.String("host", app.Host), zap.Int("port", app.Port)) - app.App.Listen(fmt.Sprintf("%s:%d", app.Host, app.Port)) + + cfg := config.Server{ + ListeningAddr: fmt.Sprintf("%s:%d", app.Host, app.Port), + ReadBufferSize: app.ReadBufferSize, + } + app.App.Must(app.App.ListenTo(cfg)) } diff --git a/bench/clan_test.go b/bench/clan_test.go index 4e148aef..938481b2 100644 --- a/bench/clan_test.go +++ b/bench/clan_test.go @@ -10,6 +10,7 @@ package bench import ( "fmt" "net/http" + "strings" "testing" "github.com/satori/go.uuid" @@ -136,6 +137,39 @@ func BenchmarkRetrieveClanSummary(b *testing.B) { } } +func BenchmarkRetrieveClansSummary(b *testing.B) { + db, err := models.GetPerfDB() + if err != nil { + panic(err.Error()) + } + + game, owner, err := getGameAndPlayer(db) + if err != nil { + panic(err.Error()) + } + + clans, err := createClans(db, game, owner, 500) + if err != nil { + panic(err.Error()) + } + + var clanIDs []string + for _, clan := range clans { + clanIDs = append(clanIDs, clan.PublicID) + } + qs := strings.Join(clanIDs, ",") + b.ResetTimer() + + for i := 0; i < b.N; i++ { + route := getRoute(fmt.Sprintf("/games/%s/clans-summary?clanPublicIds=%s", game.PublicID, qs)) + res, err := get(route) + validateResp(res, err) + res.Body.Close() + + result = res + } +} + func BenchmarkSearchClan(b *testing.B) { db, err := models.GetPerfDB() if err != nil {