summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Mastracci <matthew@mastracci.com>2023-05-18 18:08:57 -0600
committerGitHub <noreply@github.com>2023-05-18 18:08:57 -0600
commit8724ba9d084127147e2bb2c997a6bf2f38c9b3d2 (patch)
tree2a5893dbd9191b2615685731585834c3ed7b625f
parentc2995893be188f727f461d330bfbc54030663c62 (diff)
feat(runtime): Provide environment-configurable options for tokio parameters (#19173)
-rw-r--r--runtime/tokio_util.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/runtime/tokio_util.rs b/runtime/tokio_util.rs
index d723006bd..1245a5b8e 100644
--- a/runtime/tokio_util.rs
+++ b/runtime/tokio_util.rs
@@ -1,11 +1,41 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use std::fmt::Debug;
+use std::str::FromStr;
use deno_core::task::MaskFutureAsSend;
+/// Default configuration for tokio. In the future, this method may have different defaults
+/// depending on the platform and/or CPU layout.
+const fn tokio_configuration() -> (u32, u32, usize) {
+ (61, 31, 1024)
+}
+
+fn tokio_env<T: FromStr>(name: &'static str, default: T) -> T
+where
+ <T as FromStr>::Err: Debug,
+{
+ match std::env::var(name) {
+ Ok(value) => value.parse().unwrap(),
+ Err(_) => default,
+ }
+}
+
pub fn create_basic_runtime() -> tokio::runtime::Runtime {
+ let (event_interval, global_queue_interval, max_io_events_per_tick) =
+ tokio_configuration();
+
tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
+ .event_interval(tokio_env("DENO_TOKIO_EVENT_INTERVAL", event_interval))
+ .global_queue_interval(tokio_env(
+ "DENO_TOKIO_GLOBAL_QUEUE_INTERVAL",
+ global_queue_interval,
+ ))
+ .max_io_events_per_tick(tokio_env(
+ "DENO_TOKIO_MAX_IO_EVENTS_PER_TICK",
+ max_io_events_per_tick,
+ ))
// This limits the number of threads for blocking operations (like for
// synchronous fs ops) or CPU bound tasks like when we run dprint in
// parallel for deno fmt.