1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon
Kir Kolyshkin a076badb8b ContainerTop: speed up
Current ContainerTop (a.k.a. docker top) implementation uses "ps"
to get the info about *all* running processes, then parses it, then
filters the results to only contain PIDs used by the container.
Collecting data only to throw most of it away is inefficient,
especially on a system running many containers (or processes).
For example, "docker top" on a container with a single process
can take up to 0.5 seconds to execute (on a mostly idle system)
which is noticeably slow.

Since the containers PIDs are known beforehand, let's use ps's
"-q" option to provide it with a list of PIDs we want info about.

The problem with this approach is, some ps options can't be used
with "-q" (the only one I'm aware of is "f" ("forest view") but
there might be more). As the list of such options is not known,
in case ps fails, it is executed again without "q" (retaining
the old behavior).

Next, the data produced by "ps" is filtered in the same way as before.
The difference here is, in case "-q" worked, the list is much shorter.

I ran some benchmarks on my laptop, with about 8000 "sleep" processes
running to amplify the savings.

The improvement in "docker top" execution times is 5x to 10x (roughly
0.05s vs 0.5s).

The improvement in ContainerTop() execution time is up to 100x
(roughly 3ms vs 300ms).

I haven't measured the memory or the CPU time savings, guess those
are not that critical.

