Skip to content

Commit

Permalink
don't os.File.Sync() on mac CAS items
Browse files Browse the repository at this point in the history
os.File.Sync() was inneffective on mac in go prior to 1.12. In 1.12 onwards
it is effective, but slow: golang/go#26650

This change disables Sync for CAS uploads on mac, because we can (potentially)
verify this later. Let's see if this helps performance on mac: buchgr#67 (while
being less risky than buchgr#68).
  • Loading branch information
mostynb committed Jan 1, 2020
1 parent 8f26fd6 commit 12603b2
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cache/disk/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"sort"
"sync"

"github.com/buchgr/bazel-remote/cache"
"github.com/djherbis/atime"
)

const isMac = runtime.GOOS == "darwin"

// lruItem is the type of the values stored in SizedLRU to keep track of items.
// It implements the SizedItem interface.
type lruItem struct {
Expand Down Expand Up @@ -236,8 +239,11 @@ func (c *diskCache) Put(kind cache.EntryKind, hash string, expectedSize int64, r
}
}

if err := f.Sync(); err != nil {
return err
shouldSync := !isMac || kind != cache.CAS
if shouldSync {
if err := f.Sync(); err != nil {
return err
}
}

if err := f.Close(); err != nil {
Expand Down

0 comments on commit 12603b2

Please sign in to comment.