4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

FastAPI vs Vert.x ベンチマークとか感想とか

Last updated at Posted at 2020-10-23

AIをAPIにするためにPythonのFWを探していたが、FastAPIに出会って触ってみたらめっちゃ速いし良さそうだったのでプロジェクトでVertxをすでに技術選択していた自分にアチャーってなってる

ベンチマーク

Rails6が100同時で250req/secぐらいでるサーバーで確認

Requests per second:    245.42 [#/sec] (mean)
Time per request:       407.472 [ms] (mean)
Time per request:       4.075 [ms] (mean, across all concurrent requests)

OKってテキスト返すだけのサンプルプログラムベンチマーク
FastAPIはgunicorn -> uvicornx4で起動

100同時

Vert.x - Kotlin

Requests per second:    3207.38 [#/sec] (mean)
Time per request:       31.178 [ms] (mean)
Time per request:       0.312 [ms] (mean, across all concurrent requests)

FastAPI

Requests per second:    2703.43 [#/sec] (mean)
Time per request:       36.990 [ms] (mean)
Time per request:       0.370 [ms] (mean, across all concurrent requests)

1000同時

Vert.x - Kotlin

Requests per second:    3777.86 [#/sec] (mean)
Time per request:       264.700 [ms] (mean)
Time per request:       0.265 [ms] (mean, across all concurrent requests)
Transfer rate:          1080.97 [Kbytes/sec] received

FastAPI

Requests per second:    2746.82 [#/sec] (mean)
Time per request:       364.058 [ms] (mean)
Time per request:       0.364 [ms] (mean, across all concurrent requests)
Transfer rate:          413.10 [Kbytes/sec] received

10000同時

Vert.x - Kotlin

Requests per second:    3736.25 [#/sec] (mean)
Time per request:       2676.477 [ms] (mean)
Time per request:       0.268 [ms] (mean, across all concurrent requests)
Transfer rate:          1069.07 [Kbytes/sec] received

FastAPI

Requests per second:    3524.81 [#/sec] (mean)
Time per request:       2837.034 [ms] (mean)
Time per request:       0.284 [ms] (mean, across all concurrent requests)
Transfer rate:          218.69 [Kbytes/sec] received

感想

FastAPI良い。。。

  • 普通に使う分にはvertxとFastAPIは同程度の速度でしょう。FastAPIくそ速い
  • FastAPIはソースコードの量少なくてすむ、すぐかける
  • パフォーマンスは実用なら誤差範囲。

FWというより使う言語の好みの問題に収束しそう
私はVertxが好き。

  • 動かすまでにIDEがミスをかなり詳しく検知してくれる(静的型付け)
  • ディレクトリ構造気にせず作業できる
  • プロジェクトの構造を構築しやすい
  • Vertxはeventbusとか夢もある

技術選択してしまったポジショントークでVertxを擁護したいけど、FastAPIの良さにはもう文句でない。FastAPIは流行るでしょう。もう流行ってる。VertxはいつまでもマイナーFWです。。

FastAPI

  • APIドキュメントを自動リアルタイム生成
  • 開発中はリアルタイムにリロードしてくれるので楽
  • webの記事がvertxより充実している印象
  • 比べると圧倒的にシンプルでとっつきやすい
  • AIとつなぎ込みが簡単(のはず?)なのでPythonでバックエンドは完結できそうな感じある
  • だれが書いても同じような見通しの良さのコードになりそう→超重要
  • サーバーサイドを薄く、軽く、速く、という最近の流れにマッチしてる感じある
  • Docker使えばこちらもデプロイ簡単らしい。
  • C10K大丈夫
  • sessionは標準では無いっぽいのがAPI特化故か。issueは立ってる

Vertx

  • (Kotlinなら)静的型付けの楽さ。起動しなくてもタイポとか指摘してくれる
  • IDEの恩恵をフルに得られる。補完とかリファクタはIDEがある分一日の長の感じある
  • fat-jarつかえばデプロイかんたん(Javaいれたらサーバー構築完了の楽さ好き)
  • (私は)Kotlin書いてて楽しい
  • (OpenAPIのライブラリつかって開発)APIドキュメントはこちらも自動生成っぽいことにはなる
  • OpenAPI読み込めるの最高→重要
  • ロギングとかのJVM資産ある(これは私がPythonよく知らないだけなのかも。でもlog4jとか便利よね)
  • eventbusという夢
  • C10K大丈夫
  • 実はいろいろ揃っていて他に何も要らない感じはある。sessionとかあるので旧来風にsession cookieで認証維持とかできて楽
  • やろうとおもえばSpringすればDIもできる。なんでもできる

他のフレームワークとの比較

JVM言語とPythonなのでactixとかとくらべてエンジニアは集めやすそう。業務系なら鉄板SpringBootとか.Net MVCが情報量多くて良さそう。

4
4
0

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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?