NOTE that busybox ps does not implement -q so the fallback is always
used, but AFAIK it is not usable anyway and Docker expects a normal
ps to be on the system (say the list of fields produced by
"busybox ps -ef" differs from normal "ps -ef" etc.).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-05-24 18:24:27 -07:00
..
caps Add canonical import comment 2018-02-05 16:51:57 -05:00
cluster Fix typos: remove duplicated "the" 2018-05-17 21:49:51 +09:00
config Replace deprecated testutil.ErrorContains() 2018-05-21 00:13:04 +02:00
discovery Automated migration using 2018-03-16 11:03:43 -04:00
events Add canonical import comment 2018-02-05 16:51:57 -05:00
exec Add canonical import comment 2018-02-05 16:51:57 -05:00
graphdriver aufs: log reason why aufs is not supported. 2018-05-20 12:02:41 +02:00
images Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
initlayer Add canonical import comment 2018-02-05 16:51:57 -05:00
links Add canonical import comment 2018-02-05 16:51:57 -05:00
listeners Add canonical import comment 2018-02-05 16:51:57 -05:00
logger Replace deprecated testutil.ErrorContains() 2018-05-21 00:13:04 +02:00
names Add canonical import comment 2018-02-05 16:51:57 -05:00
network Add canonical import comment 2018-02-05 16:51:57 -05:00
stats Fix stats collector spinning CPU if no stats are collected 2018-03-15 17:56:15 +01:00
testdata Remove libtrust dep from api 2017-09-06 12:05:19 -04:00
apparmor_default.go Add canonical import comment 2018-02-05 16:51:57 -05:00
apparmor_default_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_tarcopyoptions.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_tarcopyoptions_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_tarcopyoptions_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
archive_unix.go Move mount parsing to separate package. 2018-04-19 06:35:54 -04:00
archive_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
attach.go Add canonical import comment 2018-02-05 16:51:57 -05:00
auth.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
bindmount_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
changes.go c.RWLayer: check for nil before use 2018-02-09 11:24:09 -08:00
checkpoint.go Add canonical import comment 2018-02-05 16:51:57 -05:00
cluster.go Add canonical import comment 2018-02-05 16:51:57 -05:00
commit.go Move all daemon image methods into imageService 2018-02-26 16:48:29 -05:00
configs.go Merge configs/secrets in unix implementation 2018-02-16 11:25:14 -05:00
configs_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
configs_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
configs_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
container.go Move mount parsing to separate package. 2018-04-19 06:35:54 -04:00
container_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
container_operations.go Move network operations out of container package 2018-05-10 17:16:00 -04:00
container_operations_unix.go Don't make container mount unbindable 2018-04-10 15:14:34 -04:00
container_operations_windows.go Move network operations out of container package 2018-05-10 17:16:00 -04:00
container_unix_test.go Automated migration using 2018-03-16 11:03:43 -04:00
container_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
create.go Move ImageService to new package 2018-02-26 16:49:37 -05:00
create_test.go Automated migration using 2018-03-16 11:03:43 -04:00
create_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
create_windows.go Move mount parsing to separate package. 2018-04-19 06:35:54 -04:00
daemon.go Merge pull request #36396 from selansen/master 2018-05-03 06:34:14 -04:00
daemon_linux.go Merge pull request #36091 from kolyshkin/mount 2018-04-21 11:03:54 +02:00
daemon_linux_test.go daemon unit tests: skip some if non-root 2018-05-22 13:12:29 -07:00
daemon_test.go daemon unit tests: skip some if non-root 2018-05-22 13:12:29 -07:00
daemon_unix.go Allow user to control the default address pools 2018-04-30 11:14:08 -04:00
daemon_unix_test.go Remove old/uneeded volume migration from vers 1.7 2018-04-17 14:06:53 -04:00
daemon_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
daemon_windows.go Remove old/uneeded volume migration from vers 1.7 2018-04-17 14:06:53 -04:00
daemon_windows_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
debugtrap_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
debugtrap_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
debugtrap_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
delete.go Move ImageService to new package 2018-02-26 16:49:37 -05:00
delete_test.go Replace deprecated testutil.ErrorContains() 2018-05-21 00:13:04 +02:00
dependency.go Add canonical import comment 2018-02-05 16:51:57 -05:00
disk_usage.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
errors.go Add canonical import comment 2018-02-05 16:51:57 -05:00
events.go Image events 2018-02-21 18:26:16 -05:00
events_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
exec.go Merge pull request #36815 from allencloud/simplify-ode 2018-05-11 10:06:33 -04:00
exec_linux.go Fix AppArmor not being applied to Exec processes 2018-03-02 14:05:36 +01:00
exec_linux_test.go Fix AppArmor not being applied to Exec processes 2018-03-02 14:05:36 +01:00
exec_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
export.go daemon.ContainerExport(): do not panic 2018-03-13 21:24:43 -07:00
health.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
health_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
info.go Remove use of global volume driver store 2018-04-17 14:07:08 -04:00
info_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
info_unix_test.go Automated migration using 2018-03-16 11:03:43 -04:00
info_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
inspect.go Move all daemon image methods into imageService 2018-02-26 16:48:29 -05:00
inspect_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
inspect_test.go Automated migration using 2018-03-16 11:03:43 -04:00
inspect_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
keys.go Add canonical import comment 2018-02-05 16:51:57 -05:00
keys_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
kill.go Add canonical import comment 2018-02-05 16:51:57 -05:00
links.go Add canonical import comment 2018-02-05 16:51:57 -05:00
list.go Remove unnecessary GetImageIDAndOS use GetImage 2018-02-26 16:49:37 -05:00
list_test.go Clean some cli-only integration tests 2018-02-19 11:19:19 +01:00
list_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
list_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
logdrivers_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
logdrivers_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
logs.go Fix race conditions in logs API 2018-05-14 15:48:32 -04:00
logs_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
metrics.go Move ImageService to new package 2018-02-26 16:49:37 -05:00
metrics_unix.go Merge pull request #35829 from cpuguy83/no_private_mount_for_plugins 2018-02-21 12:28:13 +01:00
metrics_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
monitor.go Windows: Remove servicing mode 2018-02-27 08:48:31 -08:00
mounts.go Add canonical import comment 2018-02-05 16:51:57 -05:00
names.go Add canonical import comment 2018-02-05 16:51:57 -05:00
network.go Move network operations out of container package 2018-05-10 17:16:00 -04:00
oci_linux.go Merge pull request #36991 from kolyshkin/slice-in-place 2018-05-14 13:49:47 +02:00
oci_linux_test.go daemon.getSourceMount(): fix for / mount point 2018-05-10 12:53:37 -07:00
oci_windows.go Move network operations out of container package 2018-05-10 17:16:00 -04:00
pause.go Add canonical import comment 2018-02-05 16:51:57 -05:00
prune.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
reload.go Move ImageService to new package 2018-02-26 16:49:37 -05:00
reload_test.go daemon unit tests: skip some if non-root 2018-05-22 13:12:29 -07:00
reload_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
reload_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
rename.go Add canonical import comment 2018-02-05 16:51:57 -05:00
resize.go Add canonical import comment 2018-02-05 16:51:57 -05:00
restart.go Add canonical import comment 2018-02-05 16:51:57 -05:00
seccomp_disabled.go Add canonical import comment 2018-02-05 16:51:57 -05:00
seccomp_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
seccomp_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
secrets_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
selinux_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
selinux_unsupported.go Add canonical import comment 2018-02-05 16:51:57 -05:00
start.go Move ImageService to new package 2018-02-26 16:49:37 -05:00
start_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
start_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stats.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
stats_collector.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stats_unix.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stats_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
stop.go Add canonical import comment 2018-02-05 16:51:57 -05:00
top_unix.go ContainerTop: speed up 2018-05-24 18:24:27 -07:00
top_unix_test.go Add canonical import comment 2018-02-05 16:51:57 -05:00
top_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
trustkey.go Add canonical import comment 2018-02-05 16:51:57 -05:00
trustkey_test.go Replace deprecated testutil.ErrorContains() 2018-05-21 00:13:04 +02:00
unpause.go Add canonical import comment 2018-02-05 16:51:57 -05:00
update.go Add canonical import comment 2018-02-05 16:51:57 -05:00
update_linux.go Add canonical import comment 2018-02-05 16:51:57 -05:00
update_windows.go Add canonical import comment 2018-02-05 16:51:57 -05:00
volumes.go Move mount parsing to separate package. 2018-04-19 06:35:54 -04:00
volumes_linux.go Use rslave propagation for mounts from daemon root 2018-02-07 14:27:09 -05:00
volumes_linux_test.go Use rslave propagation for mounts from daemon root 2018-02-07 14:27:09 -05:00
volumes_unit_test.go Move mount parsing to separate package. 2018-04-19 06:35:54 -04:00
volumes_unix.go Move mount parsing to separate package. 2018-04-19 06:35:54 -04:00
volumes_unix_test.go Move mount parsing to separate package. 2018-04-19 06:35:54 -04:00
volumes_windows.go Fix some linting issues 2018-05-17 19:28:27 +02:00
wait.go Switch from x/net/context -> context 2018-04-23 13:52:44 -07:00
workdir.go Add canonical import comment 2018-02-05 16:51:57 -05:00