mirror of
https://github.com/docker/compose.git
synced 2025-07-21 12:44:54 +02:00
watch: increase the windows watch i/o buffer (#3620)
fixes https://github.com/tilt-dev/tilt/issues/3556
This commit is contained in:
parent
1a1d1707ed
commit
b3615d64e2
@ -3,7 +3,11 @@ package watch
|
|||||||
import (
|
import (
|
||||||
"expvar"
|
"expvar"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/tilt-dev/tilt/pkg/logger"
|
"github.com/tilt-dev/tilt/pkg/logger"
|
||||||
)
|
)
|
||||||
@ -67,3 +71,22 @@ var _ PathMatcher = EmptyMatcher{}
|
|||||||
func NewWatcher(paths []string, ignore PathMatcher, l logger.Logger) (Notify, error) {
|
func NewWatcher(paths []string, ignore PathMatcher, l logger.Logger) (Notify, error) {
|
||||||
return newWatcher(paths, ignore, l)
|
return newWatcher(paths, ignore, l)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const WindowsBufferSizeEnvVar = "TILT_WATCH_WINDOWS_BUFFER_SIZE"
|
||||||
|
|
||||||
|
const defaultBufferSize int = 65536
|
||||||
|
|
||||||
|
func DesiredWindowsBufferSize() int {
|
||||||
|
envVar := os.Getenv(WindowsBufferSizeEnvVar)
|
||||||
|
if envVar != "" {
|
||||||
|
size, err := strconv.Atoi(envVar)
|
||||||
|
if err != nil {
|
||||||
|
return size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultBufferSize
|
||||||
|
}
|
||||||
|
|
||||||
|
func IsWindowsShortReadError(err error) bool {
|
||||||
|
return runtime.GOOS == "windows" && err != nil && strings.Contains(err.Error(), "short read")
|
||||||
|
}
|
||||||
|
@ -136,6 +136,12 @@ func (d *naiveNotify) Errors() chan error {
|
|||||||
func (d *naiveNotify) loop() {
|
func (d *naiveNotify) loop() {
|
||||||
defer close(d.wrappedEvents)
|
defer close(d.wrappedEvents)
|
||||||
for e := range d.events {
|
for e := range d.events {
|
||||||
|
// The Windows fsnotify event stream sometimes gets events with empty names
|
||||||
|
// that are also sent to the error stream. Hmmmm...
|
||||||
|
if e.Name == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if e.Op&fsnotify.Create != fsnotify.Create {
|
if e.Op&fsnotify.Create != fsnotify.Create {
|
||||||
if d.shouldNotify(e.Name) {
|
if d.shouldNotify(e.Name) {
|
||||||
d.wrappedEvents <- FileEvent{e.Name}
|
d.wrappedEvents <- FileEvent{e.Name}
|
||||||
@ -251,6 +257,7 @@ func newWatcher(paths []string, ignore PathMatcher, l logger.Logger) (*naiveNoti
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
MaybeIncreaseBufferSize(fsw)
|
||||||
|
|
||||||
err = fsw.SetRecursive()
|
err = fsw.SetRecursive()
|
||||||
isWatcherRecursive := err == nil
|
isWatcherRecursive := err == nil
|
||||||
|
9
pkg/watch/watcher_nonwin.go
Normal file
9
pkg/watch/watcher_nonwin.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package watch
|
||||||
|
|
||||||
|
import "github.com/tilt-dev/fsnotify"
|
||||||
|
|
||||||
|
func MaybeIncreaseBufferSize(w *fsnotify.Watcher) {
|
||||||
|
// Not needed on non-windows
|
||||||
|
}
|
19
pkg/watch/watcher_windows.go
Normal file
19
pkg/watch/watcher_windows.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package watch
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/tilt-dev/fsnotify"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO(nick): I think the ideal API would be to automatically increase the
|
||||||
|
// size of the buffer when we exceed capacity. But this gets messy,
|
||||||
|
// because each time we get a short read error, we need to invalidate
|
||||||
|
// everything we know about the currently changed files. So for now,
|
||||||
|
// we just provide a way for people to increase the buffer ourselves.
|
||||||
|
//
|
||||||
|
// It might also pay to be clever about sizing the buffer
|
||||||
|
// relative the number of files in the directory we're watching.
|
||||||
|
func MaybeIncreaseBufferSize(w *fsnotify.Watcher) {
|
||||||
|
w.SetBufferSize(DesiredWindowsBufferSize())
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user