l00ker

l00ker

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

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:

Most Liked

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

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

Last Post!

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:

Where Next?

Popular in Discussions Top

ricklove
I was just introduced to Elixir and Phoenix. I was told about the 2 million websocket test that was done 2 years ago. From my research, t...
New
AlexMcConnell
The reason that Rails is as popular as it is is because it’s very easy for relatively inexperienced developers to get a lot of work done....
588 20046 166
New
chulkilee
Here are the list of HTTP client libraries/wrappers, and some thoughts on HTTP client in general. I’d like to hear from others how they w...
New
PragTob
Hello everyone, I know we had quite some threads (read through lots of them) about background job processing but it remains a hotly deba...
New
marciol
Please, let me know if this kind of discussion already took place in another topic . Hi all, how do you consider if is better to build ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
mmmrrr
Just saw that dhh announced https://hotwire.dev/ Is it just me or is this essentially live view? :smiley: Although I like the “iFrame-e...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement