Skip to content

Commit d19df4f

Browse files
authored
Merge pull request #3410 from filippog/get-spec-stat-optimization
container: skip checking for files in non-existent directories.
2 parents bf2a7fe + 9a30197 commit d19df4f

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

container/common/helpers.go

+4
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ func getSpecInternal(cgroupPaths map[string]string, machineInfoFactory info.Mach
7575
dir, err := os.Stat(cgroupPathDir)
7676
if err == nil && dir.ModTime().Before(lowestTime) {
7777
lowestTime = dir.ModTime()
78+
} else if os.IsNotExist(err) {
79+
// Directory does not exist, skip checking for files within.
80+
continue
7881
}
82+
7983
// The modified time of the cgroup directory sometimes changes whenever a subcontainer is created.
8084
// eg. /docker will have creation time matching the creation of latest docker container.
8185
// Use clone_children/events as a workaround as it isn't usually modified. It is only likely changed

container/common/helpers_test.go

+37
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,40 @@ func TestRemoveNetMetrics(t *testing.T) {
247247
}
248248
}
249249
}
250+
251+
func BenchmarkGetSpecCgroupV2(b *testing.B) {
252+
root, err := os.Getwd()
253+
if err != nil {
254+
b.Fatalf("getwd: %s", err)
255+
}
256+
257+
cgroupPaths := map[string]string{
258+
"": filepath.Join(root, "test_resources/cgroup_v2/test1"),
259+
}
260+
261+
for i := 0; i < b.N; i++ {
262+
_, err := getSpecInternal(cgroupPaths, &mockInfoProvider{}, false, false, true)
263+
assert.Nil(b, err)
264+
}
265+
266+
}
267+
268+
func BenchmarkGetSpecCgroupV1(b *testing.B) {
269+
root, err := os.Getwd()
270+
if err != nil {
271+
b.Fatalf("getwd: %s", err)
272+
}
273+
274+
cgroupPaths := map[string]string{
275+
"memory": filepath.Join(root, "test_resources/cgroup_v1/test1/memory"),
276+
"cpu": filepath.Join(root, "test_resources/cgroup_v1/test1/cpu"),
277+
"cpuset": filepath.Join(root, "test_resources/cgroup_v1/test1/cpuset"),
278+
"pids": filepath.Join(root, "test_resources/cgroup_v1/test1/pids"),
279+
}
280+
281+
for i := 0; i < b.N; i++ {
282+
_, err := getSpecInternal(cgroupPaths, &mockInfoProvider{}, false, false, false)
283+
assert.Nil(b, err)
284+
}
285+
286+
}

0 commit comments

Comments
 (0)