mtrudel / bandit

Bandit is a pure Elixir HTTP server for Plug & WebSock applications
MIT License
1.67k stars 80 forks source link

Performance Cowboy 2 vs Bandit Phoenix adapter #372

Closed svsool closed 3 months ago

svsool commented 3 months ago

πŸ‘‹ Hello Mat!

I did a quick load test on an MBP M1 (elixir 1.14.0-otp-25 / erlang 25.0.4) with one Erlang scheduler online (+S = 1 in VM args) using k6, and wanted to share some results.

TL;DR: RPS seems to be lower (18k vs 23k) with Bandit vs Cowboy 2.7 and elixir 1.14.0-otp-25 / erlang 25.0.4, and similar (25k vs 24k) with elixir 1.17.1-otp-27 / erlang 27.0.

Phoenix with Cowboy Adapter (2 x runs)

image

image

Phoenix with Bandit Adapter (2 x runs)

image

image

Steps to reproduce:

I also tried setups from this repo (related post) except response modified to match original test, sleep removed and number of schedulers set to 1.

A bare Cowboy 1.x setup gave 40k+ RPS on a single core using the same echo test.

image

And with Cowboy 2.7 from that same repo.

image

With Bandit 1.5 + Plug 1.16, no Phoenix (bandit_test.zip)

image

Also tried to run Bandit's own benchmarks locally using mix benchmark cowboy bandit@main, but unfortunately got the following error:

Let me know if additional tweaking required to achieve better results with Bandit vs Cowboy and whether results are relatively comparable when reproduced using your hardware.

Thanks!

svsool commented 3 months ago

Did re-run tests with latest elixir 1.17.1-otp-27 / erlang 27.0, and with the same synthetic test Bandit performs slightly better than Cowboy 2.7 with http 1.1 when used as Phoenix adapter, and better than Cowboy 2.7 with a standalone setup.

Seems standalone Cowboy 1.x performs worse with the latest elixir / erlang build vs elixir 1.14.0-otp-25 / erlang 25.0.4 build overall, but better than standalone Bandit.

Phoenix with Cowboy Adapter

image

image

Phoenix with Bandit Adapter

image

image

With Bandit 1.5 + Plug 1.16, no Phoenix

image

image

With Cowboy 1.x

image

image

With Cowboy 2.7

image

image

svsool commented 3 months ago

Feel free to re-open if going to re-test and compare relative numbers yourself or if there are any other possible improvements. πŸ‘‹

mtrudel commented 3 months ago

Thanks for the report! I'd not seen k6 before but it looks like exactly the client-side tool I'd wanted access to when I wrote the benchmark library (the client implementation there is pretty sad). What do you think would be involved in moving the mtrudel/benchmark suite over to use k6 on the client side?

svsool commented 3 months ago

hi @mtrudel, k6 from my experience is relatively easy to set up, and there are examples on running it with github actions (see related k6-action), what comes to test cases which bandit benchmark suit requires you'd probably know the details the best.