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: #67 (while
being less risky than #68).
  • Loading branch information
mostynb committed Dec 30, 2019
1 parent d7187df commit 721c593
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 721c593

Please sign in to comment.