Performance testing Load function

This commit is contained in:
Matthew Holt
2019-03-26 19:42:52 -06:00
parent 86e2d1b0a4
commit a8dc73b4d9
7 changed files with 132 additions and 12 deletions

View File

@ -3,10 +3,16 @@ package caddy2
import (
"encoding/json"
"fmt"
"log"
"runtime/debug"
"strings"
"sync"
"time"
)
var currentCfg *Config
var currentCfgMu sync.Mutex
// Start runs Caddy with the given config.
func Start(cfg Config) error {
cfg.runners = make(map[string]Runner)
@ -26,16 +32,33 @@ func Start(cfg Config) error {
for name, r := range cfg.runners {
err := r.Run()
if err != nil {
// TODO: If any one has an error, stop the others
return fmt.Errorf("%s module: %v", name, err)
}
}
currentCfgMu.Lock()
if currentCfg != nil {
for _, r := range cfg.runners {
err := r.Cancel()
if err != nil {
log.Println(err)
}
}
}
currentCfg = &cfg
currentCfgMu.Unlock()
// TODO: debugging memory leak...
debug.FreeOSMemory()
return nil
}
// Runner is a thing that Caddy runs.
type Runner interface {
Run() error
Cancel() error
}
// Config represents a Caddy configuration.