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

perf(node-api): Add caching of query contexts to backend #1819

Closed
wants to merge 27 commits into from
Closed

Conversation

calbera
Copy link
Contributor

@calbera calbera commented Jul 30, 2024

LRU cache the query contexts (to optimize for 1 endpoint handler calling backend multiple times, should only incur 1 query context)

Summary by CodeRabbit

  • New Features

    • Introduced a caching mechanism for query contexts, improving performance and efficiency.
    • Added configuration options for cache size and expiration settings.
    • Enhanced configuration management for the Node API, allowing for modular customization.
  • Bug Fixes

    • Enhanced context management to prevent unintended state mutations.
  • Tests

    • Implemented comprehensive unit tests for the new caching functionality, ensuring reliability across various scenarios.
    • Updated tests to validate new initialization values for the ExecutionPayloadHeader structure.
  • Documentation

    • Added documentation detailing the new cache configuration and usage.

@calbera calbera requested a review from archbear July 30, 2024 15:14
Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates integrate a caching mechanism into the Backend struct, significantly enhancing query context management. A new QueryCache struct, employing an LRU strategy, allows for efficient storage and retrieval of contexts based on slots, which reduces overhead by minimizing redundant context creation. Accompanying unit tests ensure the reliability of this caching functionality, while configuration files provide customizable cache settings, collectively enhancing the performance and efficiency of the system.

Changes

