@@ -132,6 +132,23 @@ func benchContainer(b *testing.B, pod *api.PodSandbox, name string) *api.Contain
132132 }
133133}
134134
135+ // benchTrackerCleanup returns a function that deletes the container's entry
136+ // from the cgroup tracker map (no BPF programs loaded in benchmarks).
137+ func benchTrackerCleanup (b * testing.B , maps * benchMaps , container * api.Container ) func () {
138+ b .Helper ()
139+
140+ cgRoot := cgroups .GetCgroupResolutionPrefix ()
141+ cgroupPath := filepath .Join (cgRoot , container .GetLinux ().GetCgroupsPath ())
142+ cgID , err := cgroups .GetCgroupIDFromPath (cgroupPath )
143+ require .NoError (b , err , "resolve cgroup ID" )
144+
145+ return func () {
146+ if err = maps .cgTracker .Delete (& cgID ); err != nil {
147+ b .Fatalf ("delete cgroup tracker entry: %v" , err )
148+ }
149+ }
150+ }
151+
135152func buildSyncFixtures (b * testing.B , numPods , containersPerPod int ) ([]* api.PodSandbox , []* api.Container ) {
136153 b .Helper ()
137154
@@ -183,11 +200,15 @@ func BenchmarkPluginStartContainer(b *testing.B) {
183200 b .StopTimer ()
184201 p := newBenchPlugin (b , maps )
185202 container := benchContainer (b , pod , fmt .Sprintf ("start-container-%d" , i ))
203+ cleanup := benchTrackerCleanup (b , maps , container )
186204 b .StartTimer ()
187205
188206 if err := p .StartContainer (ctx , pod , container ); err != nil {
189207 b .Fatalf ("StartContainer: %v" , err )
190208 }
209+
210+ b .StopTimer ()
211+ cleanup ()
191212 }
192213}
193214
@@ -201,6 +222,8 @@ func BenchmarkPluginRemoveContainer(b *testing.B) {
201222 b .StopTimer ()
202223 p := newBenchPlugin (b , maps )
203224 container := benchContainer (b , pod , fmt .Sprintf ("remove-container-%d" , i ))
225+ cleanup := benchTrackerCleanup (b , maps , container )
226+
204227 if err := p .StartContainer (ctx , pod , container ); err != nil {
205228 b .Fatalf ("seed StartContainer: %v" , err )
206229 }
@@ -209,5 +232,8 @@ func BenchmarkPluginRemoveContainer(b *testing.B) {
209232 if err := p .RemoveContainer (ctx , pod , container ); err != nil {
210233 b .Fatalf ("RemoveContainer: %v" , err )
211234 }
235+
236+ b .StopTimer ()
237+ cleanup ()
212238 }
213239}
0 commit comments