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

Use LRUCache for Application Manifests Cache #5108

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pkg/app/piped/cmd/piped/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
addLoginUserToPasswd bool
launcherVersion string
maxRecvMsgSize int
appManifestCacheCount int
}

func NewCommand() *cobra.Command {
Expand All @@ -111,10 +112,11 @@
panic(fmt.Sprintf("failed to detect the current user's home directory: %v", err))
}
p := &piped{
adminPort: 9085,
toolsDir: path.Join(home, ".piped", "tools"),
gracePeriod: 30 * time.Second,
maxRecvMsgSize: 1024 * 1024 * 10, // 10MB
adminPort: 9085,
toolsDir: path.Join(home, ".piped", "tools"),
gracePeriod: 30 * time.Second,
maxRecvMsgSize: 1024 * 1024 * 10, // 10MB
appManifestCacheCount: 150,

Check warning on line 119 in pkg/app/piped/cmd/piped/piped.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/piped/cmd/piped/piped.go#L115-L119

Added lines #L115 - L119 were not covered by tests
}
cmd := &cobra.Command{
Use: "piped",
Expand All @@ -135,6 +137,7 @@
cmd.Flags().BoolVar(&p.enableDefaultKubernetesCloudProvider, "enable-default-kubernetes-cloud-provider", p.enableDefaultKubernetesCloudProvider, "Whether the default kubernetes provider is enabled or not. This feature is deprecated.")
cmd.Flags().BoolVar(&p.addLoginUserToPasswd, "add-login-user-to-passwd", p.addLoginUserToPasswd, "Whether to add login user to $HOME/passwd. This is typically for applications running as a random user ID.")
cmd.Flags().DurationVar(&p.gracePeriod, "grace-period", p.gracePeriod, "How long to wait for graceful shutdown.")
cmd.Flags().IntVar(&p.appManifestCacheCount, "app-manifest-cache-count", p.appManifestCacheCount, "The number of app manifests to cache. The cache-key contains the commit hash. The default is 150.")

Check warning on line 140 in pkg/app/piped/cmd/piped/piped.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/piped/cmd/piped/piped.go#L140

Added line #L140 was not covered by tests

cmd.Flags().StringVar(&p.launcherVersion, "launcher-version", p.launcherVersion, "The version of launcher which initialized this Piped.")

Expand Down Expand Up @@ -355,7 +358,11 @@
analysisResultStore := analysisresultstore.NewStore(apiClient, input.Logger)

// Create memory caches.
appManifestsCache := memorycache.NewTTLCache(ctx, time.Hour, time.Minute)
appManifestsCache, err := memorycache.NewLRUCache(p.appManifestCacheCount)
if err != nil {
input.Logger.Error("failed to create app manifests cache", zap.Error(err))
return err
}

Check warning on line 365 in pkg/app/piped/cmd/piped/piped.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/piped/cmd/piped/piped.go#L361-L365

Added lines #L361 - L365 were not covered by tests

var liveStateGetter livestatestore.Getter
// Start running application live state store.
Expand Down
Loading