Commit Graph

48 Commits

Author SHA1 Message Date
Iceber Gu
778e8f2af4 Use the const labels.LabelUncompressed
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
2023-01-03 18:29:21 +08:00
Maksym Pavlenko
b5366f8d7e CRI: Retrieve image spec on client
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
2022-05-26 12:38:55 -07:00
Wei Fu
8113758568 CRI: improve image pulling performance
Background:

With current design, the content backend uses key-lock for long-lived
write transaction. If the content reference has been marked for write
transaction, the other requestes on the same reference will fail fast with
unavailable error. Since the metadata plugin is based on boltbd which
only supports single-writer, the content backend can't block or handle
the request too long. It requires the client to handle retry by itself,
like OpenWriter - backoff retry helper. But the maximum retry interval
can be up to 2 seconds. If there are several concurrent requestes fo the
same image, the waiters maybe wakeup at the same time and there is only
one waiter can continue. A lot of waiters will get into sleep and we will
take long time to finish all the pulling jobs and be worse if the image
has many more layers, which mentioned in issue #4937.

After fetching, containerd.Pull API allows several hanlers to commit
same ChainID snapshotter but only one can be done successfully. Since
unpack tar.gz is time-consuming job, it can impact the performance on
unpacking for same ChainID snapshotter in parallel.

For instance, the Request 2 doesn't need to prepare and commit, it
should just wait for Request 1 finish, which mentioned in pull
request #6318.

```text
	Request 1	Request 2

	Prepare
	   |
	   |
	   |
	   |		Prepare
	Commit		   |
			   |
			   |
			   |
			Commit(failed on exist)
```

Both content backoff retry and unnecessary unpack impacts the performance.

Solution:

Introduced the duplicate suppression in fetch and unpack context. The
deplicate suppression uses key-mutex and single-waiter-notify to support
singleflight. The caller can use the duplicate suppression in different
PullImage handlers so that we can avoid unnecessary unpack and spin-lock
in OpenWriter.

Test Result:

Before enhancement:

```bash
➜  /tmp sudo bash testing.sh "localhost:5000/redis:latest" 20
crictl pull localhost:5000/redis:latest (x20) takes ...

real	1m6.172s
user	0m0.268s
sys	0m0.193s

docker pull localhost:5000/redis:latest (x20) takes ...

real	0m1.324s
user	0m0.441s
sys	0m0.316s

➜  /tmp sudo bash testing.sh "localhost:5000/golang:latest" 20
crictl pull localhost:5000/golang:latest (x20) takes ...

real	1m47.657s
user	0m0.284s
sys	0m0.224s

docker pull localhost:5000/golang:latest (x20) takes ...

real	0m6.381s
user	0m0.488s
sys	0m0.358s
```

With this enhancement:

```bash
➜  /tmp sudo bash testing.sh "localhost:5000/redis:latest" 20
crictl pull localhost:5000/redis:latest (x20) takes ...

real	0m1.140s
user	0m0.243s
sys	0m0.178s

docker pull localhost:5000/redis:latest (x20) takes ...

real	0m1.239s
user	0m0.463s
sys	0m0.275s

➜  /tmp sudo bash testing.sh "localhost:5000/golang:latest" 20
crictl pull localhost:5000/golang:latest (x20) takes ...

real	0m5.546s
user	0m0.217s
sys	0m0.219s

docker pull localhost:5000/golang:latest (x20) takes ...

real	0m6.090s
user	0m0.501s
sys	0m0.331s
```

Test Script:

localhost:5000/{redis|golang}:latest is equal to
docker.io/library/{redis|golang}:latest. The image is hold in local registry
service by `docker run -d -p 5000:5000 --name registry registry:2`.

```bash

image_name="${1}"
pull_times="${2:-10}"

cleanup() {
  ctr image rmi "${image_name}"
  ctr -n k8s.io image rmi "${image_name}"
  crictl rmi "${image_name}"
  docker rmi "${image_name}"
  sleep 2
}

crictl_testing() {
  for idx in $(seq 1 ${pull_times}); do
    crictl pull "${image_name}" > /dev/null 2>&1 &
  done
  wait
}

docker_testing() {
  for idx in $(seq 1 ${pull_times}); do
    docker pull "${image_name}" > /dev/null 2>&1 &
  done
  wait
}

cleanup > /dev/null 2>&1

echo 3 > /proc/sys/vm/drop_caches
sleep 3
echo "crictl pull $image_name (x${pull_times}) takes ..."
time crictl_testing
echo

echo 3 > /proc/sys/vm/drop_caches
sleep 3
echo "docker pull $image_name (x${pull_times}) takes ..."
time docker_testing
```

