Browse Source

Merge pull request #1002 from AudriusButkevicius/routine-cfg

Make copiers, pullers and finishers configurable
Jakob Borg 11 years ago
parent
commit
16d9944dbb
3 changed files with 18 additions and 15 deletions
  1. 3 0
      internal/config/config.go
  2. 3 0
      internal/model/model.go
  3. 12 15
      internal/model/puller.go

+ 3 - 0
internal/config/config.go

@@ -58,6 +58,9 @@ type FolderConfiguration struct {
 	IgnorePerms     bool                        `xml:"ignorePerms,attr"`
 	IgnorePerms     bool                        `xml:"ignorePerms,attr"`
 	Versioning      VersioningConfiguration     `xml:"versioning"`
 	Versioning      VersioningConfiguration     `xml:"versioning"`
 	LenientMtimes   bool                        `xml:"lenientMtimes"`
 	LenientMtimes   bool                        `xml:"lenientMtimes"`
+	Copiers         int                         `xml:"copiers" default:"1"`   // This defines how many files are handled concurrently.
+	Pullers         int                         `xml:"pullers" default:"16"`  // Defines how many blocks are fetched at the same time, possibly between separate copier routines.
+	Finishers       int                         `xml:"finishers" default:"1"` // Most of the time, should be equal to the number of copiers. These are CPU bound due to hashing.
 
 
 	Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
 	Invalid string `xml:"-"` // Set at runtime when there is an error, not saved
 
 

+ 3 - 0
internal/model/model.go

@@ -178,6 +178,9 @@ func (m *Model) StartFolderRW(folder string) {
 		model:         m,
 		model:         m,
 		ignorePerms:   cfg.IgnorePerms,
 		ignorePerms:   cfg.IgnorePerms,
 		lenientMtimes: cfg.LenientMtimes,
 		lenientMtimes: cfg.LenientMtimes,
+		copiers:       cfg.Copiers,
+		pullers:       cfg.Pullers,
+		finishers:     cfg.Finishers,
 	}
 	}
 	m.folderRunners[folder] = p
 	m.folderRunners[folder] = p
 	m.fmut.Unlock()
 	m.fmut.Unlock()

+ 12 - 15
internal/model/puller.go

@@ -40,12 +40,9 @@ import (
 // TODO: Stop on errors
 // TODO: Stop on errors
 
 
 const (
 const (
-	copiersPerFolder   = 1
-	pullersPerFolder   = 16
-	finishersPerFolder = 2
-	pauseIntv          = 60 * time.Second
-	nextPullIntv       = 10 * time.Second
-	checkPullIntv      = 1 * time.Second
+	pauseIntv     = 60 * time.Second
+	nextPullIntv  = 10 * time.Second
+	checkPullIntv = 1 * time.Second
 )
 )
 
 
 // A pullBlockState is passed to the puller routine for each block that needs
 // A pullBlockState is passed to the puller routine for each block that needs
@@ -76,6 +73,9 @@ type Puller struct {
 	versioner     versioner.Versioner
 	versioner     versioner.Versioner
 	ignorePerms   bool
 	ignorePerms   bool
 	lenientMtimes bool
 	lenientMtimes bool
+	copiers       int
+	pullers       int
+	finishers     int
 }
 }
 
 
 // Serve will run scans and pulls. It will return when Stop()ed or on a
 // Serve will run scans and pulls. It will return when Stop()ed or on a
@@ -153,7 +153,7 @@ loop:
 					checksum = true
 					checksum = true
 				}
 				}
 
 
-				changed := p.pullerIteration(copiersPerFolder, pullersPerFolder, finishersPerFolder, checksum)
+				changed := p.pullerIteration(checksum)
 				if debug {
 				if debug {
 					l.Debugln(p, "changed", changed)
 					l.Debugln(p, "changed", changed)
 				}
 				}
@@ -240,11 +240,8 @@ func (p *Puller) String() string {
 // pullerIteration runs a single puller iteration for the given folder and
 // pullerIteration runs a single puller iteration for the given folder and
 // returns the number items that should have been synced (even those that
 // returns the number items that should have been synced (even those that
 // might have failed). One puller iteration handles all files currently
 // might have failed). One puller iteration handles all files currently
-// flagged as needed in the folder. The specified number of copier, puller and
-// finisher routines are used. It's seldom efficient to use more than one
-// copier routine, while multiple pullers are essential and multiple finishers
-// may be useful (they are primarily CPU bound due to hashing).
-func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int, checksum bool) int {
+// flagged as needed in the folder.
+func (p *Puller) pullerIteration(checksum bool) int {
 	pullChan := make(chan pullBlockState)
 	pullChan := make(chan pullBlockState)
 	copyChan := make(chan copyBlocksState)
 	copyChan := make(chan copyBlocksState)
 	finisherChan := make(chan *sharedPullerState)
 	finisherChan := make(chan *sharedPullerState)
@@ -253,7 +250,7 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int, checksum bo
 	var pullWg sync.WaitGroup
 	var pullWg sync.WaitGroup
 	var doneWg sync.WaitGroup
 	var doneWg sync.WaitGroup
 
 
-	for i := 0; i < ncopiers; i++ {
+	for i := 0; i < p.copiers; i++ {
 		copyWg.Add(1)
 		copyWg.Add(1)
 		go func() {
 		go func() {
 			// copierRoutine finishes when copyChan is closed
 			// copierRoutine finishes when copyChan is closed
@@ -262,7 +259,7 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int, checksum bo
 		}()
 		}()
 	}
 	}
 
 
-	for i := 0; i < npullers; i++ {
+	for i := 0; i < p.pullers; i++ {
 		pullWg.Add(1)
 		pullWg.Add(1)
 		go func() {
 		go func() {
 			// pullerRoutine finishes when pullChan is closed
 			// pullerRoutine finishes when pullChan is closed
@@ -271,7 +268,7 @@ func (p *Puller) pullerIteration(ncopiers, npullers, nfinishers int, checksum bo
 		}()
 		}()
 	}
 	}
 
 
-	for i := 0; i < nfinishers; i++ {
+	for i := 0; i < p.finishers; i++ {
 		doneWg.Add(1)
 		doneWg.Add(1)
 		// finisherRoutine finishes when finisherChan is closed
 		// finisherRoutine finishes when finisherChan is closed
 		go func() {
 		go func() {