Files Change Summary
mod/node-api/backend/backend.go Added cache field to Backend, modified New constructor, and optimized stateFromSlotRaw to utilize caching.
mod/node-api/backend/cache/*.go Introduced QueryCache struct with LRU implementation for managing query contexts; added constructors and methods, along with a configuration structure for customizable cache settings.
mod/node-api/backend/cache/cache_test.go Implemented unit tests for QueryCache functionality, validating cache operations and size management.
mod/node-api/backend/cache/config.go Established a configuration structure for cache size and TTL settings, enhancing operational flexibility.
mod/node-api/config.go Introduced a Config struct for managing backend and server configurations in the node API, along with a default configuration function.
mod/config/config.go Refactored NodeAPI configuration: renamed imports and updated configuration calls to reflect new module structure.
mod/node-core/pkg/components/api.go Added Config field to NodeAPIBackendInput and refined configuration handling in ProvideNodeAPIBackend and ProvideNodeAPIServer functions.
mod/cli/pkg/flags/flags.go Reorganized Node API configuration constants for server and backend settings, enhancing clarity and modularity.
mod/config/pkg/template/template.go Restructured configuration template for the Node API, introducing sections for server and backend settings.
mod/node-api/go.mod Added dependency on github.com/hashicorp/golang-lru/v2 for LRU caching capabilities.
mod/config/go.mod Added new indirect dependencies for JWT, object manipulation, and enhanced time functionalities.

Sequence Diagram(s)

sequenceDiagram
    participant Backend
    participant QueryCache
    participant Node

    Backend->>QueryCache: GetQueryContext(slot)
    alt Cache Hit
        QueryCache-->>Backend: Return existing context
    else Cache Miss
        Backend->>Node: CreateQueryContext(slot)
        Node-->>Backend: Return new context
        Backend->>QueryCache: AddQueryContext(slot, new context)
    end
Loading

🐇 In fields of code so bright and new,
A cache was born, as if it knew!
With contexts stored, like carrots in line,
Queries now speed, oh how divine!
Let’s hop for joy, for changes made,
In a world of code, our dreams cascade! 🍃✨


Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

Attention: Patch coverage is 20.00000% with 48 lines in your changes missing coverage. Please review.

Project coverage is 24.98%. Comparing base (bdcc291) to head (0a1371b).
Report is 59 commits behind head on main.

Files Patch % Lines
mod/node-api/backend/backend.go 0.00% 18 Missing ⚠️
mod/cli/pkg/flags/flags.go 0.00% 13 Missing ⚠️
mod/node-api/backend/cache/config.go 0.00% 5 Missing ⚠️
mod/node-api/config.go 0.00% 5 Missing ⚠️
mod/node-api/backend/config.go 0.00% 4 Missing ⚠️
mod/node-core/pkg/components/api.go 0.00% 2 Missing ⚠️
mod/config/config.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1819   +/-   ##
=======================================
  Coverage   24.97%   24.98%           
=======================================
  Files         326      330    +4     
  Lines       14184    14227   +43     
  Branches       19       19           
=======================================
+ Hits         3543     3555   +12     
- Misses      10511    10542   +31     
  Partials      130      130           
Files Coverage Δ
mod/node-api/backend/cache/cache.go 100.00% <100.00%> (ø)
mod/config/config.go 0.00% <0.00%> (ø)
mod/node-core/pkg/components/api.go 0.00% <0.00%> (ø)
mod/node-api/backend/config.go 0.00% <0.00%> (ø)
mod/node-api/backend/cache/config.go 0.00% <0.00%> (ø)
mod/node-api/config.go 0.00% <0.00%> (ø)
mod/cli/pkg/flags/flags.go 0.00% <0.00%> (ø)
mod/node-api/backend/backend.go 0.00% <0.00%> (ø)

Base automatically changed from api-opts to main July 30, 2024 15:44
@calbera calbera marked this pull request as ready for review July 30, 2024 15:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between a9255e3 and fcf1c8c.

Files selected for processing (4)
  • mod/node-api/backend/backend.go (4 hunks)
  • mod/node-api/backend/cache/cache.go (1 hunks)
  • mod/node-api/backend/cache/cache_test.go (1 hunks)
  • mod/node-api/backend/cache/config.go (1 hunks)
Additional context used
GitHub Check: nilaway
mod/node-api/backend/backend.go

[failure] 189-189:
b.sb.StateFromContext(queryCtx).Copy undefined (type BeaconStateT has no field or method Copy)

Additional comments not posted (25)
mod/node-api/backend/cache/config.go (6)

1-19: File License and Copyright Notice

The file contains a detailed license notice, which is important for legal compliance. Ensure that this notice is consistent across all files in the repository.


21-22: Package Declaration

The package is correctly declared as cache, which aligns with the file's purpose.


23-23: Import Statement

The time package is imported, which is necessary for the time.Duration type used in the configuration.


25-28: Constants Definition

The default values for QueryContextSize and QueryContextTTL are defined. These values are sensible defaults for a cache configuration.


30-36: Config Struct Definition

The Config struct is well-defined with appropriate fields for cache size and TTL. The use of mapstructure tags indicates this struct can be easily used with configuration libraries.


38-44: DefaultConfig Function

The DefaultConfig function returns a Config struct with default values. This is a good practice to provide a standard configuration.

mod/node-api/backend/cache/cache.go (8)

1-19: File License and Copyright Notice

The file contains a detailed license notice, which is important for legal compliance. Ensure that this notice is consistent across all files in the repository.


21-22: Package Declaration

The package is correctly declared as cache, which aligns with the file's purpose.


23-28: Import Statements

The necessary packages are imported, including the golang-lru package for the LRU cache implementation and a custom math package.


30-35: QueryCache Struct Definition

The QueryCache struct is defined with a single field for the LRU cache. The use of generics in the LRU cache is appropriate for type safety.


37-45: NewQueryCache Constructor

The NewQueryCache function initializes a QueryCache with the provided configuration. The use of the LRU cache constructor is correct, and the function properly handles the configuration parameters.


48-52: NewQueryCacheWithDefaultConfig Constructor

This function provides a convenient way to create a QueryCache with default settings. It correctly calls the NewQueryCache function with the default configuration.


54-57: GetQueryContext Method

The GetQueryContext method retrieves a context from the cache. The method is simple and correctly returns both the context and a boolean indicating whether it was found.


59-62: AddQueryContext Method

The AddQueryContext method adds a context to the cache. The method is straightforward and correctly uses the LRU cache's Add method.

mod/node-api/backend/cache/cache_test.go (8)

1-19: File License and Copyright Notice

The file contains a detailed license notice, which is important for legal compliance. Ensure that this notice is consistent across all files in the repository.


21-22: Package Declaration

The package is correctly declared as cache_test, which is a common convention for testing packages in Go.


23-31: Import Statements

The necessary packages are imported, including the testing package for writing tests, the cache package being tested, and the require package from testify for assertions.


33-38: TestQueryCache Function

The TestQueryCache function sets up the test environment, including creating a configuration and initializing the QueryCache. This setup is clear and appropriate.


42-46: Test Case: Get from Empty Cache

This test case checks the behavior of the GetQueryContext method when the cache is empty. The assertions correctly verify that the context is not found and is nil.


48-55: Test Case: Set and Get

This test case verifies that a context can be added to the cache and subsequently retrieved. The assertions ensure that the context is correctly stored and retrieved.


57-71: Test Case: Overwrite Existing

This test case checks that an existing context in the cache can be overwritten. The assertions verify that the new context replaces the old one.


73-80: Test Case: Prune and Verify Deletion

This test case ensures that the cache correctly prunes old entries when the cache size limit is reached. The assertions verify that the oldest entry is removed.

mod/node-api/backend/backend.go (3)

119-122: LGTM! Initialization of the cache field is correct.

The New function correctly initializes the cache field using cache.NewQueryCacheWithDefaultConfig().


Line range hint 153-167:
LGTM! Dependency on stateFromSlotRaw.

The stateFromSlot function looks correct but relies on stateFromSlotRaw, which has a potential issue with the Copy method.


175-189: Potential issue with the Copy method.

The static analysis tool indicates that b.sb.StateFromContext(queryCtx).Copy is undefined. Ensure that BeaconStateT has a Copy method or replace it with an appropriate method to create a copy of the state.

-  st = b.sb.StateFromContext(queryCtx).Copy()
+  st = b.sb.StateFromContext(queryCtx).DeepCopy() // Assuming DeepCopy is the correct method
Tools
GitHub Check: nilaway

[failure] 189-189:
b.sb.StateFromContext(queryCtx).Copy undefined (type BeaconStateT has no field or method Copy)

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between fcf1c8c and aa4b919.

Files selected for processing (2)
  • mod/node-api/backend/backend.go (6 hunks)
  • mod/node-api/backend/types.go (1 hunks)
Additional comments not posted (6)
mod/node-api/backend/types.go (2)

68-68: LGTM!

The addition of the type parameter T to the BeaconState interface enhances its flexibility and allows it to work with any specified type.


74-75: LGTM!

The addition of the Copy() method to the BeaconState interface is a valuable enhancement for maintaining state consistency in concurrent or distributed systems.

mod/node-api/backend/backend.go (4)

26-26: LGTM!

The import of the cache package is necessary for implementing the caching mechanism.


68-68: LGTM!

The addition of the cache field to the Backend struct enables caching of query contexts, improving performance by reducing redundant context creation.


122-122: LGTM!

The initialization of the cache field in the New constructor function ensures that each instance of Backend is equipped with caching capability.


175-189: LGTM!

The modification of the stateFromSlotRaw method to utilize the cache field for query context management enhances performance by reducing redundant context creation. Copying the state ensures the integrity of the original state.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between aa4b919 and 38f69a9.

Files selected for processing (3)
  • mod/node-api/backend/cache/cache.go (1 hunks)
  • mod/node-api/backend/cache/cache_test.go (1 hunks)
  • mod/node-api/backend/cache/config.go (1 hunks)
Additional comments not posted (14)
mod/node-api/backend/cache/config.go (5)

1-19: File header looks good.

The license information is correct and complete.


21-23: Package declaration and imports look good.

The package name cache is appropriate, and the time import is necessary for TTL configuration.


25-31: Constants for default cache size and TTL look good.

The default values are reasonable and the comments provide clear explanations.


33-39: Config struct looks good.

The struct is well-defined and the tags are correct for configuration parsing.


41-47: DefaultConfig function looks good.

The function correctly initializes the Config struct with default values.

mod/node-api/backend/cache/cache.go (6)

1-19: File header looks good.

The license information is correct and complete.


21-28: Package declaration and imports look good.

The package name cache is appropriate, and the imports are necessary for the cache implementation.


30-35: QueryCache struct looks good.

The struct is well-defined and the comments provide clear explanations.


37-45: NewQueryCache function looks good.

The function correctly initializes the QueryCache with the provided configuration.


48-52: NewQueryCacheWithDefaultConfig function looks good.

The function correctly initializes the QueryCache with the default configuration.


54-64: Cache operations methods look good.

The methods are well-defined and provide necessary cache operations.

mod/node-api/backend/cache/cache_test.go (3)

1-19: File header looks good.

The license information is correct and complete.


21-31: Package declaration and imports look good.

The package name cache_test is appropriate, and the imports are necessary for the tests.


33-84: TestQueryCache function looks good.

The function is well-structured and covers different scenarios for cache operations.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 38f69a9 and a38f2b2.

Files ignored due to path filters (1)
  • mod/node-api/go.sum is excluded by !**/*.sum
