Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Reduce sorts done by ListImagesWithOptions #2338

Merged
merged 2 commits into from
Aug 15, 2019
Merged

Reduce sorts done by ListImagesWithOptions #2338

merged 2 commits into from
Aug 15, 2019

Conversation

squaremo
Copy link
Member

@squaremo squaremo commented Aug 8, 2019

The PR as a whole is intended to address #2328 by reducing the number of sorts, since that was identified as a bottleneck there.

The API ListImagesWithOptions as called by Weave Cloud asks for pretty much all the fields, so the first commit here will not make a big difference -- there will still be one sort per container. It may avoid some allocation, and some calculation in other uses (i.e., when not called by Weave Cloud).

The second commit caches the result of sorting by timestamp, when that is done. It will be effective to the extent that

  • the same image is used in more than one container
  • containers are using tag filters that ordered the images by timestamp (i.e., everything but semver)

There are some modest improvements that could be made with more invasive changes. Possibly the biggest improvement would be to sort images (actually the image tags) when they are fetched, rather than when they are used, since the latter will usually outnumber the former by orders of magnitude.

@squaremo squaremo changed the title Only calculate container fields that are requested Reduce sorts done by ListImagesWithOptions Aug 8, 2019
@squaremo squaremo marked this pull request as ready for review August 12, 2019 10:12
@stefanprodan stefanprodan added this to the 1.14.0 milestone Aug 13, 2019
The ListImagesWithOptions API method lets you supply a list of the
fields you want for each container, so that you can cut down on the
size of the response when you don't care about some fields. But all
the fields are calculated, whatever you ask for, which involves a lot
of sorting and filtering.

This commit makes the procedure calculating the fields _only_
calculate the fields that were actually requested. Some of the
calculations depend on the same intermediate results; so, the approach
is to lazily calculate and cache intermediate results.
Much of the time, the images returned from the ListImagesWithOptions
API are sorted according to timestamp. As a cheap and simple
optimisation for this case, when we're constructing a result, cache
both the slice of image.Info records and those records sorted by
timestamp.

This means, for any given request, images that occur in more than one
container will be sorted by timestamp only once.
@squaremo squaremo merged commit 2f37429 into master Aug 15, 2019
@squaremo squaremo deleted the do-less-sorting branch August 15, 2019 10:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants