-
Notifications
You must be signed in to change notification settings - Fork 1
Description
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:
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.