Seastar (C++ Async Framework)

For building HTTP server to handle huge load. Invented in 2010. In 2015 ScyllaDB started using it

Architecture

Suppose machine has 1 CPU(4 cores on it)
Seastar will create 1 thread is allocated per CPU core, ie 4 threads. Each thread is binded to Core(CPU Affinity)
Each CPU core acts as an isolated, self-contained server with its own RAM, network, disk etc. This avoids Context Switching, IPC and This makes it Ultra Fast


Each core has its seperate RAM partition

user_id = "A" --> |Hash| = 6. 6 % 4 = 2 (Shard 2)

|----------------------------Physical Machine 1 CPU (4 Cores)---------------------|
|                                                                                 |
| RAM |0-25|               |26-50|            |51-75|             |76-100|        |
|       /\                    /\                /\                  /\            |
| |---- Core 0 -----| |---- Core 1 -----| |---- Core 2 -----| |---- Core 3 -----| |
| | Thread 0        | | Thread 1        | | Thread 2        | | Thread 3        | |
| | Hashes ending 00| | Hashes ending 01| | Hashes ending 02| | Hashes ending 03| |
| |-----------------| |-----------------| |-----------------| |-----------------| |
|                                                                                 |
|---------------------------------------------------------------------------------|
        

Code

#include <seastar/core/app-template.hh>
#include <iostream>

int main(int argc, char** argv) {
    seastar::app_template app;

    return app.run(argc, argv, [] {
        std::cout << "Hello from Seastar!" << std::endl;
        return seastar::make_ready_future<>();
    });
}