@sentio/runtime 3.0.2-rc.2 → 3.1.0-rc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -84,6 +84,7 @@ declare const program: Command<[string], {
84
84
  processTimeout: number;
85
85
  workerTimeout: number;
86
86
  enablePartition: boolean;
87
+ multiServer: number;
87
88
  }, {}>;
88
89
  type ProcessorRuntimeOptions = ReturnType<typeof program.opts> & {
89
90
  target: string;
@@ -18942,6 +18942,8 @@ var import_nice_grpc2 = __toESM(require_lib2(), 1);
18942
18942
  var import_nice_grpc_error_details = __toESM(require_lib3(), 1);
18943
18943
  import http from "http";
18944
18944
  import { Session } from "node:inspector/promises";
18945
+ import { fork } from "child_process";
18946
+ import { fileURLToPath } from "url";
18945
18947
 
18946
18948
  // src/full-service.ts
18947
18949
  import { createRequire } from "module";
@@ -19637,6 +19639,10 @@ try {
19637
19639
  } catch (e) {
19638
19640
  console.error("Failed to parse worker number", e);
19639
19641
  }
19642
+ var serverNum = 1;
19643
+ if (process.env["PROCESSOR_SERVER_NUM"]) {
19644
+ serverNum = parseInt(process.env["PROCESSOR_SERVER_NUM"].trim());
19645
+ }
19640
19646
  function myParseInt(value, dummyPrevious) {
19641
19647
  const parsedValue = parseInt(value, 10);
19642
19648
  if (isNaN(parsedValue)) {
@@ -19644,7 +19650,7 @@ function myParseInt(value, dummyPrevious) {
19644
19650
  }
19645
19651
  return parsedValue;
19646
19652
  }
19647
- var program2 = new Command("processor-runner").allowUnknownOption().allowExcessArguments().name("processor-runner").description("Sentio Processor Runtime").argument("<target>", "Path to the processor module to load").option("-p, --port <port>", "Port to listen on", "4000").option("--concurrency <number>", "Number of concurrent workers", myParseInt, 4).option("--batch-count <number>", "Batch count for processing", myParseInt, 1).option("-c, --chains-config <path>", "Path to chains configuration file", "chains-config.json").option("--chainquery-server <url>", "Chain query server URL").option("--pricefeed-server <url>", "Price feed server URL").option("--log-format <format>", "Log format (console|json)", "console").option("--debug", "Enable debug mode").option("--otlp-debug", "Enable OTLP debug mode").option("--start-action-server", "Start action server instead of processor server").option("--worker <number>", "Number of worker threads", myParseInt, workerNum).option("--process-timeout <seconds>", "Process timeout in seconds", myParseInt, 60).option(
19653
+ var program2 = new Command("processor-runner").allowUnknownOption().allowExcessArguments().name("processor-runner").description("Sentio Processor Runtime").argument("<target>", "Path to the processor module to load").option("-p, --port <port>", "Port to listen on", "4000").option("--concurrency <number>", "Number of concurrent workers(V2 only, deprecated)", myParseInt, 4).option("--batch-count <number>", "Batch count for processing", myParseInt, 1).option("-c, --chains-config <path>", "Path to chains configuration file", "chains-config.json").option("--chainquery-server <url>", "Chain query server URL").option("--pricefeed-server <url>", "Price feed server URL").option("--log-format <format>", "Log format (console|json)", "console").option("--debug", "Enable debug mode").option("--otlp-debug", "Enable OTLP debug mode").option("--start-action-server", "Start action server instead of processor server").option("--worker <number>", "Number of worker threads(V2 only, deprecated) ", myParseInt, workerNum).option("--process-timeout <seconds>", "Process timeout in seconds", myParseInt, 60).option(
19648
19654
  "--worker-timeout <seconds>",
19649
19655
  "Worker timeout in seconds",
19650
19656
  myParseInt,
@@ -19653,7 +19659,7 @@ var program2 = new Command("processor-runner").allowUnknownOption().allowExcessA
19653
19659
  "--enable-partition",
19654
19660
  "Enable binding data partition",
19655
19661
  process.env["SENTIO_ENABLE_BINDING_DATA_PARTITION"] === "true"
19656
- );
19662
+ ).option("--multi-server <number>", "Enable multi-server mode for processor runtime", myParseInt, serverNum);
19657
19663
  import("node:process").then((p) => p.stdout.write(""));
19658
19664
 
19659
19665
  // src/processor-runner.ts
@@ -19669,8 +19675,42 @@ await setupOTLP(options.otlpDebug);
19669
19675
  Error.stackTraceLimit = 20;
19670
19676
  configureEndpoints(options);
19671
19677
  console.debug("Starting Server", options);
19678
+ var isChildProcess = process.env["SENTIO_MULTI_SERVER_CHILD"] === "true";
19679
+ var childServerPort = process.env["SENTIO_CHILD_SERVER_PORT"];
19680
+ if (options.multiServer > 1 && !isChildProcess) {
19681
+ const childProcesses = [];
19682
+ const basePort = parseInt(options.port);
19683
+ for (let i = 1; i < options.multiServer; i++) {
19684
+ const childPort = basePort + i;
19685
+ const child = fork(fileURLToPath(import.meta.url), process.argv.slice(2), {
19686
+ env: {
19687
+ ...process.env,
19688
+ SENTIO_MULTI_SERVER_CHILD: "true",
19689
+ SENTIO_CHILD_SERVER_PORT: String(childPort)
19690
+ },
19691
+ stdio: "inherit"
19692
+ });
19693
+ child.on("error", (err) => {
19694
+ console.error(`Child process on port ${childPort} error:`, err);
19695
+ });
19696
+ child.on("exit", (code) => {
19697
+ console.log(`Child process on port ${childPort} exited with code ${code}`);
19698
+ });
19699
+ childProcesses.push(child);
19700
+ console.log(`Spawned child server process for port ${childPort}`);
19701
+ }
19702
+ const shutdownChildren = () => {
19703
+ for (const child of childProcesses) {
19704
+ child.kill("SIGINT");
19705
+ }
19706
+ };
19707
+ process.on("SIGINT", shutdownChildren);
19708
+ process.on("SIGTERM", shutdownChildren);
19709
+ }
19710
+ var actualPort = isChildProcess && childServerPort ? childServerPort : options.port;
19672
19711
  var server;
19673
19712
  var baseService;
19713
+ var httpServer;
19674
19714
  var loader = async () => {
19675
19715
  const m = await import(options.target);
19676
19716
  console.debug("Module loaded", m);
@@ -19678,7 +19718,7 @@ var loader = async () => {
19678
19718
  };
19679
19719
  if (options.startActionServer) {
19680
19720
  server = new ActionServer(loader);
19681
- server.listen(options.port);
19721
+ server.listen(actualPort);
19682
19722
  } else {
19683
19723
  server = (0, import_nice_grpc2.createServer)({
19684
19724
  "grpc.max_send_message_length": 768 * 1024 * 1024,
@@ -19696,59 +19736,77 @@ if (options.startActionServer) {
19696
19736
  ProcessorV3Definition,
19697
19737
  new FullProcessorServiceV3Impl(new ProcessorServiceImplV3(loader, options, server.shutdown))
19698
19738
  );
19699
- server.listen("0.0.0.0:" + options.port);
19700
- console.log("Processor Server Started at:", options.port);
19739
+ server.listen("0.0.0.0:" + actualPort);
19740
+ console.log("Processor Server Started at:", actualPort);
19701
19741
  }
19702
- var metricsPort = 4040;
19703
- var httpServer = http.createServer(async function(req, res) {
19704
- if (req.url) {
19705
- const reqUrl = new URL(req.url, `http://${req.headers.host}`);
19706
- const queries = reqUrl.searchParams;
19707
- switch (reqUrl.pathname) {
19708
- // case '/metrics':
19709
- // const metrics = await mergedRegistry.metrics()
19710
- // res.write(metrics)
19711
- // break
19712
- case "/heap": {
19713
- try {
19714
- const file = "/tmp/" + Date.now() + ".heapsnapshot";
19715
- await dumpHeap(file);
19716
- const readStream = import_fs_extra2.default.createReadStream(file);
19717
- res.writeHead(200, { "Content-Type": "application/json" });
19718
- readStream.pipe(res);
19719
- res.end();
19720
- } catch {
19721
- res.writeHead(500);
19722
- res.end();
19742
+ if (!isChildProcess) {
19743
+ const metricsPort = 4040;
19744
+ httpServer = http.createServer(async function(req, res) {
19745
+ if (req.url) {
19746
+ const reqUrl = new URL(req.url, `http://${req.headers.host}`);
19747
+ const queries = reqUrl.searchParams;
19748
+ switch (reqUrl.pathname) {
19749
+ // case '/metrics':
19750
+ // const metrics = await mergedRegistry.metrics()
19751
+ // res.write(metrics)
19752
+ // break
19753
+ case "/heap": {
19754
+ try {
19755
+ const file = "/tmp/" + Date.now() + ".heapsnapshot";
19756
+ await dumpHeap(file);
19757
+ const readStream = import_fs_extra2.default.createReadStream(file);
19758
+ res.writeHead(200, { "Content-Type": "application/json" });
19759
+ readStream.pipe(res);
19760
+ res.end();
19761
+ } catch {
19762
+ res.writeHead(500);
19763
+ res.end();
19764
+ }
19765
+ break;
19723
19766
  }
19724
- break;
19725
- }
19726
- case "/profile": {
19727
- try {
19728
- const profileTime = parseInt(queries.get("t") || "1000", 10) || 1e3;
19729
- const session = new Session();
19730
- session.connect();
19731
- await session.post("Profiler.enable");
19732
- await session.post("Profiler.start");
19733
- await new Promise((resolve) => setTimeout(resolve, profileTime));
19734
- const { profile } = await session.post("Profiler.stop");
19735
- res.writeHead(200, { "Content-Type": "application/json" });
19736
- res.write(JSON.stringify(profile));
19737
- session.disconnect();
19738
- } catch {
19739
- res.writeHead(500);
19767
+ case "/profile": {
19768
+ try {
19769
+ const profileTime = parseInt(queries.get("t") || "1000", 10) || 1e3;
19770
+ const session = new Session();
19771
+ session.connect();
19772
+ await session.post("Profiler.enable");
19773
+ await session.post("Profiler.start");
19774
+ await new Promise((resolve) => setTimeout(resolve, profileTime));
19775
+ const { profile } = await session.post("Profiler.stop");
19776
+ res.writeHead(200, { "Content-Type": "application/json" });
19777
+ res.write(JSON.stringify(profile));
19778
+ session.disconnect();
19779
+ } catch {
19780
+ res.writeHead(500);
19781
+ }
19782
+ break;
19740
19783
  }
19741
- break;
19784
+ default:
19785
+ res.writeHead(404);
19742
19786
  }
19743
- default:
19744
- res.writeHead(404);
19787
+ } else {
19788
+ res.writeHead(404);
19745
19789
  }
19746
- } else {
19747
- res.writeHead(404);
19790
+ res.end();
19791
+ }).listen(metricsPort);
19792
+ console.log("Metric Server Started at:", metricsPort);
19793
+ if (process.env["OOM_DUMP_MEMORY_SIZE_GB"]) {
19794
+ let dumping = false;
19795
+ const memorySize = parseFloat(process.env["OOM_DUMP_MEMORY_SIZE_GB"]);
19796
+ console.log("heap dumping is enabled, limit set to ", memorySize, "gb");
19797
+ const dir = process.env["OOM_DUMP_DIR"] || "/tmp";
19798
+ setInterval(async () => {
19799
+ const mem = process.memoryUsage();
19800
+ console.log("Current Memory Usage", mem);
19801
+ if (mem.heapTotal > memorySize * 1024 * 1024 * 1024 && !dumping) {
19802
+ const file = join(dir, `${Date.now()}.heapsnapshot`);
19803
+ dumping = true;
19804
+ await dumpHeap(file);
19805
+ process.exit(11);
19806
+ }
19807
+ }, 1e3 * 60);
19748
19808
  }
19749
- res.end();
19750
- }).listen(metricsPort);
19751
- console.log("Metric Server Started at:", metricsPort);
19809
+ }
19752
19810
  process.on("SIGINT", function() {
19753
19811
  shutdownServers(0);
19754
19812
  }).on("uncaughtException", (err) => {
@@ -19756,7 +19814,7 @@ process.on("SIGINT", function() {
19756
19814
  if (baseService) {
19757
19815
  baseService.unhandled = err;
19758
19816
  }
19759
- }).on("unhandledRejection", (reason, p) => {
19817
+ }).on("unhandledRejection", (reason, _p) => {
19760
19818
  if (reason?.message.startsWith('invalid ENS name (disallowed character: "*"')) {
19761
19819
  return;
19762
19820
  }
@@ -19765,22 +19823,6 @@ process.on("SIGINT", function() {
19765
19823
  baseService.unhandled = reason;
19766
19824
  }
19767
19825
  });
19768
- if (process.env["OOM_DUMP_MEMORY_SIZE_GB"]) {
19769
- let dumping = false;
19770
- const memorySize = parseFloat(process.env["OOM_DUMP_MEMORY_SIZE_GB"]);
19771
- console.log("heap dumping is enabled, limit set to ", memorySize, "gb");
19772
- const dir = process.env["OOM_DUMP_DIR"] || "/tmp";
19773
- setInterval(async () => {
19774
- const mem = process.memoryUsage();
19775
- console.log("Current Memory Usage", mem);
19776
- if (mem.heapTotal > memorySize * 1024 * 1024 * 1024 && !dumping) {
19777
- const file = join(dir, `${Date.now()}.heapsnapshot`);
19778
- dumping = true;
19779
- await dumpHeap(file);
19780
- process.exit(11);
19781
- }
19782
- }, 1e3 * 60);
19783
- }
19784
19826
  async function dumpHeap(file) {
19785
19827
  console.log("Heap dumping to", file);
19786
19828
  const session = new Session();
@@ -19801,10 +19843,14 @@ async function dumpHeap(file) {
19801
19843
  function shutdownServers(exitCode) {
19802
19844
  server.forceShutdown();
19803
19845
  console.log("RPC server shut down");
19804
- httpServer.close(function() {
19805
- console.log("Http server shut down");
19846
+ if (httpServer) {
19847
+ httpServer.close(function() {
19848
+ console.log("Http server shut down");
19849
+ process.exit(exitCode);
19850
+ });
19851
+ } else {
19806
19852
  process.exit(exitCode);
19807
- });
19853
+ }
19808
19854
  }
19809
19855
  import("node:process").then((p) => p.stdout.write(""));
19810
19856
  //# sourceMappingURL=processor-runner.js.map