-
Notifications
You must be signed in to change notification settings - Fork 66
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
before_scenario
and parallel
options
#437
Comments
👋 Hello there - thanks for opening an issue! 💚 I think I gotta think on that a bit more. My first reaction was "yeah" then I was like "I'm not sure" then reading through the use cases in the docs I found this one:
And at least that one would need to execute for each one in However, quite frankly, Smells like we might need another hook type but boi would I not be looking forward to that (I wrote the hooks many years ago during a longer vacation and the complexity they bring is big vs. how often I think they're used) Can you tell me what your use case is (broadly speaking)? I'd like to think through it - plus it's a feature I think is rarely used so reinforcement for its usefulness is appreciated 😁 |
🎉 Thanks! So, I'm testing out different modules that all implement the same behavior. Each module starts up a process or a supervision tree of processes to do basically the same job, but I want to compare the performance of individual calls but also what happens as the processes queues get more and more loaded. Here's the sanitized version of my benchee script: definitions = [ ... ]
inputs =
Map.new(definitions, fn definition ->
{
"#{definition[:module_under_test]}: #{inspect(definition[:module_under_test_opts])}",
definition
}
end)
Benchee.run(
%{
"foo" => fn {%{
module_under_test: module_under_test,
module_under_test_opts: module_under_test_opts
}, %{pid: _pid, users: users}} ->
user = Enum.random(users)
module_under_test.foo(user.id)
end,
"update" => fn {%{
module_under_test: module_under_test,
module_under_test_opts: module_under_test_opts
}, %{pid: _pid, users: users}} ->
user = Enum.random(users)
module_under_test.bar(user.id, %{attr1: "Biz Buzz #{:random.uniform(5000)}"})
end
},
warmup: 2,
time: 5,
inputs: inputs,
parallel: 2,
before_scenario: fn %{
module_under_test: module_under_test,
module_under_test_opts: module_under_test_opts
} = input ->
{:ok, pid} = module_under_test.start_link(module_under_test_opts)
Process.unlink(pid)
users =
Enum.map(0..20, fn i ->
{:ok, user} =
module_under_test.create(%{name: "User #{i}", email: "user#{i}@example.com"})
user
end)
{input, %{users: users, pid: pid}}
end,
after_scenario: fn {_input, %{pid: pid}} ->
Process.exit(pid, :kill)
Process.sleep(500)
end,
formatters: [
{Benchee.Formatters.HTML, file: "benchee_output.html"},
{Benchee.Formatters.CSV, file: "benchee_output.csv"},
Benchee.Formatters.Console
]
) The I could use something like All of that is also making me wonder, maybe this isn't a job for |
Thanks for sharing! I mean the reason of existence for A workaround that might work for you right now would be to have each Enum.each(modules, fn module_under_test ->
former_before_scenario()
Benche.run(%{
# using module_under_test
save: "folder/cool_bench#{module_under_test}.benchee"
}
end)
Benchee.report(load: "folder/cool_benchee_*") (written from memory, untested) I asked @pablocostass quickly and with some time (this is a longer thing) I'll review wording. But most likely I'd change it so that That said, the initial changes to "fix" https://github.com/bencheeorg/benchee/blob/main/lib/benchee/benchmark/runner.ex#L81-L119 |
Thanks very much! I've been using your workaround and I've got a version that's been working fine. Now I have the harder task of interpreting my results 😅 Thanks again! |
Is it by design that
before_scenario
runs multiple times ifparallel
is greater than1
? I'm trying to setup a single process which can be accessed by the parallel run scenarios so that I can test how processes scale under load. If this is by design I'll find a way to work around it, but it seems like maybebefore_scenario
should just run once for each scenario no matter the value ofparallel
🤔The text was updated successfully, but these errors were encountered: