Skip to content

Commit 79d89ad

Browse files
leokondrashovCuriousGeorgiy
authored andcommitted
Don't create new networks if we have enough
Signed-off-by: Leonid Kondrashov <[email protected]>
1 parent 3a2aeda commit 79d89ad

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

networking/networkManager.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,20 @@ func (mgr *NetworkManager) addNetConfig() {
127127

128128
// allocNetConfig allocates a new network config from the pool to a function instance identified by funcID
129129
func (mgr *NetworkManager) allocNetConfig(funcID string) *NetworkConfig {
130-
// Add netconfig to pool to keep pool to configured size
131-
go mgr.addNetConfig()
132-
133130
logger := log.WithFields(log.Fields{"funcID": funcID})
134131
logger.Debug("Allocating a new network config from network pool to function instance")
135132

136-
// Pop a network config from the pool and allocate it to the function instance
137133
mgr.poolCond.L.Lock()
134+
// Add netconfig to pool to keep pool to configured size
135+
if len(mgr.networkPool) <= mgr.poolSize {
136+
go mgr.addNetConfig()
137+
}
138138
for len(mgr.networkPool) == 0 {
139139
// Wait until a new network config has been created
140140
mgr.poolCond.Wait()
141141
}
142142

143+
// Pop a network config from the pool and allocate it to the function instance
143144
config := mgr.networkPool[len(mgr.networkPool)-1]
144145
mgr.networkPool = mgr.networkPool[:len(mgr.networkPool)-1]
145146
mgr.poolCond.L.Unlock()

0 commit comments

Comments
 (0)