l00ker

l00ker

This popped up in my Google news feed last night…

Concurrency in modern programming languages: Rust vs Go vs Java vs Node.js vs Deno

That first thing that struck me about the article – given the title – is that Erlang and/or Elixir (I would think Elixir should considered a “modern programming language”) weren’t even mentioned, much less, even considered for a benchmark test.

Never the less, after reading through the article(s) (7 in all), I decided to tinker just for fun. Even though the benchmarks seem meaningless (as pointed out in one or more of the comments), I wondered how well Elixir would preform, so I created a simple Elixir app using only Cowboy w/Plug to serve the html file like the other examples in the benchmark tests.

mix new plug_test --sup

# lib/plug_test.ex
defmodule PlugTest do
  import Plug.Conn

  def init(options), do: options

  def call(conn, _opts) do
    Process.sleep(200)

    conn
    |> put_resp_header("connection", "keep-alive")
    |> put_resp_content_type("text/html; charset=utf-8")
    |> send_file(200, "hello.html")
  end
end

# hello.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Hello!</title>
  </head>
  <body>
    <h1>Hello!</h1>
    <p>Hi from Elixir</p>
  </body>
</html>

Notice the Process.sleep(200) in call/2 above. In the code the author wrote for rust, go, etc., he introduces a 2 second sleep every tenth request. I’m currently not aware of a way to do that (?), so I just decided to sleep each request process for 200 ms instead.

Here’s what I got after 2 back-to-back runs of ab -c 100 -n 10000 http://localhost:4000/

Server Software:        Cowboy
Server Hostname:        localhost
Server Port:            4000

Document Path:          /
Document Length:        178 bytes

Concurrency Level:      100
Time taken for tests:   20.483 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      4090000 bytes
HTML transferred:       1780000 bytes
Requests per second:    488.20 [#/sec] (mean)
Time per request:       204.833 [ms] (mean)
Time per request:       2.048 [ms] (mean, across all concurrent requests)
Transfer rate:          194.99 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.5      0       5
Processing:   200  202   1.1    202     211
Waiting:      200  201   1.0    201     210
Total:        201  202   1.5    202     215

Percentage of the requests served within a certain time (ms)
  50%    202
  66%    202
  75%    203
  80%    203
  90%    204
  95%    205
  98%    206
  99%    209
 100%    215 (longest request)
Server Software:        Cowboy
Server Hostname:        localhost
Server Port:            4000

Document Path:          /
Document Length:        178 bytes

Concurrency Level:      100
Time taken for tests:   20.490 seconds
Complete requests:      10000
Failed requests:        0
Total transferred:      4090000 bytes
HTML transferred:       1780000 bytes
Requests per second:    488.04 [#/sec] (mean)
Time per request:       204.901 [ms] (mean)
Time per request:       2.049 [ms] (mean, across all concurrent requests)
Transfer rate:          194.93 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.4      0       4
Processing:   200  202   1.1    202     211
Waiting:      200  201   0.9    201     211
Total:        201  202   1.3    202     212

Percentage of the requests served within a certain time (ms)
  50%    202
  66%    202
  75%    203
  80%    203
  90%    204
  95%    204
  98%    206
  99%    208
 100%    212 (longest request)

I ran the above benchmarks on my workstation PC with the following specs:

Ubuntu Linux 20.04.1
Intel(R) Core™ i7-4770K CPU @ 3.50GHz w/ 8 cores & 16GB of memory

Erlang: 24.2.1
Elixir: 1.13.2-otp-24

I know the article is almost pointless, but what are your thoughts?

Stuff like this seems to pop up all time as well as the flurry of articles with titles like The Top 10 Backend Programming Languages You Should Know In 2022 etc., that show up near the beginning of the year, most all of which, hardly ever mention Elixir. :frowning:

First 6 of 6 Posts Switch mode

kartheek

kartheek

If someone is trying to serve a static hello.html and benchmark it - they should also include nginx, apache in it :smile: .

Real fun is inside the comments section - don’t miss it.

All you demonstrated is that thread sleep works in all languages, and that overhead is significantly smaller than 200ms. You did not really benchmark the various language / server combos.

When you add 2 second delay every 10 requests you make the comparison totally meaningless. You are mesuring delays, not the code.

Reading the file in every loop mesures reading from disk, not actual program performance.

Author’s response - comment1, comment2.


Most of the performance and benchmark articles are pointless. I skim through these kind of articles and enjoy comments section.

l00ker

l00ker OP

Yeah. That’s exactly what I do 99% of the time as well. It’s just that this one was about concurrency, and when I saw how it was being benchmarked, I was mostly curious to see how well the BEAM’s Process.sleep/1 stacked up against all the others! :laughing:


I don’t have an account there or I may have left a comment about Erlang/Elixir with a link to the video of Saša’s awesome talk The Soul of Erlang and Elixir

ityonemo

ityonemo

Check out the code for process.sleep! It’s pretty instructive

kartheek

kartheek

Author updated the article - he has overwritten original images. Some of the context for comments is lost. He should have created 8th article in the series with new changes.

l00ker

l00ker OP

I see someone named Patrice Gauthier finally mentioned Elixir and the BEAM in this comment.

If this person is a member of the Elixir Forum - Thank you! :clap:

dimitarvp

dimitarvp

HAHAHA :003: That really made me laugh for solid half a minute.

I absolutely loved how defensive the author became in the comments: “I wanted to write something like this for a long time and it started dragging on so I just put something out the door”, which is a super weird statement! Not like he was a journalist on a deadline, right? I guess a lot of people are addicted to getting attention on the net, I don’t know.

And he says that on a topic where a ton of people would love more benchmarks, and were curious and were of course bound to rip it apart. Not sure what was he expecting. :man_facepalming:

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 91898 914
New
AstonJ
The obligatory hello world thread! Who are you and where are you from? :stuck_out_tongue:
4616 55835 594
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
mudasobwa
While I am working on the Language Agnostic Code Audit SaaS, which uses MetaAST (spoiler: I am expecting it to be in a good shape for ann...
New

We're in Beta

About us Mission Statement