-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Benchmark the `Images` implementation (image list) against an image store with 10, 100 and 1000 random images. Currently the images are single-platform only. The images are generated randomly, but a fixed seed is used so the actual testing data will be the same across different executions. Because the content store is not a real containerd image store but a local implementation, a small delay (500us) is added to each content store method call. This is to simulate a real-world usage where each containerd client call requires a gRPC call. Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
- Loading branch information
Showing
3 changed files
with
220 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package specialimage | ||
|
||
import ( | ||
"math/rand" | ||
"strconv" | ||
|
||
"github.com/distribution/reference" | ||
"github.com/opencontainers/go-digest" | ||
ocispec "github.com/opencontainers/image-spec/specs-go/v1" | ||
) | ||
|
||
func RandomSinglePlatform(dir string, platform ocispec.Platform, source rand.Source) (*ocispec.Index, error) { | ||
r := rand.New(source) //nolint:gosec // Ignore G404: Use of weak random number generator (math/rand instead of crypto/rand) | ||
|
||
imageRef := "random-" + strconv.FormatInt(r.Int63(), 10) + ":latest" | ||
|
||
layerCount := r.Intn(8) | ||
|
||
var layers []ocispec.Descriptor | ||
for i := 0; i < layerCount; i++ { | ||
layerDesc, err := writeLayerWithOneFile(dir, "layer-"+strconv.Itoa(i), []byte(strconv.Itoa(i))) | ||
if err != nil { | ||
return nil, err | ||
} | ||
layers = append(layers, layerDesc) | ||
} | ||
|
||
configDesc, err := writeJsonBlob(dir, ocispec.MediaTypeImageConfig, ocispec.Image{ | ||
Platform: platform, | ||
Config: ocispec.ImageConfig{ | ||
Env: []string{"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"}, | ||
}, | ||
RootFS: ocispec.RootFS{ | ||
Type: "layers", | ||
DiffIDs: layersToDigests(layers), | ||
}, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
manifest := ocispec.Manifest{ | ||
MediaType: ocispec.MediaTypeImageManifest, | ||
Config: configDesc, | ||
Layers: layers, | ||
} | ||
|
||
legacyManifests := []manifestItem{ | ||
{ | ||
Config: blobPath(configDesc), | ||
RepoTags: []string{imageRef}, | ||
Layers: blobPaths(layers), | ||
}, | ||
} | ||
|
||
ref, err := reference.ParseNormalizedNamed(imageRef) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return singlePlatformImage(dir, ref, manifest, legacyManifests) | ||
} | ||
|
||
func layersToDigests(layers []ocispec.Descriptor) []digest.Digest { | ||
var digests []digest.Digest | ||
for _, l := range layers { | ||
digests = append(digests, l.Digest) | ||
} | ||
return digests | ||
} | ||
|
||
func blobPaths(descriptors []ocispec.Descriptor) []string { | ||
var paths []string | ||
for _, d := range descriptors { | ||
paths = append(paths, blobPath(d)) | ||
} | ||
return paths | ||
} |