codesenberg / bombardier

Fast cross-platform HTTP benchmarking tool written in Go
MIT License
6.03k stars 315 forks source link

Add new flag 'randid' #57

Closed l0nax closed 4 years ago

l0nax commented 4 years ago

This PR adds a new flag named randid, when it's enabled it replaces <[_id]> with a random uint32 in the request body.

This means the following body:

{"name":"new_new_new<[_id]>","email":"verynice@very.com","password":"not_so_good"}

will be replaced (for example) with the following content – if randid is enabled:

{"name":"new_new_new23154","email":"verynice@very.com","password":"not_so_good"}

To decrease the "random number generation time" I use fastrand, on my PC it was 94 % faster than the normal math.rand function.

Raw benchmark results on my PC:

goos: linux
goarch: amd64
pkg: github.com/valyala/fastrand
BenchmarkUint32n-2                      100000000           10.2 ns/op         0 B/op          0 allocs/op
BenchmarkRNGUint32n-2                   653525556            1.84 ns/op        0 B/op          0 allocs/op
BenchmarkRNGUint32nWithLock-2           34382449            31.4 ns/op         0 B/op          0 allocs/op
BenchmarkRNGUint32nArray-2              50329755            59.0 ns/op         0 B/op          0 allocs/op
BenchmarkMathRandInt31n-2               27102625            43.5 ns/op         0 B/op          0 allocs/op
BenchmarkMathRandRNGInt31n-2            259698030            4.62 ns/op        0 B/op          0 allocs/op
BenchmarkMathRandRNGInt31nWithLock-2    34518178            39.7 ns/op         0 B/op          0 allocs/op
BenchmarkMathRandRNGInt31nArray-2        6467250           184 ns/op           0 B/op          0 allocs/op

Since in #55 was discussed to implement another flag where the place holder values will be read from a file I'm unsure if this PR covers the complete requested feature of #55.

But since I'm also needed a possibility to have a "placeholder var" in the body I implemented this one with "random ID's".

codesenberg commented 4 years ago

This seems to be a bit hacky and there are no tests. Even if there were tests, I'd rather have some general solution that would allow this and other types of request generation. I had some functionality like that planned, but don't have time to implement features these days.