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

Initial layer caching implementation #95

Draft
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

GZGavinZhao
Copy link
Member

@GZGavinZhao GZGavinZhao commented Mar 25, 2024

WIP.

Current issues:

  • If you Ctrl+C or something catastrophic happens during layer creation (i.e. the fetching of dependencies), the incomplete layer is not deleted. It should be deleted. When this happens, find the hash at the start of the output of solbuild build and sudo rm -rf /var/cache/solbuild/layers/<hash>. Or just sudo rm -rf /var/cache/solbuild/layers to delete all layers.
  • It seems like 32bit dependencies are not installed correctly.
  • Display the hash of the layer not only at the start of the build, but also at the end of the build as well.

This PR shouldn't touch anything outside of /var/cache/solbuild/layers, so if anything catastrophic happens, just run sudo solbuild dc and start over.

Test instructions:

  1. Ensure you have the xxhash package installed because you need the xxxh128sum binary in your PATH.
  2. gh pr checkout 95 or checkout this branch however you prefer to.
  3. make
  4. Now you should have a solbuild binary in ./bin/solbuild. Use this solbuild as how you would normally build packages. You should notice that after you build a package once, when you build it the second time, it should jump straight to the setup phase, skipping the step of installing dependencies.

@joebonrichie
Copy link
Contributor

joebonrichie commented Mar 31, 2024

It looks like hashFile()/hashFileBytes() does the same thing as FileSha256sum()

I also tried an implementation with XXH3

import "github.com/zeebo/xxh3"

func FileXXH3Sum(path string) (string, error) {
	defer timeTaken("FileXXH3Sum")()
	mfile, err := os.Open(path)
	if err != nil {
		return "", err
	}
	defer mfile.Close()

	h := xxh3.New()

	_, err = io.Copy(h, mfile)
	if err != nil {
		return "", err
	}

	return fmt.Sprintf("%x", h.Sum128().Bytes()), nil
}
func timeTaken(name string) func() {
	start := time.Now()
	return func() {
		fmt.Printf("%s execution time: %v\n", name, time.Since(start))
	}
}

A similar thing could be done with blake3 which would allow 256bits again.

Dirty benchmarks (m64py)
FileXXH3Sum execution time: 5.10317828s (uncached)
FileXXH3Sum execution time: 1.441753051s (cached)
FileSha256sum execution time: 9.536810397s (uncached)
FileSha256sum execution time: 5.823365451s (cached)

edit: it looks like your hashFileBytes() implementation using io.Copy is slightly faster than the MapFile approach.

@ermo
Copy link
Contributor

ermo commented Apr 4, 2024

Friendly reminder that this solbuild version appears to rundep on xxhash, which contains the xxh128sum binary used to hash the layers.

Should probably be added in the cover letter or in the readme + added as a proper solbuild rundep once this hits the repo...

@ermo ermo added enhancement New feature or request help wanted Extra attention is needed labels Apr 5, 2024
@GZGavinZhao GZGavinZhao self-assigned this Jun 14, 2024
@GZGavinZhao
Copy link
Member Author

Feature-wise complete, I've been using this since April as well. Need some code cleanup and add this feature behind a flag, then this should be ready for review.

@joebonrichie
Copy link
Contributor

Chrooting after a interrupted build seems to fail, even after deleting the layers

^C 🗲  CTRL+C interrupted, cleaning up 
 ✗  Exiting due to interruption 
task: Failed to run task "build": exit status 1
[ble: exit 201]
⮞  ninya   git:main  ~/solus/…/l/libvpx  1  sudo rm -rf /var/cache/solbuild/layers/
 ⮞  ninya   git:main  ~/solus/…/l/libvpx  sudo solbuild chroot
 ✓  Using default profile name=unstable-x86_64
mount: /var/cache/solbuild/unstable-x86_64/libvpx/union: fsconfig system call failed: Stale file handle.
       dmesg(1) may have more information after failed mount system call.
 ✗  Failed to mount overlayfs point=/var/cache/solbuild/unstable-x86_64/libvpx/union err="exit status 32"
[ble: exit 1]

@GZGavinZhao
Copy link
Member Author

@joebonrichie Arghh I completely overlooked the chroot command because I don't use it... I fixed the layer cleanup issue which caused the mount failure, but currently the layer is not being brought into the chroot so I'm going to fix that next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants