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

Minimize expensive API calls #245

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

stokito
Copy link
Contributor

@stokito stokito commented Dec 9, 2020

The PR is intended to improve performance and minimize expensive API calls.
Docker API has two methods: ContainersList() and more detailed Inspect().
The ContainersList() has almost all needed fields except of ENV variables that are shown only in Inspect() response.
So the basic idea of the PR is: what if we'll try to get all fields from ContainersList() but when user opens Single View additionally make Inspect() call to get ENV variables. This also allows us to fetch here other things e.g. #226

Currently ctop works like:

  1. When ctop starts it calls ContainersList() but extracts only name, registers a container and calls a separate Inspect() or each container to get all other fields.
  2. When a new container created ctop receives created event and calls Inspect() to retrieve all fields and only then registers a container.

But in fact the only one container field shown in main view is container's name. All other fields are shown only in Single view.
And the created event already contains container's name and image. So we can just register a container directly from event.
But in future ctop may receive a new functionality to show other fields directly in main view (e.g. show image column). So let's keep the fetching of full info but use cheap ContainersList().

Also the PR has additional improvements: Refresh periodically each 5 minutes to remove non existing containers and bulk refresh.

Inspect call is expensive and slow but almost all fields we can extract directly from List Containers.
The only one missing info for us is ENV VAR which can be retrieved only from inspect
Destroy event may be lost so users may see non existing containers. To cleanup them we have to refresh all containers periodically.
This will be more lightweight API call than inspect
When new container created event received then register the new container with basic fields: name, image.
But we need to request other fields: IPs, ports, etc.
To get them add the new container's id to list needsRefresh.
Usually few containers are created almost simultaneously so to minimize API calls we try to make a batch update.
We'll make a short delay to collect all new containers ids and only then request refresh.
# Conflicts:
#	connector/docker.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant