12
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

3大Elixir HTTPクライアントバトル勃発:ピュアElixir実装「Req」 vs 最古参「HTTPoison」 vs Erlang由来「Hackney」

Last updated at Posted at 2024-12-15

この記事は、Elixir Advent Calendar 2024 シリーズ4 の15日目です

昨日は、 @RyoWakabayashiさん 「Advent of code 2015 Day 6 Part 2 を Livebook で楽しむ」 でした


piacere です、ご覧いただいてありがとございます :bow:

ピュアElixirで構築された新進気鋭の「Req」と、大昔からElixirを支え続けてきた「HTTPoison」、Erlang時代から脈々と受け継がれてきた「Hackney」の、3大Elixir HTTPクライアントをバトらせてみました

:xmas-tree: There are 13 Elixir Advent Calendar, making for a hot winter! :xmas-tree:

Over the past 7 years, Elixir has consistently been a top-ranking language in the programming category of the Advent Calendar, claiming the #1 spot last year. This year, too, Elixir is sure to stay at the top.

We’re feeling the excitement again this year… Please support or subscribe! :bow:

https://qiita.com/advent-calendar/2024/elixir
https://qiita.com/advent-calendar/2024/ranking/feedbacks/categories/programming_languages
image.png

事前準備

Livebookでライブラリをロードします

Notebook dependencies and setup
Mix.install([
  {:kino_benchee, "~> 0.1"}, 
  {:req, "~> 0.5"}, 
  {:httpoison, "~> 2.2"}, 
  {:hackney, "~> 1.20"}, 
])

小データ量のHTTPクライアント性能のバトル

コードブロックを追加し、下記コードを実行します

url = "https://api.github.com/rate_limit"
Benchee.run(
  %{
    "Req.get!" => fn -> Req.get!(url) end,
    "HTTPoison.get!" => fn -> HTTPoison.get!(url) end,
    ":hackney.request" => fn -> :hackney.request("get", url, [], "", []) end
  },
  memory_time: 2,
  reduction_time: 2
)

巷の評判通り、Reqが最高速です

裏側では、最も高速と言われる Finch を使っているので、当然と言えば当然かもですが

意外なのは、HTTPoisonが引けを取っていないことでしょうか … これは、JSONバトルにおけるPoison でも述べていたことですが、昔からあるHTTPoisonがかなり高速なことには、

image.png

巨大データ量のHTTPクライアント性能のバトル

今度は、1.9MByteとサイズが大きい NASAのデータ を拾う下記コードを実行します

url = "https://images-api.nasa.gov/search?q=space"
Benchee.run(
  %{
    "Req.get!" => fn -> Req.get!(url) end,
    "HTTPoison.get!" => fn -> HTTPoison.get!(url) end,
    ":hackney.request" => fn -> :hackney.request("get", url, [], "", []) end
  },
  memory_time: 2,
  reduction_time: 2
)

すると、先程は性能の出ていなかったHackneyが倍以上の速度を見せて、逆にReqとHTTPoisonは遅いという結果となりました

案外、この事実は広くは知られていないのでは?

image.png

p.s.このコラムが、面白かったり、役に立ったら…

image.png にて、どうぞ応援よろしくお願いします :bow:


明日は、 @RyoWakabayashiさんで 「Advent of code 2015 Day 7 Part 1 を Livebook で楽しむ」 です

12
1
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?