Skip to content

docs: Add page for caching configuration - #8695

Merged
vikram-dagger merged 6 commits into
dagger:mainfrom
vikram-dagger:docs-184-cache-pruning
Nov 6, 2024
Merged

vikram-dagger merged 6 commits into
dagger:mainfrom
vikram-dagger:docs-184-cache-pruning

Conversation

@vikram-dagger

Copy link
Copy Markdown
Contributor

No description provided.

@vikram-dagger
vikram-dagger requested a review from a team as a code owner October 12, 2024 19:47
Comment thread docs/current_docs/features/caching.mdx Outdated

The layer cache size configuration is managed by [Buildkit's garbage collector](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md?plain=1#L83-L94).

To free up disk space used by the cache, use the following command:

@vikram-dagger vikram-dagger Oct 12, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Which cache does this command impact?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would also love a small table mapping the type of the filters to dagger's functions/apis/etc.

@vikram-dagger
vikram-dagger force-pushed the docs-184-cache-pruning branch from a0a0170 to ebffe32 Compare October 18, 2024 18:14
@vikram-dagger vikram-dagger changed the title docs: Add note on cache size and pruning docs: Add page for caching configuration Oct 19, 2024
@vikram-dagger
vikram-dagger force-pushed the docs-184-cache-pruning branch from 6e2ad5c to 1a3b680 Compare October 19, 2024 15:33
@vikram-dagger
vikram-dagger requested a review from sipsma October 19, 2024 15:36

@TomChv TomChv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Small comments, otherwise look great


Dagger caches two types of data:

1. Layers: This refers to build instructions and the results of some API calls. This cache is implemented by Buildkit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we want to explain a bit more how it works?

Basically a layer is the "receipe" of the instruction (for example COPY) with its arguments (for example a & b) as well as the result.
Then when Dagger executes a Buildkit operation, buildkit will first check if it already has the receipe and if the argument matches, if it does, it will fetch the result directly, skip the execution and send it to the next operation.
In contrary, if the cache miss, all next operations will also have its cache invalidated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added

- It may sometimes be necessary to explicitly force execution of specific pipeline operations, bypassing the Dagger layer cache. The typical approach for this is to [invalidate the Dagger layer cache](../cookbook/cookbook.mdx#invalidate-cache) by introducing a volatile time variable at a specific point in the Dagger pipeline

- For the volume cache:
- Cache the tool's own cache directory instead of caching the installed dependencies directory. For example, with `node` and `npm`, use a cache volume for the `~/.npm` cache directory and not for the project's `node_modules` directory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

AFAIK this change is to optimize how deps are cached and retrieved. @kpenfound can you add more context?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also see #8719


For these tools to cache properly, they need their own cache data (usually a directory) to be persisted between sessions. By using a cache volume for this data, Dagger can reuse the cached contents across pipeline runs and reduce execution time.

## Caching best practices

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why do we remove it? Maybe you can add a link to the other page here too, if someone is looking at the caching page, he might assume best practises are also here and not in configuration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved to features page as I had similar feedback earlier, so perhaps that's the more natural place for this information.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fine by me

@vikram-dagger
vikram-dagger requested a review from TomChv October 24, 2024 11:08
@vikram-dagger
vikram-dagger force-pushed the docs-184-cache-pruning branch from fbf1a0f to 7a01ca6 Compare October 24, 2024 11:15

For these tools to cache properly, they need their own cache data (usually a directory) to be persisted between sessions. By using a cache volume for this data, Dagger can reuse the cached contents across pipeline runs and reduce execution time.

## Caching best practices

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fine by me

@TomChv

TomChv commented Oct 25, 2024

Copy link
Copy Markdown
Member

I let other people give a 2nd look just to confirm then we should merge it :D

Dagger caches two types of data:

1. Layers: This refers to build instructions and the results of some API calls. This cache is implemented by Buildkit.
2. Volumes: This refers to the contents of a Dagger filesystem volume and is persisted across Dagger Engine sessions. It is implemented by Dagger (distinct from Buildkit).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is implemented by Dagger (distinct from Buildkit).

Cache volumes are still implemented by buildkit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@vikram-dagger vikram-dagger Nov 5, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Both caches are managed by BuildKit. In this case, I propose to remove the BuildKit reference altogether, as I'm not sure naming the underlying tech is useful to an end-user.

### Layer caching

- Layers are cached in sequence, and a change in any one layer invalidates that and all subsequent layers. Pay attention to the order of your build operations, and sequence non-volatile operations before volatile ones to avoid invalidating the cache early.
- It may sometimes be necessary to explicitly force execution of specific pipeline operations, bypassing the Dagger layer cache. The typical approach for this is to [invalidate the Dagger layer cache](../cookbook/cookbook.mdx#invalidate-cache) by introducing a volatile time variable at a specific point in the Dagger pipeline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we should have an example? This is the same as before though, so not blocking.

@gerhard gerhard left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mentioned a few nits, but nothing blocking (maybe that BuildKit config link?), so approving optimistically.


Dagger caches two types of data:

1. Layers: This refers to build instructions and the results of some API calls. This cache is implemented by Buildkit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

- Buildkit
+ BuildKit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

See above for related discussion

Dagger caches two types of data:

1. Layers: This refers to build instructions and the results of some API calls. This cache is implemented by Buildkit.
2. Volumes: This refers to the contents of a Dagger filesystem volume and is persisted across Dagger Engine sessions. It is implemented by Dagger (distinct from Buildkit).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

- Show all the cache entry metadata:

```shell
echo '{daggerEngine{localCache{entrySet{entries{description diskSpaceBytes}}}}}' | dagger query

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This reads more human-friendly to me:

dagger query <<EOF
{
  daggerEngine {
    localCache {
      entrySet {
        entries {
          description
          diskSpaceBytes
        }
      }
    }
  }
}
EOF

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

- Show high level summaries of cache usage:

```shell
echo '{daggerEngine{localCache{entrySet{entryCount diskSpaceBytes}}}}' | dagger query

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A more human-friendly version:

dagger query <<EOF
{
  daggerEngine {
    localCache {
      entrySet {
        entryCount
        diskSpaceBytes
      }
    }
  }
}
EOF

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated


## Cache pruning

The layer cache size configuration is managed by [Buildkit's garbage collector](https://github.com/moby/buildkit/blob/master/docs/buildkitd.toml.md?plain=1#L83-L94).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

- Buildkit
+ BuildKit

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would pin this link to a specific version - master is guaranteed to change & this will break. I believe that it did since this PR was opened:

image

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

To free up disk space used by the cache, use the following command:

```shell
dagger core dagger-engine local-cache prune

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

While I really like that this is supported via dagger core, for consistency reasons, I would stick with:

dagger query <<EOF
{
  daggerEngine {
    localCache {
      prune
    }
  }
}
EOF

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated

Vikram Vaswani added 6 commits November 5, 2024 11:30
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
Signed-off-by: Vikram Vaswani <[email protected]>
@vikram-dagger
vikram-dagger force-pushed the docs-184-cache-pruning branch from 7a01ca6 to aa40257 Compare November 5, 2024 06:08
@gerhard

gerhard commented Nov 5, 2024

Copy link
Copy Markdown
Contributor

Just took another look, LGTM 👍

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.

5 participants