-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
988 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/topfreegames/khan/loadtest" | ||
"github.com/topfreegames/khan/log" | ||
"github.com/uber-go/zap" | ||
) | ||
|
||
var sharedClansFile string | ||
var nGoroutines int | ||
|
||
var loadtestCmd = &cobra.Command{ | ||
Use: "loadtest", | ||
Short: "runs a load test against a remote Khan API", | ||
Long: `Runs a load test against a remote Khan API with the specified arguments. | ||
You can use environment variables to override configuration keys.`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
logger := zap.New(zap.NewJSONEncoder(), zap.InfoLevel) | ||
|
||
exitChannel := make(chan bool) | ||
routine := func() { | ||
l := logger.With( | ||
zap.String("source", "loadtestCmd"), | ||
zap.String("operation", "Run/goroutine"), | ||
) | ||
|
||
app := loadtest.GetApp(ConfigFile, sharedClansFile, logger) | ||
if err := app.Run(); err != nil { | ||
log.E(l, "Goroutine exited with error.", func(cm log.CM) { | ||
cm.Write(zap.String("error", err.Error())) | ||
}) | ||
} else { | ||
log.I(l, "Goroutine exited without errors.") | ||
} | ||
|
||
exitChannel <- true | ||
} | ||
for i := 0; i < nGoroutines; i++ { | ||
go routine() | ||
} | ||
for i := 0; i < nGoroutines; i++ { | ||
<-exitChannel | ||
} | ||
|
||
l := logger.With( | ||
zap.String("source", "loadtestCmd"), | ||
zap.String("operation", "Run"), | ||
) | ||
log.I(l, "Application exited without errors.") | ||
}, | ||
} | ||
|
||
func init() { | ||
RootCmd.AddCommand(loadtestCmd) | ||
|
||
loadtestCmd.Flags().StringVar( | ||
&sharedClansFile, | ||
"clans", | ||
"./config/loadTestSharedClans.yaml", | ||
"shared clans list for load test", | ||
) | ||
|
||
loadtestCmd.Flags().IntVar( | ||
&nGoroutines, | ||
"goroutines", | ||
1, | ||
"number of goroutines to spawn for concurrent load tests", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
clans: | ||
- "clan1publicID" | ||
- "clan2publicID" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
Load Test for Khan API | ||
====================== | ||
|
||
This application performs a specified amount of sequential requests to a remote Khan API server, with a specified time period between two consecutive requests. Usage: `../khan loadtest --help` | ||
|
||
# Game parameters | ||
Khan does not offer a route to get game information, so the maximum number of members per clan and the membership level for application are defined under the key `loadtest` within `../config/local.yaml`: | ||
``` | ||
loadtest: | ||
game: | ||
maxMembers: 50 | ||
membershipLevel: "member" | ||
``` | ||
Or setting the following environment variables: | ||
``` | ||
KHAN_LOADTEST_GAME_MAXMEMBERS (default: 0) | ||
KHAN_LOADTEST_GAME_MEMBERSHIPLEVEL (default: "") | ||
``` | ||
|
||
# Request parameters | ||
Both amount and period are defined under the key `loadtest` within `../config/local.yaml`: | ||
``` | ||
loadtest: | ||
requests: | ||
amount: 1 | ||
period: | ||
ms: 1 | ||
``` | ||
Or setting the following environment variables: | ||
``` | ||
KHAN_LOADTEST_REQUESTS_AMOUNT (default: 0) | ||
KHAN_LOADTEST_REQUESTS_PERIOD_MS (default: 0) | ||
``` | ||
|
||
# Request operations | ||
For each request, an operation is chosen at random with probabilities defined at `../config/local.yaml`, like this: | ||
``` | ||
loadtest: | ||
operations: | ||
retrieveSharedClan: | ||
probability: 0.3 | ||
updateSharedClan: | ||
probability: 0.3 | ||
``` | ||
Or setting the following environment variables: | ||
``` | ||
KHAN_LOADTEST_OPERATIONS_RETRIEVESHAREDCLAN_PROBABILITY (no default value) | ||
KHAN_LOADTEST_OPERATIONS_UPDATESHAREDCLAN_PROBABILITY (no default value) | ||
``` | ||
Request operations are defined in files `player.go`, `clan.go` and `membership.go`. Check the operation keys to set the probabilities. | ||
|
||
# Remote KHAN API server parameters | ||
Khan API server URL and credentials should be set by environment variables, like this: | ||
``` | ||
KHAN_KHAN_URL: URL including protocol and port to remote Khan API server | ||
KHAN_KHAN_USER: basic auth username | ||
KHAN_KHAN_PASS: basic auth password | ||
KHAN_KHAN_GAMEID: game public ID | ||
KHAN_KHAN_TIMEOUT: nanoseconds to wait before timing out a request (default: 500 ms) | ||
KHAN_KHAN_MAXIDLECONNS: max keep-alive connections to keep among all hosts (default: 100) | ||
KHAN_KHAN_MAXIDLECONNSPERHOST: max keep-alive connections to keep per-host (default: 2) | ||
``` | ||
|
||
# Operations with clans shared among different load test processes | ||
Some operations are targeted to a set of clans that should be shared among different processes running a load test. This is supposed to test the most common sequence of operations (`updatePlayer`, then `getClan`, then `updateClan`) in its most common use case, which is a number of different clients updating the score of a particular clan within its metadata field. Use the file `../config/loadTestSharedClans.yaml` to specify a list of clan public IDs, like this: | ||
|
||
``` | ||
clans: | ||
- "clan1publicID" | ||
- "clan2publicID" | ||
``` |
Oops, something went wrong.