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

atc: Consider image volumes in volume-locality strategy #8057

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 21 additions & 8 deletions atc/worker/placement.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,33 +140,33 @@ type volumeLocalityStrategy struct{}
func (strategy volumeLocalityStrategy) Order(logger lager.Logger, pool Pool, workers []db.Worker, spec runtime.ContainerSpec) ([]db.Worker, error) {
counts := make(map[string]int, len(workers))

for _, input := range spec.Inputs {
volume, ok := input.Artifact.(runtime.Volume)
updateCountsForArtifact := func(artifact runtime.Artifact, destinationPath string) error {
volume, ok := artifact.(runtime.Volume)
if !ok {
// Non-volume artifacts don't live on workers, so don't affect
// volume locality decisions.
continue
return nil
}
logger := logger.WithData(lager.Data{
"handle": volume.Handle(),
"path": input.DestinationPath,
"path": destinationPath,
})
srcWorker := volume.DBVolume().WorkerName()
counts[srcWorker]++

resourceCacheID := volume.DBVolume().GetResourceCacheID()
if resourceCacheID == 0 {
logger.Debug("resource-not-cached")
continue
return nil
}
resourceCache, found, err := pool.db.ResourceCacheFactory.FindResourceCacheByID(resourceCacheID)
if err != nil {
logger.Error("failed-to-find-resource-cache", err)
return nil, err
return err
}
if !found {
logger.Debug("resource-cache-not-found")
continue
return nil
}
for _, worker := range workers {
if worker.Name() == srcWorker {
Expand All @@ -175,12 +175,25 @@ func (strategy volumeLocalityStrategy) Order(logger lager.Logger, pool Pool, wor
_, found, err := pool.db.VolumeRepo.FindResourceCacheVolume(worker.Name(), resourceCache)
if err != nil {
logger.Error("failed-to-find-resource-cache-volume", err)
return nil, err
return err
}
if found {
counts[worker.Name()]++
}
}
return nil
}

err := updateCountsForArtifact(spec.ImageSpec.ImageArtifact, "/")
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually image is much bigger than other artifacts, can we give image 5 counts?

That way will especially benefit those use case where some job uses huge task images, but the job doesn't run frequently. Current image-get runs on a worker, task runs on the other worker, image streaming take longer time than directly pulling image from registry, because volume streaming involves tar->gzip->ungzip->untar.

if err != nil {
return nil, err
}

for _, input := range spec.Inputs {
err := updateCountsForArtifact(input.Artifact, input.DestinationPath)
if err != nil {
return nil, err
}
}

for _, cachePath := range spec.Caches {
Expand Down
27 changes: 27 additions & 0 deletions atc/worker/placement_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,33 @@ var _ = Describe("Container Placement Strategies", func() {
return strategy
}

Test("sorts the workers based on image volume", func() {
scenario := Setup(
workertest.WithBasicJob(),
workertest.WithWorkers(
grt.NewWorker("worker1").
WithVolumesCreatedInDBAndBaggageclaim(
grt.NewVolume("image-volume1"),
),
grt.NewWorker("worker2").
WithVolumesCreatedInDBAndBaggageclaim(
grt.NewVolume("image-volume2"),
),
),
)

workers, err := volumeLocalityStrategy().Order(logger, scenario.Pool, scenario.DB.Workers, runtime.ContainerSpec{
TeamID: scenario.TeamID,
JobID: scenario.JobID,
StepName: scenario.StepName,
ImageSpec: runtime.ImageSpec{
ImageArtifact: scenario.WorkerVolume("worker2", "image-volume2"),
},
})
Expect(err).ToNot(HaveOccurred())
Expect(workerNames(workers)).To(Equal([]string{"worker2", "worker1"}))
})

Test("sorts the workers by number of local inputs", func() {
scenario := Setup(
workertest.WithBasicJob(),
Expand Down