Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keepalive flag. Fixes issue #30 #43

Merged
merged 1 commit into from
Oct 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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