Skip to content

Conversation

@shrima-cf
Copy link
Contributor

No description provided.

@shrima-cf shrima-cf requested review from a team as code owners November 20, 2025 17:13
@shrima-cf shrima-cf force-pushed the shrima/STOR-3398 branch 2 times, most recently from ab5df90 to 1bf2f83 Compare November 20, 2025 17:44
// https://opensource.org/licenses/Apache-2.0

#include "actor-cache.h"
#include "workerd/io/io-gate.h"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "workerd/io/io-gate.h"
#include <workerd/io/io-gate.h>


void inputGateLocked() override {
metrics.inputGateLocked();
if (IoContext::hasCurrent()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should always have an active IoContext shouldn't we?
So

    auto& context = IoContext::current();
    auto inputGateHoldSpan = context.makeTraceSpan("actor_input_gate_hold"_kjc);

Should be better

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my testing, we don't have IoContext when we invoke the input gate or hold them. I am trying to see if I can use the parent's context.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would really limit the effectiveness and reliability of this PR.

I don't understand input gates well enough but I would love to learn more about them to understand how to best approach this.
If we need to instead iterate over all of the actor's current inflight requests and open spans in all of them we could do that instead of relying on the IoContext

metrics.outputGateWaiterAdded();
if (IoContext::hasCurrent()) {
auto& ioContext = IoContext::current();
outputGateWaitSpan = ioContext.makeTraceSpan("actor_output_gate_wait"_kjc);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is naively overwriting any existing span, but it's possible for an OutputGate to have multiple waiters. I'll look more closely in a minute, but I'd expect us to want to attach a span to each (traced) waiter

Copy link
Member

@a-robinson a-robinson Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd think we could hold these WaitSpan variables in the InputGate::Waiter for InputGates, and for OutputGates we could attach a span on the branch promise returned from OutputGate::wait (similar to the defer for hooks.outputGateWaiterRemoved())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with one request and this works, but or input gates the IoContext is not set at the point where the gates are held/waited, so have to use the parent's IoContext or pass in a parent span. I am working on that change now, will mostly switch to same model for outpute gate too

@danlapid danlapid self-requested a review November 21, 2025 00:57
@justin-mp
Copy link
Contributor

Why is this the right layer to create the spans? It certainly seems awkward to have to keep track of the spans at the hook layer.

It seems to me that a better approach might be to take SpanParent parameters to InputGate::wait() and OutputGate::lockWhile(). Each of those could create a child span that has the lifetime of the promise that they return. (This would be particularly trivial in OutputGate::lockWhile because it's a co-routine.) Moreover, it would let us trace each call into those functions as necessary.

(I think @a-robinson said more or less the same thing in #5563 (comment).)

@shrima-cf
Copy link
Contributor Author

Why is this the right layer to create the spans? It certainly seems awkward to have to keep track of the spans at the hook layer.

It seems to me that a better approach might be to take SpanParent parameters to InputGate::wait() and OutputGate::lockWhile(). Each of those could create a child span that has the lifetime of the promise that they return. (This would be particularly trivial in OutputGate::lockWhile because it's a co-routine.) Moreover, it would let us trace each call into those functions as necessary.

(I think @a-robinson said more or less the same thing in #5563 (comment).)

Yes, see my reply above for Alex's comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants