Skip to content

Commit

Permalink
Rename 'idle xacts' to plural form.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Jun 23, 2020
1 parent 7496042 commit b229638
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Expand Up @@ -9,12 +9,12 @@ import (
func Start(ctx context.Context, c *Config) error {
var wg sync.WaitGroup

if c.IdleXact {
if c.IdleXacts {
wg.Add(1)
go func() {
defer wg.Done()

err := runIdleXactWorkload(ctx, c)
err := runIdleXactsWorkload(ctx, c)
if err != nil {
log.Errorf("idle transactions workload failed: %s", err)
}
Expand Down
32 changes: 16 additions & 16 deletions app/cmd/main.go
Expand Up @@ -17,15 +17,15 @@ var (

func main() {
var (
showVersion = kingpin.Flag("version", "show version and exit").Default().Bool()
logLevel = kingpin.Flag("log-level", "set log level: debug, info, warn, error").Default("warn").Envar("NOISIA_LOG_LEVEL").String()
postgresConninfo = kingpin.Flag("conninfo", "Postgres connection string (DSN or URL), must be specified explicitly").Default("").Envar("NOISIA_POSTGRES_CONNINFO").String()
jobs = kingpin.Flag("jobs", "Run workload with specified number of workers").Default("1").Envar("NOISIA_JOBS").Uint16()
idleXact = kingpin.Flag("idle-xact", "Run idle transactions workload").Default("false").Envar("NOISIA_IDLE_XACT").Bool()
idleXactNaptimeMin = kingpin.Flag("idle-xact.naptime-min", "Min transactions naptime, in seconds").Default("5").Envar("NOISIA_IDLE_XACT_NAPTIME_MIN").Int()
idleXactNaptimeMax = kingpin.Flag("idle-xact.naptime-max", "Max transactions naptime, in seconds").Default("20").Envar("NOISIA_IDLE_XACT_NAPTIME_MAX").Int()
rollbacks = kingpin.Flag("rollbacks", "Run rollbacks workload").Default("false").Envar("NOISIA_ROLLBACKS").Bool()
rollbacksRate = kingpin.Flag("rollbacks.rate", "Number of transactions per second (per worker)").Default("10").Envar("NOISIA_ROLLBACKS_RATE").Int()
showVersion = kingpin.Flag("version", "show version and exit").Default().Bool()
logLevel = kingpin.Flag("log-level", "set log level: debug, info, warn, error").Default("info").Envar("NOISIA_LOG_LEVEL").String()
postgresConninfo = kingpin.Flag("conninfo", "Postgres connection string (DSN or URL), must be specified explicitly").Default("").Envar("NOISIA_POSTGRES_CONNINFO").String()
jobs = kingpin.Flag("jobs", "Run workload with specified number of workers").Default("1").Envar("NOISIA_JOBS").Uint16()
idleXacts = kingpin.Flag("idle-xacts", "Run idle transactions workload").Default("false").Envar("NOISIA_IDLE_XACTS").Bool()
idleXactsNaptimeMin = kingpin.Flag("idle-xacts.naptime-min", "Min transactions naptime, in seconds").Default("5").Envar("NOISIA_IDLE_XACTS_NAPTIME_MIN").Int()
idleXactsNaptimeMax = kingpin.Flag("idle-xacts.naptime-max", "Max transactions naptime, in seconds").Default("20").Envar("NOISIA_IDLE_XACTS_NAPTIME_MAX").Int()
rollbacks = kingpin.Flag("rollbacks", "Run rollbacks workload").Default("false").Envar("NOISIA_ROLLBACKS").Bool()
rollbacksRate = kingpin.Flag("rollbacks.rate", "Number of transactions per second (per worker)").Default("10").Envar("NOISIA_ROLLBACKS_RATE").Int()
)
kingpin.Parse()
log.SetLevel(*logLevel)
Expand All @@ -36,13 +36,13 @@ func main() {
}

config := &app.Config{
PostgresConninfo: *postgresConninfo,
Jobs: *jobs,
IdleXact: *idleXact,
IdleXactNaptimeMin: *idleXactNaptimeMin,
IdleXactNaptimeMax: *idleXactNaptimeMax,
Rollbacks: *rollbacks,
RollbacksRate: *rollbacksRate,
PostgresConninfo: *postgresConninfo,
Jobs: *jobs,
IdleXacts: *idleXacts,
IdleXactsNaptimeMin: *idleXactsNaptimeMin,
IdleXactsNaptimeMax: *idleXactsNaptimeMax,
Rollbacks: *rollbacks,
RollbacksRate: *rollbacksRate,
}

if err := config.Validate(); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions app/config.go
Expand Up @@ -5,21 +5,21 @@ import (
)

type Config struct {
PostgresConninfo string
Jobs uint16 // max 65535
IdleXact bool
IdleXactNaptimeMin int
IdleXactNaptimeMax int
Rollbacks bool
RollbacksRate int
PostgresConninfo string
Jobs uint16 // max 65535
IdleXacts bool
IdleXactsNaptimeMin int
IdleXactsNaptimeMax int
Rollbacks bool
RollbacksRate int
}

func (c *Config) Validate() error {
if c.PostgresConninfo == "" {
return errors.New("'conninfo' is not specified")
}

if c.IdleXactNaptimeMin < 1 || c.IdleXactNaptimeMin > c.IdleXactNaptimeMax {
if c.IdleXactsNaptimeMin < 1 || c.IdleXactsNaptimeMin > c.IdleXactsNaptimeMax {
return errors.New("wrong 'idle-xact.naptime-min' or 'idle-xact.naptime-max' specified")
}

Expand Down
4 changes: 2 additions & 2 deletions app/idle_xacts.go
Expand Up @@ -8,7 +8,7 @@ import (
"time"
)

func runIdleXactWorkload(ctx context.Context, config *Config) error {
func runIdleXactsWorkload(ctx context.Context, config *Config) error {
log.Infoln("Starting idle transactions workload")

pool, err := pgxpool.Connect(context.Background(), config.PostgresConninfo)
Expand All @@ -24,7 +24,7 @@ func runIdleXactWorkload(ctx context.Context, config *Config) error {
// run workers only when it's possible to write into channel (channel is limited by number of jobs)
case guard <- struct{}{}:
go func() {
naptime := time.Duration(rand.Intn(config.IdleXactNaptimeMax-config.IdleXactNaptimeMin)+config.IdleXactNaptimeMin) * time.Second
naptime := time.Duration(rand.Intn(config.IdleXactsNaptimeMax-config.IdleXactsNaptimeMin)+config.IdleXactsNaptimeMin) * time.Second

log.Debugln("starting xact with naptime %s", naptime)
err := startSingleIdleXact(context.Background(), pool, naptime)
Expand Down

0 comments on commit b229638

Please sign in to comment.