Skip to content

Commit

Permalink
Merge pull request #2 from PeterCxy/patch-idle-workers
Browse files Browse the repository at this point in the history
fs: serve: Distribute requests only to idle workers
  • Loading branch information
chrislusf authored Aug 17, 2021
2 parents 2cac465 + 2b7fb2e commit c8e1e73
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions fs/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ func (s *Server) Serve(fs FS) error {
N := 128
jobs := make([]chan fuse.Request, N)
for i := 0; i < N; i++ {
jobs[i] = make(chan fuse.Request, N)
jobs[i] = make(chan fuse.Request)
}
worker := func(i int) {
for req := range jobs[i] {
Expand All @@ -521,7 +521,7 @@ func (s *Server) Serve(fs FS) error {
}(i)
}

var i int
job_cases := make([]reflect.SelectCase, N)
for {
req, err := s.conn.ReadRequest()
if err != nil {
Expand All @@ -531,11 +531,18 @@ func (s *Server) Serve(fs FS) error {
return err
}

jobs[i] <- req
i++
if i >= N {
i = 0
// Attempt to distribute the job to an idle worker
// If no such worker can be found, block until we can find one
// There is no point building up the job queue and reading in
// new requests when no worker is available to process them
for i, job := range jobs {
job_cases[i] = reflect.SelectCase {
Dir: reflect.SelectSend,
Chan: reflect.ValueOf(job),
Send: reflect.ValueOf(req),
}
}
reflect.Select(job_cases)
}

for i := 0; i < N; i++ {
Expand Down

0 comments on commit c8e1e73

Please sign in to comment.