Skip to content

Commit

Permalink
Merge pull request #43 from cvhariharan/master
Browse files Browse the repository at this point in the history
Add keepalive flag. Fixes issue #30
  • Loading branch information
nakabonne authored Oct 4, 2020
2 parents 9ad170f + 6f10403 commit e963eff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions attacker/attacker.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Options struct {
Workers uint64
MaxWorkers uint64
MaxBody int64
KeepAlive bool

Attacker Attacker
}
Expand Down Expand Up @@ -71,6 +72,7 @@ func Attack(ctx context.Context, target string, resCh chan *Result, metricsCh ch
vegeta.Workers(opts.Workers),
vegeta.MaxWorkers(opts.MaxWorkers),
vegeta.MaxBody(opts.MaxBody),
vegeta.KeepAlive(opts.KeepAlive),
)
}

Expand Down
25 changes: 14 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ type cli struct {
bodyFile string
maxBody int64

debug bool
version bool
stdout io.Writer
stderr io.Writer
debug bool
version bool
keepAlive bool
stdout io.Writer
stderr io.Writer
}

func main() {
Expand All @@ -60,6 +61,7 @@ func main() {
flagSet.Int64VarP(&c.maxBody, "max-body", "M", 0, "Maximum number of bytes to capture from response bodies")
flagSet.BoolVarP(&c.version, "version", "v", false, "Print the current version.")
flagSet.BoolVar(&c.debug, "debug", false, "Run in debug mode.")
flagSet.BoolVarP(&c.keepAlive, "keepalive", "K", false, "Use persistent connections if keepalive is set to true. (default false)")
flagSet.Usage = c.usage
if err := flagSet.Parse(os.Args[1:]); err != nil {
if !errors.Is(err, flag.ErrHelp) {
Expand Down Expand Up @@ -153,13 +155,14 @@ func (c *cli) makeOptions() (*attacker.Options, error) {
}

return &attacker.Options{
Rate: c.rate,
Duration: c.duration,
Timeout: c.timeout,
Method: c.method,
Body: body,
MaxBody: c.maxBody,
Header: header,
Rate: c.rate,
Duration: c.duration,
Timeout: c.timeout,
Method: c.method,
Body: body,
MaxBody: c.maxBody,
Header: header,
KeepAlive: c.keepAlive,
}, nil
}

Expand Down

0 comments on commit e963eff

Please sign in to comment.