webx-net / webx

A DSL and framework for hypermedia driven web backends, and REST APIs
https://webx.sh
6 stars 1 forks source link

Asynchronization and parallelization #5

Closed WilliamRagstad closed 9 months ago

WilliamRagstad commented 9 months ago

Using inspiration from the actor model, we can safely share a mutable reference to a thread-unsafe instance of deno_code::JsRuntime between our web servers' asynchronous handler functions running as Future tasks in tokio threads. The achieved architecture looks like the following:

graph TB
    A["Main (Thread)"]
    Dev["Dev Mode Features (Thread)"]
    subgraph Tokio["Tokio Runtime (Thread Pool)"]
        W["Web Server"]
        C["Worker 1"]
        D["Worker 2"]
        E["Worker N"]
    end
    F["JS Runtime Manager (Thread + Singleton)"]

    A -->|"Starts"| F
    A -->|"Starts"| W
    A -.->|"Starts"| Dev
    W -->|"Starts"| C
    W -->|"Starts"| D
    W -->|"Starts"| E
    C -->|"Accesses"| F
    D -->|"Accesses"| F
    E -->|"Accesses"| F
    Dev -.->|"Accesses"| F

    style Tokio fill:#803037

Closes