@@ -131,9 +131,18 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
131131 // remove from resent tracking - it may get resent again, or get processed
132132 resent = None
133133 }
134+ val kind = r.action.exec.kind
135+ val memory = r.action.limits.memory.megabytes.MB
136+
137+ val prewarmedPoolForOtherKind = prewarmedPool.filter { info =>
138+ info match {
139+ case (_, PreWarmedData (_, `kind`, `memory`, _, _)) => false
140+ case _ => true
141+ }
142+ }
134143 val createdContainer =
135144 // Is there enough space on the invoker for this action to be executed.
136- if (hasPoolSpaceFor(busyPool, r.action.limits. memory.megabytes. MB )) {
145+ if (hasPoolSpaceFor(busyPool ++ prewarmedPoolForOtherKind, memory)) {
137146 // Schedule a job to a warm container
138147 ContainerPool
139148 .schedule(r.action, r.msg.user.namespace.name, freePool)
@@ -142,12 +151,12 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
142151 // There was no warm/warming/warmingCold container. Try to take a prewarm container or a cold container.
143152
144153 // Is there enough space to create a new container or do other containers have to be removed?
145- if (hasPoolSpaceFor(busyPool ++ freePool, r.action.limits. memory.megabytes. MB )) {
154+ if (hasPoolSpaceFor(busyPool ++ freePool ++ prewarmedPoolForOtherKind, memory)) {
146155 takePrewarmContainer(r.action)
147156 .map(container => (container, " prewarmed" ))
148157 .orElse {
149- val container = Some (createContainer(r.action.limits. memory.megabytes. MB ), " cold" )
150- incrementColdStartCount(r.action.exec. kind, r.action.limits. memory.megabytes. MB )
158+ val container = Some (createContainer(memory), " cold" )
159+ incrementColdStartCount(kind, memory)
151160 container
152161 }
153162 } else None )
@@ -164,8 +173,8 @@ class ContainerPool(childFactory: ActorRefFactory => ActorRef,
164173 takePrewarmContainer(r.action)
165174 .map(container => (container, " recreatedPrewarm" ))
166175 .getOrElse {
167- val container = (createContainer(r.action.limits. memory.megabytes. MB ), " recreated" )
168- incrementColdStartCount(r.action.exec. kind, r.action.limits. memory.megabytes. MB )
176+ val container = (createContainer(memory), " recreated" )
177+ incrementColdStartCount(kind, memory)
169178 container
170179 }))
171180
0 commit comments