slashmo / gsoc-swift-baggage-context

BaggageContext library, extracted from slashmo/gsoc-swift-tracing
https://github.com/slashmo/gsoc-swift-tracing
Apache License 2.0
4 stars 2 forks source link

Future: Deadlines and Cancelation patterns #24

Closed ktoso closed 3 years ago

ktoso commented 3 years ago

We'll eventually want to also define patterns for distributed deadlines with context.

We'd like to be able to use context to protect tail latencies of services, e.g. if a service call is already past its deadline, there's no reason to continue working on the downstream calls it caused.

Downstreams would need to protect their expensive calls using something like:

func expensiveOperation(context: BaggageContext) throws { 
  guard context.deadline else { // specific spelling not sure about yet, also because swift concurrency 
    throw DeadlineExceeded(context)
  }
}

We would like to ensure cancelation works well with whatever the swift concurrency story becomes and how it'd handle cancelation as well.


Composing and "sub deadlines" must be easy to compose, it should be easily possible to "my entire work should take 1 minute (until time T)" but each sub task must take no longer than a few seconds (until t1)" so we must allow composing deadlines like such.

The deadline should always take the "lower of the current deadline, and the passed in one".


If we'd ever get function wrappers, it could become @DeadlineRespecting (terrible name, we'd find a good one) that does this automatically.