tsenart / vegeta

HTTP load testing tool and library. It's over 9000!
http://godoc.org/github.com/tsenart/vegeta/lib
MIT License
23.51k stars 1.36k forks source link

Any existing examples of generator to use with -lazy ? #353

Closed Kimserey closed 5 years ago

Kimserey commented 5 years ago

Question

I would like to generate random body for each POST requests executed. I read the post from thisdata.com and the issues linked to that random body scenario and saw that it all pointed to having a generator providing a stream of input to vegeta using -lazy option.

I understand that it can be written in any language/script but I am having a hard time to understand how to write one and even find an example of a generator that could be piped to vegeta.

Would you have an existing example?

tsenart commented 5 years ago

Perhaps you’d find the new JSON target format easier to produce?

Kimserey commented 5 years ago

Thanks for the reply @tsenart , yes JSON target format will definitely make it easier.

But I am still trying to understand how does -lazy work. For example if I make a script that prints every 10 seconds a JSON formatted target for a period of 1 minute, does that mean that vegeta will attack every 10 seconds for a duration of 1 minute?

Would the following be the right command?

> my_script_generator.sh | vegeta -lazy
tsenart commented 5 years ago

Your script should produce targets as fast as it can with no sleeping in between targets.

Kimserey commented 5 years ago

Your script should produce targets as fast as it can with no sleeping in between targets.

Got it, and vegeta would select the latest target generated?

tsenart commented 5 years ago

No. Your generator blocks if vegeta attack is too slow to consume targets. On the other hand, if vegeta attack is too fast, it won’t be able to sustain your desired request rate. Generated targets are not dropped. By the way, if you use CTRL-C to stop the attack, it’s normal to see a broken pipe error; basically it’s your generator that is trying to write to a closed pipe, because vegeta already quit.

Kimserey commented 5 years ago

Your generator blocks if vegeta attack is too slow to consume targets. On the other hand, if vegeta attack is too fast, it won’t be able to sustain your desired request rate.

Oh okay, my bad, this was due to my misunderstanding of how pipe worked.

So if I were to create a test for a duration of 10 minutes, the requirements for the generator would be:

  1. generate value faster than the rate
  2. generate for a duration of 10 minutes

Otherwise the command my_script_generator.sh | vegeta -lazy -rate=10 -duration=10m will never stop right?

Asking because I'd like to pipe it then to a result file my_script_generator.sh | vegeta -lazy -rate=10 -duration=10m > results.bin. At some point in time, my_script_generator.sh has to terminate by itself in order to have the whole command completed.

tsenart commented 5 years ago

Yes to point number 1. The second isn’t needed. vegeta attack will stop after 10 minutes and your script will fail to write to stdout with the broken pipe error.

Kimserey commented 5 years ago

It doesn't seem to stop I am on Windows running vegeta v12.1.0. It will wait until my generator completes. If the generator never completes, I have to CTRL+C.`

I've created a generator using dotnet which is basically a console application writing on standard output infinitely and running with the following command on CMD:

dotnet mygenerator.dll | vegeta -lazy -rate=10 -duration=10m

But this question can be closed, as I understand now how to get -lazy to work.

Kimserey commented 5 years ago

Just to clarify a bit further, the generator wouldn't need run for a special duration - it would only need to ensure the rate and the amount of targets to be generated.

For example if I were to run a test for 10 rps for a duration of 1 min, the requirements for the generator would be that it needs to generate 600 targets (10 rps * 60 sec), it will then terminate naturally and vegeta will read the targets at its own rate.

tsenart commented 5 years ago

Vegeta reads targets on demand when -lazy=true. You can use buffered IO to stdout or not. If you don’t, then your script will block waiting between each target read.