Prewarm wasm workers before accepting requests
This commit is contained in:
@@ -1388,6 +1388,15 @@ void listen_for_connections()
|
||||
server.on_data = &handle_data;
|
||||
server.on_complete = &handle_complete;
|
||||
server.on_cli_complete = &handle_cli_complete;
|
||||
Request startup_context;
|
||||
startup_context.server = &server_state;
|
||||
f64 wasm_start = time_precise();
|
||||
String wasm_error = wasm_backend_start(startup_context);
|
||||
f64 wasm_ms = (time_precise() - wasm_start) * 1000.0;
|
||||
if(wasm_error == "")
|
||||
printf("(P) wasm worker ready: PID %i in %.3f ms\n", getpid(), wasm_ms);
|
||||
else
|
||||
fprintf(stderr, "(!) wasm worker initialization failed: PID %i in %.3f ms: %s\n", getpid(), wasm_ms, wasm_error.c_str());
|
||||
for(;;)
|
||||
{
|
||||
server.process(-1);
|
||||
|
||||
@@ -88,6 +88,11 @@ static String wasm_backend_ensure_started(Request* context)
|
||||
return("");
|
||||
}
|
||||
|
||||
String wasm_backend_start(Request& request)
|
||||
{
|
||||
return(wasm_backend_ensure_started(&request));
|
||||
}
|
||||
|
||||
static bool wasm_artifact_exists(Request* context, const String& entry_unit)
|
||||
{
|
||||
if(entry_unit == "")
|
||||
|
||||
@@ -10,6 +10,10 @@
|
||||
// artifact; handler-agnostic, the caller names the handler.
|
||||
bool wasm_backend_should_handle(Request& request, const String& entry_unit);
|
||||
|
||||
// Initialize the process-local engine after fork and before the worker accepts
|
||||
// requests. Returns "" on success or the retained backend initialization error.
|
||||
String wasm_backend_start(Request& request);
|
||||
|
||||
// Serve a request through a wasm workspace by invoking a named unit handler —
|
||||
// "render", "cli", "websocket", "serve_http", "serve_http:named" — and populate
|
||||
// the native Request. Returns "" on success or a collapsed error. The handler is
|
||||
|
||||
Reference in New Issue
Block a user