mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-08-01 15:03:05 +08:00
revert to same implementation as before
This reverts commit 7e8edc3c4a
.
This commit is contained in:
parent
67e019d54b
commit
bdf2ddddfd
@ -77,7 +77,7 @@ type WFS struct {
|
|||||||
signature int32
|
signature int32
|
||||||
|
|
||||||
// throttle writers
|
// throttle writers
|
||||||
concurrentWriters *util.LimitedOutOfOrderProcessor
|
concurrentWriters *util.LimitedConcurrentExecutor
|
||||||
Server *fs.Server
|
Server *fs.Server
|
||||||
}
|
}
|
||||||
type statsCache struct {
|
type statsCache struct {
|
||||||
@ -135,7 +135,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {
|
|||||||
wfs.fsNodeCache = newFsCache(wfs.root)
|
wfs.fsNodeCache = newFsCache(wfs.root)
|
||||||
|
|
||||||
if wfs.option.ConcurrentWriters > 0 {
|
if wfs.option.ConcurrentWriters > 0 {
|
||||||
wfs.concurrentWriters = util.NewLimitedOutOfOrderProcessor(int32(wfs.option.ConcurrentWriters))
|
wfs.concurrentWriters = util.NewLimitedConcurrentExecutor(wfs.option.ConcurrentWriters)
|
||||||
}
|
}
|
||||||
|
|
||||||
return wfs
|
return wfs
|
||||||
|
@ -7,6 +7,46 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// initial version comes from https://github.com/korovkin/limiter/blob/master/limiter.go
|
||||||
|
|
||||||
|
// LimitedConcurrentExecutor object
|
||||||
|
type LimitedConcurrentExecutor struct {
|
||||||
|
limit int
|
||||||
|
tokenChan chan int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewLimitedConcurrentExecutor(limit int) *LimitedConcurrentExecutor {
|
||||||
|
|
||||||
|
// allocate a limiter instance
|
||||||
|
c := &LimitedConcurrentExecutor{
|
||||||
|
limit: limit,
|
||||||
|
tokenChan: make(chan int, limit),
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate the tokenChan:
|
||||||
|
for i := 0; i < c.limit; i++ {
|
||||||
|
c.tokenChan <- i
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute adds a function to the execution queue.
|
||||||
|
// if num of go routines allocated by this instance is < limit
|
||||||
|
// launch a new go routine to execute job
|
||||||
|
// else wait until a go routine becomes available
|
||||||
|
func (c *LimitedConcurrentExecutor) Execute(job func()) {
|
||||||
|
token := <-c.tokenChan
|
||||||
|
go func() {
|
||||||
|
defer func() {
|
||||||
|
c.tokenChan <- token
|
||||||
|
}()
|
||||||
|
// run the job
|
||||||
|
job()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
// a different implementation, but somehow more "conservative"
|
||||||
type OperationRequest func()
|
type OperationRequest func()
|
||||||
|
|
||||||
type LimitedOutOfOrderProcessor struct {
|
type LimitedOutOfOrderProcessor struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user