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:
|
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.
A single
WXRuntimethread holds a context withHashMap<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
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
JsRuntimefor 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.