mirror of
https://github.com/openshift/installer.git
synced 2026-02-07 03:47:13 +01:00
With this change: * listing of container object is no longer limited to 50, but left to the default (which is 10000 on a standard Swift configuration); * the object deletion calls are issued in concurrent goroutines rather than serially, giving Swift a chance to work them in parallel. The limit is set to 10 concurrent goroutines. The goal of this change is to tackle waiting times on OCP destroy on clusters with massive amounts of data stored in OpenStack object storage.
36 lines
715 B
Go
36 lines
715 B
Go
package openstack
|
|
|
|
import "sync"
|
|
|
|
type semaphore struct {
|
|
semC chan struct{}
|
|
wg sync.WaitGroup
|
|
}
|
|
|
|
// newSemaphore returns a semaphore. A semaphore runs at most maxConcurrency
|
|
// functions concurrently.
|
|
func newSemaphore(maxConcurrency int) *semaphore {
|
|
return &semaphore{
|
|
semC: make(chan struct{}, maxConcurrency),
|
|
}
|
|
}
|
|
|
|
// Add enqueues the function f to be run in a separate goroutine as soon as
|
|
// there is a free slot. Add returns immediately.
|
|
func (s *semaphore) Add(f func()) {
|
|
s.wg.Add(1)
|
|
go func() {
|
|
s.semC <- struct{}{}
|
|
defer func() {
|
|
<-s.semC
|
|
s.wg.Done()
|
|
}()
|
|
f()
|
|
}()
|
|
}
|
|
|
|
// Wait returns when the queue is empty and no function is running.
|
|
func (s *semaphore) Wait() {
|
|
s.wg.Wait()
|
|
}
|