Last active
June 27, 2024 15:54
-
-
Save blampe/de96dd84c59c3d029a7a to your computer and use it in GitHub Desktop.
tchannel context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
poc here https://github.com/uber/tchannel-python/compare/stackcontext#diff-dcfe0a6e0e1f4a668fbb768aa62ba633R48 | |
``` | |
# Currently: | |
@tchannel.register | |
def handler1(req, resp, proxy): | |
pass | |
# Proxy is strange, no clear purpose. Replace proxy with context, which | |
# contains information like parent trace id, span id, and transport headers. | |
# No StackContext magic happening, manually manage context for performance | |
@tchannel.register | |
def handler1(req, resp, context): | |
# Downstream request has to pass context explicitly. Raise an error if | |
# we're outside of a StackContext and no context is provided. | |
tchannel.thrift.call( | |
kv_value.setValue("foo", "bar"), | |
context=content, | |
) | |
# StackContext case | |
@tchannel.register | |
def handler1(req, resp, context): | |
# downstream request is going to find the current context on the StackContext | |
tchannel.thrift.call( | |
kv_value.setValue("foo", "bar"), | |
) | |
# still supports power-users who want to do things like inspect | |
# the current request's TTL, caller name, etc. Make context a well-defined object: | |
context.ttl | |
context.caller_name | |
# allow overriding *some* context fields on downstream | |
# requests (not caller name, for example): | |
tchannel.thrift.call( | |
kv_value.setValue("foo", "bar"), | |
ttl=2, | |
) | |
``` |
We may be able to use http://tornado.readthedocs.org/en/latest/stack_context.html#tornado.stack_context.NullContext for performance sensitive parts that don't mind 'forgetting' the stack context. Needs investigation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How would this work? The performance cost of using stack context is not in accessing the global. That's cheap. The cost is in entering and existing the context manager, and that's unavoidable because the stack context is installed when the handler is being called: