Bibek Pandey (7) [Avatar] Offline
#1
First off, I just want to say how amazing this book was for me to understand elixir/erlang/otp. It is very well-written and practical. I really was able to develop an intuitive feel of things. So thank you Sasa immensely for writing this book.

I had a question on Chapter 11, after you setup the web module which uses plug and the cowboy adapter, how exactly did you load test the module?

Were you using standard tools like curl or did you have a more elaborate load testing setup? How exactly did you achieve the 2 min load test of 20,000 / s. Cheers Bibek
sjuric (86) [Avatar] Offline
#2
Thanks for the nice feedback! I'm really glad you liked the book!

For load tests I used the wrk tool (see the repo's wiki for installation instructions).

Once you have the tool installed, you can find the load testing script with instructions in the load_test.exs file. A 2 minute test in todo_web folder will likely break, because of issues mentioned in the Performance section (page 284, PDF page 309). In the load test script, you can shorten the test by changing -d120s to some smaller value (e.g. -d20s) to get some results.

The optimized version resides in the todo_web_optimized folder. With those changes, a 2 minutes load test performs consistently. The notable changes are mentioned at the end of the Performance section, and if you open those files, you'll find more explanations in comments.

If you're using Erlang 18 and Elixir 1.2 you may want to run the code from the post-release-updates branch, which is updated to work with the most recent Erlang/Elixir.
Bibek Pandey (7) [Avatar] Offline
#3
Awesome Sasa - thanks. I got the wrk tool to run. Thank you.

With your 'optimized' updates to database_worker and database involving mnesia, it seems fitting for the next book edition to perhaps have a section on mnesia. Pretty neat to see some readable elixir code using mnesia!

Bibek
sjuric (86) [Avatar] Offline
#4
Bibek Pandey wrote:Awesome Sasa - thanks. I got the wrk tool to run. Thank you.

With your 'optimized' updates to database_worker and database involving mnesia, it seems fitting for the next book edition to perhaps have a section on mnesia. Pretty neat to see some readable elixir code using mnesia!

Bibek


I should note that I used mnesia here because it was a simple solution that didn't require any additional dependencies. In real life, I'd rather use an external database server, such as PostgreSQL, to hold the important data. While mnesia has some compelling features, it's also somewhat esoteric. I occasionally use it to hold some non-essential data in a cluster (e.g. some caches), and I think this is it's sweet spot. It's fairly simple to setup, does the job, and you don't need any external dependencies. Everything runs in the same OS process. But when it comes to "essential" data, I personally still prefer to keep it in a dedicated database server.
Bibek Pandey (7) [Avatar] Offline
#5
Makes sense. I see a lot of references to using ETS in elixir code but not soo much mnesia, maybe for the reason you describe. Well, if you ever do a 2nd version, I wouldn't mind a section on Postgres then smilie

I have another question for you.

I tried using the runtime_tools -- specifically the observer. I was salivating to the idea of being able to drill into the ETS data for my application. However, I got an error

$ iex --hidden --name observer@127.0.0.1 --cookie game
Erlang/OTP 18 [erts-7.2] [source] [async-threads:10] [kernel-poll:false]

Interactive Elixir (1.2.3) - press Ctrl+C to exit (type h() ENTER for help)
iex(observer@127.0.0.1)1> :observer.start

16:37:41.654 [error] WX ERROR: SMP emulator required (start with erl -smp)
{:error,
{:not_smp,
[{:wxe_server, :start, 1, [file: 'wxe_server.erl', line: 65]},
{:wx, :new, 1, [file: 'wx.erl', line: 115]},
{:observer_wx, :init, 1, [file: 'observer_wx.erl', line: 96]},
{:wx_object, :init_it, 6, [file: 'wx_object.erl', line: 337]},
{:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 240]}]}}
iex(observer@127.0.0.1)2>

Where do I specify erl -smp? Were you doing this implicitly in your setup?

Thanks again!

Cheers,
Bibek
sjuric (86) [Avatar] Offline
#6
If you have more than one core, smp is enabled by default. If it's not, you could indeed provide --smp flag to force it. See here for more info.

When it comes to releases, you need to create rel/vm.args file, and there specify additional Erlang options. It's best to build the release once, then take the existing file which will reside in rel/your_app/releases/VSN/vm.args (where VSN is version number), copy its contents into rel/vm.args, modify it, and rebuild the release. You should then commit rel/vm.args into your repo.

If all went well, when you start the console you should see something like
[smp:x:y]
in the first printed line (Erlang info).