The State of Async Web Frameworks

about me

Organizer

@raiderrobert 

twitter | github | medium

where I've contribued

Web Framework

Async

What is the Problem?

Big O Notation

Google 1999

Google 2009

Bigger payloads per page

More requests per page

More time spent on them

By More People

Exponential demand

Throw more hardware at it?

Can we do more with the same?

Sharing CPU?

  • multi-processing uses lots of RAM
  • has 2-5x switching costs of threads

Context Switching

Processes
Threads

Third-thing

Apache vs Nginx

threads vs workers

chart from dreamhost

chart from dreamhost

How though?

Nginx solved it. All done, right?

Not quite

Web Framework

Async

Sync

Classic HTTP request-response cycle:

- Request comes in

- Response goes out

Async

WS, SSE, MQTT, GRPC, etc:

1) Negotiate a connection
2) Request comes in OR

3) Response goes out

4) Repeat (2) or (3) maybe

5) Close connection

 

 

async

user threads

coroutines

greenthreads

fibers

Sharing CPU for IO

Network
User Input

Disk*

Preemptive

Scheduler in control.

Acts like modern OS threads/processes and will switch "contexts" per a strategy.

Cooperative

Task is in control.

Can potentially block and not "context" switch to another task.

multi-tasking

Preemptive

Erlang/Elixir

Cooperative

Nodejs/JS

Python asyncio

PHP (swoole)

Ruby (nio4r)

Kotlin coroutines

Go

Haskell

Rust (Tokio)

My utterly imperfect but best attempt to classify

But what about X language's implementation?

Something might exist,

but I can't find it.

Let's get back to the framework part of this talk

Any Framework in

  • Elixir
  • Nodejs
  • Go 
  • Haskell

Some Frameworks in

  • Python
  • PHP
  • Rust
  • Kotlin

Python

  • Starlette
  • Tornado
  • Japronto 

PHP

  • workerman
  • swoft 
  • amp

Rust

  • actix-web
  • thruster 
  • hyper

Ruby :(

Kotlin

  • Ktor

Haskell

  • Yesod

Elixir

  • Phoenix

Nodejs

  • Koa
  • Fastify
  • Express

Go

  • gin
  • echo
  • fasthttp

Why isn't everyone doing this?

  • Not everyone has this scaling problem
  • Harder to write async code than sync code
  • Newer tech so tooling and ecosystem support lacking

Pay Off

The State of Async Frameworks 2019

By Robert Roskam

The State of Async Frameworks 2019

  • 332