Type rate as uint64
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
|||||||
// TODO: Add timeouts
|
// TODO: Add timeouts
|
||||||
type Client struct {
|
type Client struct {
|
||||||
http.Client
|
http.Client
|
||||||
rate uint
|
rate uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// Response represents the metrics we want out of an http.Response
|
// Response represents the metrics we want out of an http.Response
|
||||||
@@ -25,12 +25,12 @@ type Response struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient returns an initialized Client
|
// NewClient returns an initialized Client
|
||||||
func NewClient(rate uint) *Client {
|
func NewClient(rate uint64) *Client {
|
||||||
return &Client{http.Client{}, rate}
|
return &Client{http.Client{}, rate}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drill loops over the passed reqs channel and executes each request.
|
// Drill loops over the passed reqs channel and executes each request.
|
||||||
// It is throttled to the qps specified in the initializer
|
// It is throttled to the rate specified in the initializer
|
||||||
func (c *Client) Drill(reqs chan *http.Request, res chan *Response) {
|
func (c *Client) Drill(reqs chan *http.Request, res chan *Response) {
|
||||||
throttle := time.Tick(time.Duration(1e9 / c.rate))
|
throttle := time.Tick(time.Duration(1e9 / c.rate))
|
||||||
for req := range reqs {
|
for req := range reqs {
|
||||||
|
|||||||
6
main.go
6
main.go
@@ -16,7 +16,7 @@ func init() {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var (
|
var (
|
||||||
rate = flag.Uint("rate", 50, "Requests per second")
|
rate = flag.Uint64("rate", 50, "Requests per second")
|
||||||
targetsf = flag.String("targets", "targets.txt", "Targets file")
|
targetsf = flag.String("targets", "targets.txt", "Targets file")
|
||||||
ordering = flag.String("ordering", "random", "Attack ordering [sequential, random]")
|
ordering = flag.String("ordering", "random", "Attack ordering [sequential, random]")
|
||||||
duration = flag.Duration("duration", 10*time.Second, "Duration of the test")
|
duration = flag.Duration("duration", 10*time.Second, "Duration of the test")
|
||||||
@@ -84,8 +84,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func attack(targets Targets, ordering string, rate uint, duration time.Duration, rep Reporter) {
|
func attack(targets Targets, ordering string, rate uint64, duration time.Duration, rep Reporter) {
|
||||||
hits := make(chan *http.Request, rate*uint((duration).Seconds()))
|
hits := make(chan *http.Request, rate*uint64((duration).Seconds()))
|
||||||
defer close(hits)
|
defer close(hits)
|
||||||
responses := make(chan *Response, cap(hits))
|
responses := make(chan *Response, cap(hits))
|
||||||
defer close(responses)
|
defer close(responses)
|
||||||
|
|||||||
Reference in New Issue
Block a user