Fixes: #4937
Close: #4985
Close: #6318

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2022-04-06 07:14:18 +08:00
haoyun
bbe46b8c43 feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io>
Co-authored-by: zounengren <zouyee1989@gmail.com>
2022-01-07 10:27:03 +08:00
haoyun
c0d07094be feat: Errorf usage
Signed-off-by: haoyun <yun.hao@daocloud.io>
2021-12-13 14:31:53 +08:00
Akihiro Suda
cd2f2b0af6
client: expose (*image).platform
Expose (*image).platform as Image.Platform() .

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2021-10-21 19:46:50 +09:00
Kathryn Baldauf
f8992f451c add optional check that snapshotter supports the image platform when unpacking
Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
2020-12-10 10:54:22 -08:00
Phil Estes
0c9b05fa60
Fix image usage calculation error
Including snapshotter usage in total calculation should be gated by the
option `snapshotter` boolean.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
2020-05-20 08:44:05 -04:00
Michael Crosby
6a22a8fc9e Return the underlying images metadata
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-12-04 13:03:41 -05:00
Lantao Liu
555cb31fd9 Support configurable default platform in the client.
Signed-off-by: Lantao Liu <lantaol@google.com>
2019-09-03 13:34:25 -07:00
Phil Estes
ec0c968215
Merge pull request #3520 from dmcgowan/image-usage
Add image usage function to client
2019-08-12 18:01:15 -04:00
Derek McGowan
75771c4634
Add usage function to client
The usage function allows more configurable and accurate calculations
of the usage for an image.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2019-08-09 15:46:22 -07:00
Michael Crosby
3fded74bc7 Add unpack opts
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-08-07 18:35:55 +00:00
Maksym Pavlenko
550a6f1d73 Fix integration tests
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2019-07-11 11:54:48 -07:00
Maksym Pavlenko
1918ee4d11 Respect default snapshotter label
Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
2019-07-10 12:16:43 -07:00
Michael Crosby
41e1bb8328 Fix snapshotter getter in client code
Fixes #3312

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2019-06-17 16:57:48 +00:00
Wei Fu
2d96aad771 bugfix: unpack should always set the snapshot gc label
There are two images, A and B. A is based on B. If user pulls A first,
then user pulls B. containerd already has the unpacked snapshots in the
backend. During unpacking B, the client doesn't set gc snapshot
reference label to the config descriptor. That is the problem.

The gc module cannot reach the snapshot from the config descriptor. If
user removes the image B, the snapshot will be deleted by gc module.
That is why we should always set the snapshot gc label to config
descriptor.

