Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a private part to the Context structure #2802

Merged
merged 15 commits into from
Apr 18, 2023
Merged

Conversation

Geal
Copy link
Contributor

@Geal Geal commented Mar 17, 2023

Fix #2800

Checklist

Complete the checklist (and note appropriate exceptions) before a final PR is raised.

  • Changes are compatible[^1]
  • Documentation[^2] completed
  • Performance impact assessed and acceptable
  • Tests added and passing[^3]
    • Unit Tests
    • Integration Tests
    • Manual Tests

Exceptions

Note any exceptions here

Notes

[^1]. It may be appropriate to bring upcoming changes to the attention of other (impacted) groups. Please endeavour to do this before seeking PR approval. The mechanism for doing this will vary considerably, so use your judgement as to how and when to do this.
[^2]. Configuration is an important part of many changes. Where applicable please try to document configuration examples.
[^3]. Tick whichever testing boxes are applicable. If you are adding Manual Tests:
- please document the manual testing (extensively) in the Exceptions.
- please raise a separate issue to automate the test and label it (or ask for it to be labeled) as manual test

@github-actions

This comment has been minimized.

@@ -36,6 +40,9 @@ pub struct Context {
// Allows adding custom entries to the context.
entries: Entries,

#[serde(skip, default)]
pub(crate) private_entries: Arc<std::sync::Mutex<Extensions>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't you think a RwLock could be interesting in that case ? I think we're mostly writing outside of subgraph_service

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that could be, but there would not be much performance benefit, there will very rarely be concurrent accesses

@Geal Geal marked this pull request as ready for review March 22, 2023 15:49
@Geal Geal requested a review from BrynCooke March 22, 2023 15:49
Copy link
Contributor

@garypen garypen left a comment

Choose a reason for hiding this comment

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

High Level Comment: External CoProcessors received all the contents of the context, so moving things out of context will change that behaviour.

I think that's a good thing, but I'm just noting it here so that everyone understands this will happen.

@Geal
Copy link
Contributor Author

Geal commented Apr 17, 2023

yup, it's just that before, some internal details, that we did not meant as public API, were sent to the coprocessor. This will be stricter now

@Geal Geal changed the base branch from dev to staging-perf April 18, 2023 08:58
@Geal Geal merged commit 7d0f173 into staging-perf Apr 18, 2023
@Geal Geal deleted the geal/private-context branch April 18, 2023 09:45
Geal added a commit that referenced this pull request Apr 25, 2023
There's a cost in using the `Context` structure throughout a request's lifecycle, due to the JSON serialization and deserialization, so it should be reserved from inter plugin communication between rhai, coprocessor and Rust. But for internal router usage, we can have a more efficient structure that avoids serialization costs, and does not expose data that should not be modified by plugins.

That structure is based on a map indexed by type id, which means that if some part of the code can see that type, then it can access it in the map.

This means that some context data that was accessible from rhai and all plugins, is now inaccessible
Geal added a commit that referenced this pull request May 15, 2023
Batch of performance improvements:

* linux: replace default allocator with jemalloc (#2882) 
* Add a private part to the Context structure (#2802) 
* lighter path manipulation in response formatting (#2854) 
* prevent span attributes from being formatted to write logs (#2890) 
* Parse Accept headers once instead of three times (#2847) 
* use a parking-lot mutex in Context (#2885) 
* Filter spans before sending them to the opentelemetry layer (#2894)
@BrynCooke BrynCooke mentioned this pull request May 19, 2023
@Geal Geal mentioned this pull request Jul 6, 2023
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.

private Context data
4 participants