Files selected for processing (1)
  • mod/node-api/go.mod (1 hunks)
Additional comments not posted (1)
mod/node-api/go.mod (1)

13-13: Dependency addition approved.

The addition of github.com/hashicorp/golang-lru/v2 v2.0.7 is appropriate for implementing an LRU cache. Ensure that this version is the latest stable release and verify if there are any known issues with it.

Verification successful

Dependency addition approved.

The addition of github.com/hashicorp/golang-lru/v2 v2.0.7 is appropriate for implementing an LRU cache. This version is the latest stable release.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the added dependency version is the latest stable release.

# Test: Check the latest version of the dependency. Expect: Version v2.0.7 or higher.
go list -m -versions github.com/hashicorp/golang-lru/v2

Length of output: 127


Script:

#!/bin/bash
# Description: Verify if the added dependency version is the latest stable release by querying the GitHub API.

# Test: Check the latest release version of the dependency on GitHub. Expect: Version v2.0.7 or higher.
curl -s https://api.github.com/repos/hashicorp/golang-lru/releases/latest | jq -r .tag_name

Length of output: 100

mod/node-api/backend/backend.go Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between a38f2b2 and 7f53b05.

Files ignored due to path filters (1)
  • mod/config/go.sum is excluded by !**/*.sum
Files selected for processing (12)
  • mod/cli/pkg/flags/flags.go (2 hunks)
  • mod/config/config.go (3 hunks)
  • mod/config/go.mod (3 hunks)
  • mod/config/pkg/template/template.go (1 hunks)
  • mod/node-api/backend/backend.go (7 hunks)
  • mod/node-api/backend/cache/cache.go (1 hunks)
  • mod/node-api/backend/cache/cache_test.go (1 hunks)
  • mod/node-api/backend/cache/config.go (1 hunks)
  • mod/node-api/backend/config.go (1 hunks)
  • mod/node-api/config.go (1 hunks)
  • mod/node-core/pkg/components/api.go (3 hunks)
  • testing/files/entrypoint.sh (1 hunks)
Additional comments not posted (39)
mod/node-api/backend/config.go (3)

21-23: LGTM!

The package declaration and import statement are correct.


25-27: LGTM!

The Config struct definition is correct and aligns with the objective of configuring the cache.


29-33: LGTM!

The DefaultConfig function correctly initializes the Config struct with default values.

mod/node-api/config.go (3)

21-26: LGTM!

The package declaration and import statements are correct.


28-31: LGTM!

The Config struct definition is correct and aligns with the objective of configuring the node API.


33-38: LGTM!

The DefaultConfig function correctly initializes the Config struct with default values.

mod/node-api/backend/cache/config.go (3)

21-23: LGTM!

The package declaration and import statement are correct.


25-31: LGTM!

The constants for default values are correctly defined and documented.


33-47: LGTM!

The Config struct definition and DefaultConfig function are correct and align with the objective of configuring the cache.

mod/node-api/backend/cache/cache.go (4)

30-35: LGTM! The struct definition looks correct.

The QueryCache struct is well-defined, using an LRU cache for query contexts.


37-45: LGTM! The function correctly initializes the cache.

The NewQueryCache function properly initializes the LRU cache with the provided configuration.


48-51: LGTM! The function correctly retrieves the context.

The GetQueryContext function correctly retrieves the query context for a given slot from the cache.


53-58: LGTM! The function correctly adds the context.

The AddQueryContext function correctly adds the query context to the cache for a given slot.

mod/node-core/pkg/components/api.go (4)

Line range hint 44-49:
LGTM! The struct definition looks correct.

The addition of the Config field to the NodeAPIBackendInput struct enhances flexibility and configurability.


Line range hint 51-75:
LGTM! The function correctly uses the new configuration field.

The ProvideNodeAPIBackend function correctly uses the in.Config.NodeAPI.Backend field, improving specificity and clarity.


Line range hint 77-83:
LGTM! The struct definition looks correct.

The addition of the Config field to the NodeAPIServerInput struct enhances flexibility and configurability.


Line range hint 85-98:
LGTM! The function correctly uses the new configuration field.

The ProvideNodeAPIServer function correctly uses the in.Config.NodeAPI.Server field, improving specificity and clarity.

mod/node-api/backend/cache/cache_test.go (5)

33-39: LGTM! The initialization of the QueryCache is correct.

The QueryCache is correctly initialized with the provided configuration.


43-47: LGTM! The sub-test correctly validates the behavior.

The sub-test Get from empty cache correctly validates that getting a context from an empty cache returns false and nil.


49-56: LGTM! The sub-test correctly validates the behavior.

The sub-test Set and Get correctly validates that setting and then getting a context returns the correct value.


58-74: LGTM! The sub-test correctly validates the behavior.

The sub-test Overwrite existing correctly validates that overwriting an existing context updates the value correctly.


76-83: LGTM! The sub-test correctly validates the behavior.

The sub-test Prune and verify deletion correctly validates that the cache prunes old entries and verifies their deletion.

mod/config/config.go (2)

32-32: LGTM!

The import statement for the NodeAPI module has been renamed from server to nodeapi, reflecting a shift in how the NodeAPI configuration is accessed.


52-52: LGTM!

The NodeAPI field type in the Config struct and the DefaultConfig function has been updated from server.Config to nodeapi.Config, reflecting a semantic shift in the underlying configuration structure for the NodeAPI.

Also applies to: 71-71

mod/config/pkg/template/template.go (2)

98-98: LGTM!

The parameters enabled, address, and logging have been updated to reference the new structure [beacon-kit.node-api.server], enhancing the clarity and organization of the configuration.

Also applies to: 100-106


108-113: LGTM!

The new section [beacon-kit.node-api.backend] includes parameters size and query-context-ttl for backend settings, likely aimed at improving performance and resource management.

mod/cli/pkg/flags/flags.go (6)

73-73: LGTM!

The introduction of nodeAPIRoot improves the organization and modularity of the configuration settings.


74-74: LGTM!

The introduction of nodeAPIServerRoot enhances clarity by separating server-related configurations from backend configurations.


75-75: LGTM!

The introduction of nodeAPIBackendRoot enhances clarity by separating backend-related configurations from server configurations.


79-79: LGTM!

The introduction of NodeAPICacheSize allows for configuration of cache-related parameters, improving performance and efficiency.


80-80: LGTM!

The introduction of NodeAPICacheQueryContextTTL allows for configuration of cache-related parameters, improving performance and efficiency.


157-179: LGTM!

The updates to AddBeaconKitFlags ensure that the new configuration paths are correctly referenced, improving the organization and maintainability of the code.

mod/node-api/backend/backend.go (4)

26-26: LGTM!

The import statement for cache is necessary for integrating the caching mechanism.


68-68: LGTM!

The addition of the cache field enables the caching of query contexts, improving performance by reducing the overhead of creating new contexts for the same slots.


123-123: LGTM!

The initialization of the cache field ensures that each instance of Backend is equipped with caching capabilities tailored to the provided configuration.


176-190: LGTM!

The updates to stateFromSlotRaw effectively utilize the cache for query context management, improving performance and ensuring the integrity of the cached data by copying the state.

mod/config/go.mod (3)

69-69: LGTM!

The addition of github.com/golang-jwt/jwt v3.2.2+incompatible as an indirect dependency may be necessary for compatibility with other components or for specific features not present in the newer version.


116-116: LGTM!

The addition of github.com/stretchr/objx v0.5.2 as an indirect dependency suggests a need for enhanced object manipulation capabilities within the application.


132-132: LGTM!

The addition of golang.org/x/time v0.5.0 as an indirect dependency indicates a need for enhanced time functionalities, possibly to improve time management or scheduling features in the application.

testing/files/entrypoint.sh Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 7f53b05 and dd052b2.

Files selected for processing (2)
  • mod/cli/pkg/flags/flags.go (2 hunks)
  • mod/config/pkg/template/template.go (1 hunks)
Additional comments not posted (5)
mod/config/pkg/template/template.go (2)

98-107: LGTM: Node API server configuration restructuring.

The new section [beacon-kit.node-api.server] clearly separates server-related settings, improving configuration management.


108-113: LGTM: Backend cache configuration addition.

The new section [beacon-kit.node-api.backend.cache] adds settings for cache size and TTL, aligning with the caching implementation objectives.

mod/cli/pkg/flags/flags.go (3)

73-81: LGTM: Node API configuration constants restructuring.

The new constants nodeAPIServerRoot, nodeAPIBackendRoot, and nodeAPICacheRoot improve the organization of Node API settings.


158-168: LGTM: Node API server flag updates.

The updated flag definitions correctly reference the new server configuration paths, enhancing clarity and maintainability.


171-180: LGTM: Backend cache flag additions.

The new flag definitions for cache size and TTL align with the caching implementation objectives.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between dd052b2 and aa81801.

Files selected for processing (1)
  • mod/consensus-types/pkg/types/payload_header_test.go (2 hunks)
Additional comments not posted (2)
mod/consensus-types/pkg/types/payload_header_test.go (2)

42-45: LGTM! But verify the appropriateness of the new initialization values.

The changes ensure that the ExecutionPayloadHeader is instantiated with specific non-empty values. Verify if these values are appropriate for all use cases.


71-74: LGTM!

The changes align the test assertions with the updated initialization values, ensuring that the tests correctly validate the new default state of the ExecutionPayloadHeader.

)

// QueryCache is a cache for query contexts.
type QueryCache struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

I get the motivation here, but I am ensure if this is actually doing anything, you'll have to do some benchmarks / traces

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea we don't have traces set up anywhere. was thinking to use this lib https://github.com/open-telemetry/opentelemetry-go

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between aa81801 and 60078aa.

Files selected for processing (1)
  • mod/node-api/backend/backend.go (7 hunks)
Additional comments not posted (5)
mod/node-api/backend/backend.go (5)

26-26: Import statement for cache looks good.

The import statement for cache is necessary for the new caching mechanism.


68-68: Addition of cache field in Backend struct looks good.

The new field cache is necessary for the caching mechanism.


123-123: Initialization of cache field in New function looks good.

The cache field is correctly initialized using cache.NewQueryCache(cfg.Cache).


181-190: Changes to stateFromSlotRaw function look good.

The function correctly leverages the new cache field for query context management.


190-190: State copying in stateFromSlotRaw function looks good.

The state is correctly copied to prevent unintended mutations.

@calbera
Copy link
Contributor Author

calbera commented Jul 31, 2024

postponing this till we have tracers enabled and live trace data #1849

@calbera calbera marked this pull request as draft July 31, 2024 15:51
@calbera calbera changed the title feat(node-api): Add caching of query contexts to backend perf(node-api): Add caching of query contexts to backend Aug 1, 2024
@itsdevbear itsdevbear closed this Aug 15, 2024
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.

3 participants