Speed up VM create with work seeds
Beat VM create wall time without changing VM semantics. Generate a work-seed ext4 sidecar during image builds and rootfs rebuilds, then clone and resize that seed for each new VM instead of rebuilding /root from scratch. Plumb the new seed artifact through config, runtime metadata, store state, runtime-bundle defaults, doctor checks, and default-image reconciliation so older images still fall back cleanly. Add a daemon TAP pool to keep idle bridge-attached devices warm, expose stage timing in lifecycle logs, add a create/SSH benchmark script plus Make target, and teach verify.sh that tap-pool-* devices are reusable capacity rather than cleanup leaks. Validated with go test ./..., make build, ./verify.sh, and make bench-create ARGS="--runs 2".
This commit is contained in:
parent
a14a80fd6b
commit
c8d9a122f9
24 changed files with 695 additions and 44 deletions
|
|
@ -74,6 +74,7 @@ func (s *Store) migrate() error {
|
|||
managed INTEGER NOT NULL DEFAULT 0,
|
||||
artifact_dir TEXT,
|
||||
rootfs_path TEXT NOT NULL,
|
||||
work_seed_path TEXT,
|
||||
kernel_path TEXT NOT NULL,
|
||||
initrd_path TEXT,
|
||||
modules_dir TEXT,
|
||||
|
|
@ -103,6 +104,9 @@ func (s *Store) migrate() error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
if err := ensureColumnExists(s.db, "images", "work_seed_path", "TEXT"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -111,14 +115,15 @@ func (s *Store) UpsertImage(ctx context.Context, image model.Image) error {
|
|||
defer s.writeMu.Unlock()
|
||||
const query = `
|
||||
INSERT INTO images (
|
||||
id, name, managed, artifact_dir, rootfs_path, kernel_path, initrd_path,
|
||||
id, name, managed, artifact_dir, rootfs_path, work_seed_path, kernel_path, initrd_path,
|
||||
modules_dir, packages_path, build_size, docker, created_at, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
ON CONFLICT(id) DO UPDATE SET
|
||||
name=excluded.name,
|
||||
managed=excluded.managed,
|
||||
artifact_dir=excluded.artifact_dir,
|
||||
rootfs_path=excluded.rootfs_path,
|
||||
work_seed_path=excluded.work_seed_path,
|
||||
kernel_path=excluded.kernel_path,
|
||||
initrd_path=excluded.initrd_path,
|
||||
modules_dir=excluded.modules_dir,
|
||||
|
|
@ -132,6 +137,7 @@ func (s *Store) UpsertImage(ctx context.Context, image model.Image) error {
|
|||
boolToInt(image.Managed),
|
||||
image.ArtifactDir,
|
||||
image.RootfsPath,
|
||||
image.WorkSeedPath,
|
||||
image.KernelPath,
|
||||
image.InitrdPath,
|
||||
image.ModulesDir,
|
||||
|
|
@ -145,15 +151,15 @@ func (s *Store) UpsertImage(ctx context.Context, image model.Image) error {
|
|||
}
|
||||
|
||||
func (s *Store) GetImageByName(ctx context.Context, name string) (model.Image, error) {
|
||||
return s.getImage(ctx, "SELECT id, name, managed, artifact_dir, rootfs_path, kernel_path, initrd_path, modules_dir, packages_path, build_size, docker, created_at, updated_at FROM images WHERE name = ?", name)
|
||||
return s.getImage(ctx, "SELECT id, name, managed, artifact_dir, rootfs_path, work_seed_path, kernel_path, initrd_path, modules_dir, packages_path, build_size, docker, created_at, updated_at FROM images WHERE name = ?", name)
|
||||
}
|
||||
|
||||
func (s *Store) GetImageByID(ctx context.Context, id string) (model.Image, error) {
|
||||
return s.getImage(ctx, "SELECT id, name, managed, artifact_dir, rootfs_path, kernel_path, initrd_path, modules_dir, packages_path, build_size, docker, created_at, updated_at FROM images WHERE id = ?", id)
|
||||
return s.getImage(ctx, "SELECT id, name, managed, artifact_dir, rootfs_path, work_seed_path, kernel_path, initrd_path, modules_dir, packages_path, build_size, docker, created_at, updated_at FROM images WHERE id = ?", id)
|
||||
}
|
||||
|
||||
func (s *Store) ListImages(ctx context.Context) ([]model.Image, error) {
|
||||
rows, err := s.db.QueryContext(ctx, "SELECT id, name, managed, artifact_dir, rootfs_path, kernel_path, initrd_path, modules_dir, packages_path, build_size, docker, created_at, updated_at FROM images ORDER BY created_at ASC")
|
||||
rows, err := s.db.QueryContext(ctx, "SELECT id, name, managed, artifact_dir, rootfs_path, work_seed_path, kernel_path, initrd_path, modules_dir, packages_path, build_size, docker, created_at, updated_at FROM images ORDER BY created_at ASC")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -330,6 +336,7 @@ type scanner interface {
|
|||
func scanImageRow(row scanner) (model.Image, error) {
|
||||
var image model.Image
|
||||
var managed, docker int
|
||||
var workSeedPath sql.NullString
|
||||
var createdAt, updatedAt string
|
||||
err := row.Scan(
|
||||
&image.ID,
|
||||
|
|
@ -337,6 +344,7 @@ func scanImageRow(row scanner) (model.Image, error) {
|
|||
&managed,
|
||||
&image.ArtifactDir,
|
||||
&image.RootfsPath,
|
||||
&workSeedPath,
|
||||
&image.KernelPath,
|
||||
&image.InitrdPath,
|
||||
&image.ModulesDir,
|
||||
|
|
@ -351,6 +359,7 @@ func scanImageRow(row scanner) (model.Image, error) {
|
|||
}
|
||||
image.Managed = managed == 1
|
||||
image.Docker = docker == 1
|
||||
image.WorkSeedPath = workSeedPath.String
|
||||
image.CreatedAt, err = time.Parse(time.RFC3339, createdAt)
|
||||
if err != nil {
|
||||
return image, err
|
||||
|
|
@ -417,6 +426,35 @@ func scanVMInto(row scanner) (model.VMRecord, error) {
|
|||
return vm, nil
|
||||
}
|
||||
|
||||
func ensureColumnExists(db *sql.DB, table, column, columnType string) error {
|
||||
rows, err := db.Query(fmt.Sprintf("PRAGMA table_info(%s)", table))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
var (
|
||||
cid int
|
||||
name string
|
||||
valueType string
|
||||
notNull int
|
||||
defaultV sql.NullString
|
||||
pk int
|
||||
)
|
||||
if err := rows.Scan(&cid, &name, &valueType, ¬Null, &defaultV, &pk); err != nil {
|
||||
return err
|
||||
}
|
||||
if name == column {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if err := rows.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = db.Exec(fmt.Sprintf("ALTER TABLE %s ADD COLUMN %s %s", table, column, columnType))
|
||||
return err
|
||||
}
|
||||
|
||||
func boolToInt(value bool) int {
|
||||
if value {
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -340,6 +340,7 @@ func sampleImage(name string) model.Image {
|
|||
Managed: true,
|
||||
ArtifactDir: "/artifacts/" + name,
|
||||
RootfsPath: "/images/" + name + ".ext4",
|
||||
WorkSeedPath: "/images/" + name + ".work-seed.ext4",
|
||||
KernelPath: "/kernels/" + name,
|
||||
InitrdPath: "/initrd/" + name,
|
||||
ModulesDir: "/modules/" + name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue