Skip to content

Commit

Permalink
Merge pull request #54 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 2.0.0
  • Loading branch information
andyone authored Aug 4, 2023
2 parents 85e9990 + 3800643 commit 8902944
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 32 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<br/>

`rds-payload-generator` is simple payload generator for [Redis-Split](https://github.com/essentialkaos/rds).
`rds-payload-generator` is simple payload generator for [RDS](https://kaos.sh/rds).

### Installation

Expand All @@ -38,18 +38,18 @@ Usage: rds-payload-generator {options}
Options
--dir, -d dir Redis-Split main dir
--keys, -k Number of keys (10-1000000 default: 5000)
--ratio, -r Writes/reads ration (1-100 default: 4)
--dir, -d dir Path to RDS main dir
--keys, -k Number of keys (10-1000000 | default: 5000)
--ratio, -r Writes/reads ratio (1-100 | default: 4)
--pause, -p Max pause between requests in ms (1-1000 | default: 15)
--no-color, -nc Disable colors in output
--help, -h Show this help message
--version, -v Show version
Examples
rds-payload-generator -d /srv/redis-split -k 35000 -r 10
rds-payload-generator -d /srv/rds -k 35000 -r 10
Run tool with custom settings
```

### Build Status
Expand Down
61 changes: 38 additions & 23 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@ import (
// Application info
const (
APP = "RDS Payload Generator"
VER = "1.2.0"
DESC = "Payload generator for Redis-Split"
VER = "2.0.0"
DESC = "Payload generator for RDS"
)

// Supported command line options
const (
OPT_DIR = "d:dir"
OPT_KEYS = "k:keys"
OPT_RATIO = "r:ratio"
OPT_PAUSE = "p:pause"
OPT_NO_COLOR = "nc:no-color"
OPT_HELP = "h:help"
OPT_VER = "v:version"
Expand All @@ -56,6 +57,9 @@ const (
// START_PORT start port
const START_PORT = 63000

// UI_REFRESH user interface refresh delay
const UI_REFRESH = 50 * time.Millisecond

// ////////////////////////////////////////////////////////////////////////////////// //

// RedisStore is Redis connection pull
Expand All @@ -69,6 +73,7 @@ var optMap = options.Map{
OPT_DIR: {},
OPT_KEYS: {Type: options.INT, Value: 5000, Min: 10, Max: 1000000},
OPT_RATIO: {Type: options.INT, Value: 4, Min: 1, Max: 100},
OPT_PAUSE: {Type: options.INT, Value: 15, Min: 1, Max: 1000},
OPT_NO_COLOR: {Type: options.BOOL},
OPT_HELP: {Type: options.BOOL},
OPT_VER: {Type: options.BOOL},
Expand Down Expand Up @@ -132,7 +137,10 @@ func preConfigureUI() {
}
}

if !fsutil.IsCharacterDevice("/dev/stdout") && os.Getenv("FAKETTY") == "" {
// Check for output redirect using pipes
if fsutil.IsCharacterDevice("/dev/stdin") &&
!fsutil.IsCharacterDevice("/dev/stdout") &&
os.Getenv("FAKETTY") == "" {
fmtc.DisableColors = true
}

Expand All @@ -148,7 +156,7 @@ func configureUI() {
}
}

// checkRDSInstallation checks Redis-Split installation
// checkRDSInstallation checks RDS installation
func checkRDSInstallation() {
rdsDir := getRDSMainDir()
err := fsutil.ValidatePerms("DRX", rdsDir)
Expand Down Expand Up @@ -178,7 +186,9 @@ func generatePayload() {
store := &RedisStore{make(map[string]*redy.Client)}
metaDir := getRDSMainDir() + "/meta"
maxKey := options.GetI(OPT_KEYS)
ratio := options.GetI(OPT_RATIO)
ratio := options.GetI(OPT_RATIO) + 1
pause := getPause()
lastUIUpdate := time.Now()

fmtc.TPrintf("{s-}Starting…{!}")

Expand All @@ -189,7 +199,7 @@ func generatePayload() {
lastIDListUpdate = time.Now()
}

time.Sleep(getPause())
time.Sleep(pause)

instanceID := ids[rand.Int(num)]

Expand All @@ -203,38 +213,42 @@ func generatePayload() {

switch rand.Int(ratio) {
case 0:
client.Cmd("SET", key)
client.Cmd("SET", key, "X")
writes++
default:
client.Cmd("GET", key)
reads++
}

fmtc.TPrintf(
"{s}[{!} {c}↑ %s{!} {s}|{!} {m}↓ %s{!} {s}]{!}",
fmtutil.PrettyNum(writes),
fmtutil.PrettyNum(reads),
)
if time.Since(lastUIUpdate) >= UI_REFRESH {
fmtc.TPrintf(
"{s}[{!} {c}{*}↑{!*} %s{!} {s}|{!} {m}{*}↓{!*} %s{!} {s}]{!}",
fmtutil.PrettyNum(writes),
fmtutil.PrettyNum(reads),
)

lastUIUpdate = time.Now()
}
}
}

// getRDSMainDir returns path to main Redis-Split directory
// getRDSMainDir returns path to main RDS directory
func getRDSMainDir() string {
return fsutil.ProperPath("DRX",
[]string{
options.GetS(OPT_DIR),
"/opt/redis-split",
"/srv/redis-split",
"/srv2/redis-split",
"/srv3/redis-split",
"/srv4/redis-split",
"/opt/rds",
"/srv/rds",
"/srv2/rds",
"/srv3/rds",
"/srv4/rds",
},
)
}

// getPause returns pause between requests
func getPause() time.Duration {
r := 0.001 * float64(rand.Int(25))
r := 0.001 * float64(rand.Int(options.GetI(OPT_PAUSE)))
return time.Duration(r * float64(time.Second))
}

Expand Down Expand Up @@ -328,15 +342,16 @@ func printMan() {
func genUsage() *usage.Info {
info := usage.NewInfo()

info.AddOption(OPT_DIR, "Path to Redis-Split main dir", "dir")
info.AddOption(OPT_KEYS, "Number of keys {s-}(10-1000000 default: 5000){!}")
info.AddOption(OPT_RATIO, "Writes/reads ratio {s-}(1-100 default: 4){!}")
info.AddOption(OPT_DIR, "Path to RDS main dir", "dir")
info.AddOption(OPT_KEYS, "Number of keys {s-}(10-1000000 | default: 5000){!}")
info.AddOption(OPT_RATIO, "Writes/reads ratio {s-}(1-100 | default: 4){!}")
info.AddOption(OPT_PAUSE, "Max pause between requests in ms {s-}(1-1000 | default: 15){!}")
info.AddOption(OPT_NO_COLOR, "Disable colors in output")
info.AddOption(OPT_HELP, "Show this help message")
info.AddOption(OPT_VER, "Show version")

info.AddExample(
"-d /srv/redis-split -k 35000 -r 10",
"-d /srv/rds -k 35000 -r 10",
"Run tool with custom settings",
)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.18

require (
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.73.2
github.com/essentialkaos/ek/v12 v12.75.1
github.com/essentialkaos/redy/v4 v4.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1nkuKk=
github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.73.2 h1:MrHHcH1/qOmeMGruRdtcyWTxHQh85QEvxc8aUmjY07c=
github.com/essentialkaos/ek/v12 v12.73.2/go.mod h1:juDcZWOWaj1QmYShZkT9RzdqJ3n0tmeP/iq4sw5fQF0=
github.com/essentialkaos/ek/v12 v12.75.1 h1:HE8/uWED+QgyT6HIcRULqjMYWKhqQ1rkfa/ozcva1eQ=
github.com/essentialkaos/ek/v12 v12.75.1/go.mod h1:juDcZWOWaj1QmYShZkT9RzdqJ3n0tmeP/iq4sw5fQF0=
github.com/essentialkaos/redy/v4 v4.4.0 h1:6r6AkZiDkFWPqnvl0M+u7mcaaWQaeeiZOoLqLAMcnzQ=
github.com/essentialkaos/redy/v4 v4.4.0/go.mod h1:0TUOQZGzhRmZD13sCVUtYUYCa3Xd8v0zu2TgV6dwcHk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down

0 comments on commit 8902944

Please sign in to comment.