Skip to content

Runtime bottleneck #4

@WilliamRagstad

Description

@WilliamRagstad

A single WXRuntime thread holds a context with HashMap<WXModulePath, deno_core::JsRuntime>.
When a request is received by the web server, it sends a channel message to this thread here:

webx/src/engine/runtime.rs

Lines 698 to 701 in 8d00005

pub async fn run(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
self.recompile();
loop {
if let Ok(msg) = self.messages.recv() {

This quickly becomes a synchronization bottleneck when many clients' request require JavaScript code execution in a JsRuntime.
The current solution is a temporary "working" method of having multiple worker threads "share" a mutable reference to a JavaScript runtime via channels. (See thread in #2)

To optimize this and ensure clients don't interrupt, block, or interfere with any other client request execution, create a new JsRuntime for each incoming request. Yes, this is a huge cost and will become one of the main throttles for WebX technologies, but it is a sacrifice for ensuring correctness and safety.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement 🎨Improvements or minor featuresoptimization 🚀Optimize for memory, size or performance

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions