This commit is contained in:
@@ -34,6 +34,9 @@ import (
|
||||
"github.com/syncthing/syncthing/lib/watchaggregator"
|
||||
)
|
||||
|
||||
// Arbitrary limit that triggers a warning on kqueue systems
|
||||
const kqueueItemCountThreshold = 10000
|
||||
|
||||
type folder struct {
|
||||
stateTracker
|
||||
config.FolderConfiguration
|
||||
@@ -81,6 +84,8 @@ type folder struct {
|
||||
|
||||
puller puller
|
||||
versioner versioner.Versioner
|
||||
|
||||
warnedKqueue bool
|
||||
}
|
||||
|
||||
type syncRequest struct {
|
||||
@@ -980,6 +985,19 @@ func (f *folder) monitorWatch(ctx context.Context) {
|
||||
warnedOutside := false
|
||||
var lastWatch time.Time
|
||||
pause := time.Minute
|
||||
// Subscribe to folder summaries only on kqueue systems, to warn about potential high resource usage
|
||||
var summarySub events.Subscription
|
||||
var summaryChan <-chan events.Event
|
||||
if fs.WatchKqueue && !f.warnedKqueue {
|
||||
summarySub = f.evLogger.Subscribe(events.FolderCompletion)
|
||||
summaryChan = summarySub.C()
|
||||
}
|
||||
defer func() {
|
||||
aggrCancel() // aggrCancel might e re-assigned -> call within closure
|
||||
if summaryChan != nil {
|
||||
summarySub.Unsubscribe()
|
||||
}
|
||||
}()
|
||||
for {
|
||||
select {
|
||||
case <-failTimer.C:
|
||||
@@ -1024,6 +1042,15 @@ func (f *folder) monitorWatch(ctx context.Context) {
|
||||
aggrCancel()
|
||||
errChan = nil
|
||||
aggrCtx, aggrCancel = context.WithCancel(ctx)
|
||||
case ev := <-summaryChan:
|
||||
if data, ok := ev.Data.(FolderSummaryEventData); !ok {
|
||||
f.evLogger.Log(events.Failure, "Unexpected type of folder-summary event in folder.monitorWatch")
|
||||
} else if data.Summary.LocalTotalItems > kqueueItemCountThreshold {
|
||||
f.warnedKqueue = true
|
||||
summarySub.Unsubscribe()
|
||||
summaryChan = nil
|
||||
l.Warnf("Filesystem watching (kqueue) is enabled on %v with a lot of files/directories, and that requires a lot of resources and might slow down your system significantly", f.Description())
|
||||
}
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user