Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ src/protos/*.rs
/.cloud_certs/
cloud_envs.fish
/.claude/settings.local.json
.codex
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ license = "MIT"
license-file = "LICENSE.txt"

[workspace.dependencies]
bon = { version = "3", features = ["implied-bounds"] }
derive_more = { version = "2.0", features = [
bon = { version = "3", default-features = false, features = ["alloc", "implied-bounds"] }
derive_more = { version = "2.0", default-features = false, features = [
"constructor",
"display",
"from",
Expand All @@ -24,10 +24,10 @@ derive_more = { version = "2.0", features = [
"try_into",
] }
thiserror = "2"
tonic = "0.14"
tonic = { version = "0.14", default-features = false }
tonic-prost = "0.14"
tonic-prost-build = "0.14"
opentelemetry = { version = "0.31", features = ["metrics"] }
opentelemetry = { version = "0.31", default-features = false, features = ["metrics"] }
prost = "0.14"
prost-types = { version = "0.7", package = "prost-wkt-types" }
pbjson = "0.9"
Expand Down
22 changes: 18 additions & 4 deletions crates/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ anyhow = "1.0"
async-trait = "0.1"
backoff = "0.4"
base64 = "0.22"
bon = "3"
bon = { version = "3", default-features = false, features = ["alloc"] }
derive_more = { workspace = true }
dyn-clone = "1.0"
bytes = "1.10"
Expand All @@ -35,12 +35,18 @@ hyper-util = "0.1.16"
opentelemetry = { workspace = true, features = ["metrics"], optional = true }
parking_lot = "0.12"
thiserror = { workspace = true }
tokio = { version = "1.47", features = ["net", "time"] }
tonic = { workspace = true, features = ["tls-ring", "tls-native-roots"] }
tokio = { version = "1.47", default-features = false, features = [
"io-util",
"net",
"rt",
"sync",
"time",
] }
tonic = { workspace = true, default-features = false, features = ["tls-ring", "tls-native-roots", "channel"] }
tower = { version = "0.5", features = ["util"] }
tracing = "0.1"
url = "2.5"
uuid = { version = "1.18", features = ["v4"] }
uuid = { version = "1.18", default-features = false, features = ["v4"] }
rand = "0.10"

[dependencies.temporalio-common]
Expand All @@ -54,6 +60,14 @@ prost = "0.14"
prost-types = { workspace = true }
rstest = "0.26"
tempfile = "3"
tokio = { version = "1.47", default-features = false, features = [
"io-util",
"macros",
"net",
"rt",
"sync",
"time",
] }

[lints]
workspace = true
19 changes: 12 additions & 7 deletions crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ crc32fast = "1"
dirs = { version = "6.0", optional = true }
derive_more = { workspace = true }
erased-serde = "0.4"
futures = "0.3"
futures = { version = "0.3", default-features = false, features = ["alloc"] }
futures-channel = { version = "0.3", default-features = false, features = [
"std",
], optional = true }
Expand All @@ -55,17 +55,18 @@ hyper-util = { version = "0.1", features = [
"tokio",
], optional = true }
opentelemetry = { workspace = true, features = ["metrics"], optional = true }
opentelemetry_sdk = { version = "0.31", features = [
opentelemetry_sdk = { version = "0.31", default-features = false, features = [
"rt-tokio",
"metrics",
"spec_unstable_metrics_views",
], optional = true }
opentelemetry-otlp = { version = "0.31", features = [
opentelemetry-otlp = { version = "0.31", default-features = false, features = [
"tokio",
"metrics",
"tls",
"tls-roots",
"http-proto",
"grpc-tonic",
"reqwest-rustls",
], optional = true }
parking_lot = { version = "0.12" }
prometheus = { version = "0.14", optional = true, default-features = false }
Expand All @@ -77,9 +78,13 @@ ringbuf = { version = "0.4", optional = true }
serde = { version = "1.0", features = ["derive"] }
serde_json = { workspace = true }
thiserror = { workspace = true }
tokio = { version = "1.47", features = [], optional = true }
tokio = { version = "1.47", default-features = false, features = [
"io-util",
"net",
"rt",
], optional = true }
toml = { version = "1.0", optional = true }
tonic = { workspace = true }
tonic = { workspace = true, default-features = false, features = ["transport", "codegen"] }
tonic-prost = { workspace = true }
tracing = "0.1"
# TODO [rust-sdk-branch]: Is it reasonable to make this optional?
Expand All @@ -91,7 +96,7 @@ tracing-subscriber = { version = "0.3", default-features = false, features = [
] }
tracing-core = "0.1"
url = "2.5"
uuid = { version = "1.18", features = ["v4"] }
uuid = { version = "1.18", default-features = false, features = ["v4"] }
pbjson = { workspace = true }

[build-dependencies]
Expand Down
6 changes: 3 additions & 3 deletions crates/sdk-core-c-bridge/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ rand = "0.10"
rand_pcg = "0.10"
serde = { version = "1.0", features = ["derive"] }
serde_json = { workspace = true }
tokio = "1.47"
tokio-stream = "0.1"
tokio = { version = "1.47", default-features = false, features = ["sync"] }
tokio-stream = { version = "0.1", default-features = false }
tokio-util = "0.7"
tonic = { workspace = true }
tonic = { workspace = true, default-features = false }
tracing = "0.1"
url = "2.5"
# This is only needed as an explicit dependency so we can enable static as a feature
Expand Down
25 changes: 14 additions & 11 deletions crates/sdk-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,30 @@ async-trait = "0.1"
bon = { workspace = true }
crossbeam-channel = "0.5"
crossbeam-utils = "0.8"
dashmap = "6.1"
derive_more = { workspace = true }
enum_dispatch = "0.3"
enum-iterator = "2"
flate2 = { version = "1.1", optional = true }
futures = { version = "0.3", default-features = false }
futures-util = { version = "0.3", default-features = false }
gethostname = "1.0.2"
governor = "0.10"
hyper = { version = "1.7", optional = true }
itertools = "0.14"
lru = "0.16"
mockall = "0.14"
opentelemetry = { workspace = true, features = ["metrics"], optional = true }
opentelemetry_sdk = { version = "0.31", features = [
opentelemetry_sdk = { version = "0.31", default-features = false, features = [
"rt-tokio",
"metrics",
"spec_unstable_metrics_views",
], optional = true }
opentelemetry-otlp = { version = "0.31", features = [
opentelemetry-otlp = { version = "0.31", default-features = false, features = [
"tokio",
"metrics",
"tls",
"tls-roots",
"http-proto",
"grpc-tonic",
"reqwest-rustls",
], optional = true }
parking_lot = { version = "0.12" }
pid = "4.0"
Expand All @@ -84,20 +83,21 @@ slotmap = "1.0"
sysinfo = { version = "0.38", default-features = false, features = ["system"] }
tar = { version = "0.4", optional = true }
thiserror = { workspace = true }
tokio = { version = "1.47", features = [
tokio = { version = "1.47", default-features = false, features = [
"rt",
"rt-multi-thread",
"parking_lot",
"time",
"fs",
"process",
"macros",
] }
tokio-util = { version = "0.7", features = ["io", "io-util"] }
tokio-stream = "0.1"
tonic = { workspace = true, features = ["tls-ring", "tls-native-roots"] }
tokio-stream = { version = "0.1", default-features = false }
tonic = { workspace = true, default-features = false, features = ["tls-ring", "tls-native-roots", "transport", "codegen"] }
tracing = "0.1"
url = "2.5"
uuid = { version = "1.18", features = ["v4"] }
uuid = { version = "1.18", default-features = false, features = ["v4"] }
# Only need specific features to decompress zip files for ephemeral server download
zip = { version = "8.4", optional = true, default-features = false, features = [
"deflate",
Expand Down Expand Up @@ -138,16 +138,18 @@ hyper-util = { version = "0.1", features = [
rstest = "0.26"
semver = "1.0"
temporalio-sdk = { path = "../sdk" }
tokio = { version = "1.47", features = [
tokio = { version = "1.47", default-features = false, features = [
"rt",
"rt-multi-thread",
"parking_lot",
"time",
"fs",
"process",
"test-util",
"macros",
] }
tokio-stream = { version = "0.1", features = ["net"] }
tokio-stream = { version = "0.1", default-features = false, features = ["net"] }
tonic = { workspace = true, default-features = false, features = ["router"] }
tracing-subscriber = { version = "0.3", default-features = false }
trybuild = { version = "1.0", features = ["diff"] }

Expand Down Expand Up @@ -202,6 +204,7 @@ name = "workflow_replay"
path = "benches/workflow_replay_bench.rs"
test = false
harness = false
required-features = ["test-utilities"]

# The integration test runner should compile with the same configuration as the
# rest of the integration tests so that artifacts are shared and no additional
Expand Down
36 changes: 29 additions & 7 deletions crates/sdk-core/src/pollers/poll_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::{
use backoff::{SystemClock, backoff::Backoff, exponential::ExponentialBackoff};
use crossbeam_utils::atomic::AtomicCell;
use futures_util::{FutureExt, StreamExt, future::BoxFuture};
use governor::{Quota, RateLimiter};
use std::{
cmp,
fmt::Debug,
Expand All @@ -19,7 +18,7 @@ use std::{
Arc,
atomic::{AtomicBool, AtomicUsize, Ordering},
},
time::{Duration, SystemTime},
time::{Duration, Instant, SystemTime},
};
use temporalio_client::{
ERROR_RETURNED_DUE_TO_SHORT_CIRCUIT, request_extensions::NoRetryOnMatching,
Expand All @@ -45,6 +44,32 @@ use tracing::Instrument;

type PollReceiver<T, SK> =
Mutex<UnboundedReceiver<pollers::Result<(T, OwnedMeteredSemPermit<SK>)>>>;

struct PollRateLimiter {
interval: Duration,
next_allowed_at: Mutex<Instant>,
}

impl PollRateLimiter {
fn new(polls_per_second: f64) -> Self {
Self {
interval: Duration::from_secs_f64(polls_per_second.recip()),
next_allowed_at: Mutex::new(Instant::now()),
}
}

async fn wait(&self) {
let scheduled_at = {
let mut next_allowed_at = self.next_allowed_at.lock().await;
let now = Instant::now();
let scheduled_at = (*next_allowed_at).max(now);
*next_allowed_at = scheduled_at + self.interval;
scheduled_at
};
tokio::time::sleep_until(scheduled_at.into()).await;
}
}

pub(crate) struct LongPollBuffer<T, SK: SlotKind> {
buffered_polls: PollReceiver<T, SK>,
shutdown: CancellationToken,
Expand Down Expand Up @@ -163,14 +188,11 @@ impl LongPollBuffer<PollActivityTaskQueueResponse, ActivitySlotKind> {
) -> Self {
let pre_permit_delay = options
.max_worker_acts_per_second
.and_then(|ps| {
Quota::with_period(Duration::from_secs_f64(ps.recip()))
.map(|q| Arc::new(RateLimiter::direct(q)))
})
.map(|ps| Arc::new(PollRateLimiter::new(ps)))
.map(|rl| {
move || {
let rl = rl.clone();
async move { rl.until_ready().await }.boxed()
async move { rl.wait().await }.boxed()
}
});
let no_retry = if matches!(poller_behavior, PollerBehavior::Autoscaling { .. }) {
Expand Down
Loading
Loading