Signed-off-by: Wei Fu <fhfuwei@163.com>
2018-12-14 09:59:19 +08:00
Lantao Liu
3d5a408bfa Add Labels to client.Image.
Signed-off-by: Lantao Liu <lantaol@google.com>
2018-09-26 00:42:13 -07:00
Derek McGowan
9edcfcc1cb
Add platform match comparer interface
Adds a new platform interface for matching and comparing platforms.
This new interface allows both filtering and ordering of platforms
to support running multiple platform and choosing the best platform.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-08-27 00:11:46 -07:00
Derek McGowan
3a916a0f67
Update client Image to have configurable platform
Separate Fetch and Pull commands in client to distinguish
between platform specific and non-platform specific operations.
`ctr images pull` with all platforms will now unpack all platforms.
`ctr content fetch` now supports platform flags.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-07-17 15:43:03 -07:00
Michael Crosby
367666091b Add NewImage to return a client Image impl
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2018-04-09 14:56:46 -04:00
Derek McGowan
d608e3d9dc
Fix label being put on snapshot instead of content
The uncompressed label should be placed on content instead
of snapshots. Currently the uncompressed label is getting
passed into as a label option for apply, which is used to commit
snapshots. The content is already committed, but after apply
the uncompressed diff digest is verified and can be reliably used
to update the content with the label.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-03-27 17:55:35 -07:00
Derek McGowan
43d0a5cb60
Pass in context to lease done function in client
Allows the client to choose the context to finish the lease.
This allows the client to switch contexts when the main context
used to the create the lease may have been cancelled.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2018-03-22 14:09:24 -07:00
Kunal Kushwaha
b12c3215a0 Licence header added
Signed-off-by: Kunal Kushwaha <kushwaha_kunal_v7@lab.ntt.co.jp>
2018-02-19 10:32:26 +09:00
Jess Valarezo
41ac9fac8e update images error
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-12-01 15:14:55 -08:00
Jess Valarezo
9885edfc44 rename snapshot->snapshots pkg
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-11-29 14:55:02 -08:00
Daniel Nephin
f6e877e8be Proposed fix for image content store
Signed-off-by: Daniel Nephin <dnephin@gmail.com>
2017-11-27 16:16:17 -05:00
Lantao Liu
33c95bb418 Fix build.
Signed-off-by: Lantao Liu <lantaol@google.com>
2017-11-27 18:27:20 +00:00
yanxuean
545f247c8e prevent snapshot from gc when unpack image
Signed-off-by: yanxuean <yan.xuean@zte.com.cn>
2017-11-23 17:29:29 +08:00
Derek McGowan
dce27d8c62
Remove client use of gc root label
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-11-07 12:54:22 -08:00
Jess Valarezo
1552ee23da client: Add helper function which checks if an image is unpacked
Signed-off-by: Jess Valarezo <valarezo.jessica@gmail.com>
2017-10-30 16:33:54 -07:00
Derek McGowan
7884707c2f
Add reference labels to snapshots and content
Ensure all snapshots and content are referenced on commit and
protected from cleanup.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-10-11 10:42:47 -07:00
Allen Sun
382dafefc0 fix a potential panic when map is nil
Signed-off-by: Allen Sun <shlallen1990@gmail.com>
2017-09-27 13:59:37 +08:00
Derek McGowan
eef47ffad3
Add platform filtering on children handler
Fixes pulling of multi-arch images by limiting the expansion
of the index by filtering to the current default platform.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-09-20 15:18:18 -07:00
Stephen J Day
9163377123
platforms: provide simpler function for common use
Signed-off-by: Stephen J Day <stephen.day@docker.com>
2017-09-20 11:56:59 -07:00
Derek McGowan
46ded63f2d
Support for multi-arch image unpacking
Resolves the platform on multi-arch manifests during unpack and config resolving.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-09-14 09:32:37 -07:00
Lantao Liu
76e016ca30 Add image config function.
Signed-off-by: Lantao Liu <lantaol@google.com>
2017-08-30 23:02:43 +00:00
Abhinandan Prativadi
7a5d592372 Exposing helpers to access internal structure
Adding image.Config,image.Size,image.RootFS to retrieve the internal image information
which will be needed by consumers of containerd

Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
2017-08-11 17:09:29 -07:00
Michael Crosby
0a85f6e47d Update godoc for client package
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-08-04 11:53:31 -04:00
Derek McGowan
a78d0bdeac
Update the content interface to return info from update
Namespace keys used by client for uncompressed

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-12 16:22:13 -07:00
Derek McGowan
fba7463ed3
Add labels and fileters to content
Update list content command to support filters
Add label subcommand to content in dist tool to update labels
Add uncompressed label on unpack

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-07-12 13:59:17 -07:00
Akihiro Suda
b06aab713a support using multiple snapshotters simultaneously
e.g. dist pull --snapshotter btrfs ...; ctr run --snapshotter btrfs ...
(empty string defaults for overlayfs)

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-07-12 11:16:12 -07:00
Akihiro Suda
696e383d21 image.go: fix duplicated import
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
2017-06-29 06:15:36 +00:00
Derek McGowan
ca25c0408e
Update dist pull to use client
Replaced pull unpacker with boolean to call unpack.
Added unpack and target to image type.
Updated progress logic for pull.
Added list images to client.
Updated rootfs unpacker to use client.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
2017-06-06 15:03:52 -07:00
Michael Crosby
d0b22290ec Don't require rootfs if not set on container
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-05-25 11:17:36 -07:00
Michael Crosby
608e6daaa4 Make Task, Container, Image interface types
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-05-25 11:05:58 -07:00
Michael Crosby
bf9ad0c57f Fix spec generation for task execution
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-05-24 15:40:40 -07:00
Michael Crosby
923236004a Add pull support to client
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
2017-05-24 14:08:58 -07:00