denoland / rusty_v8

Rust bindings for the V8 JavaScript engine
https://crates.io/crates/v8
MIT License
3.13k stars 300 forks source link

set v8_enable_private_mapping_fork_optimization = true #1535

Closed ry closed 1 month ago

ry commented 1 month ago

https://issues.chromium.org/issues/42210615

Add a new build flag v8_enable_private_mapping_fork_optimization which marks all pages allocated by OS::Allocate as MADV_DONTFORK. This improves the performance of Node.js's fork/execve combination by 10x on a 600 MB heap.

https://chromium-review.googlesource.com/c/v8/v8/+/4602858 https://lobste.rs/s/tr8ozm/why_is_spawning_new_process_node_so_slow

littledivy commented 1 month ago

Seems to improve nicely:

# with v8_enable_private_mapping_fork_optimization = true
divy@divy-macbook ~/g/deno (main)> wrk -d 10s --latency http://127.0.0.1:8001/
Running 10s test @ http://127.0.0.1:8001/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     7.49ms    2.46ms  45.61ms   88.75%
    Req/Sec   671.25     60.53   787.00     85.50%
  Latency Distribution
     50%    6.87ms
     75%    7.66ms
     90%    9.93ms
     99%   14.59ms
  13425 requests in 10.05s, 0.96MB read
Requests/sec:   1335.72
Transfer/sec:     97.83KBKB

# main
divy@divy-macbook ~/g/deno (main)> wrk -d 10s --latency http://127.0.0.1:8001/
Running 10s test @ http://127.0.0.1:8001/
  2 threads and 10 connections
  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency     9.05ms    3.13ms  60.00ms   89.04%
    Req/Sec   556.14     49.83   650.00     77.00%
  Latency Distribution
     50%    8.44ms
     75%    9.46ms
     90%   11.54ms
     99%   17.72ms
  11135 requests in 10.07s, 815.55KB read
Requests/sec:   1105.98
Transfer/sec:     81.00KB
import { spawn } from "node:child_process";
import http from "node:http";
http
  .createServer((_, res) => spawn("cat", ["main.c"]).stdout.pipe(res))
  .listen(8001);