Add printing of number of goroutines to assist with performance improvements
This commit is contained in:
parent
3e5ed2c10a
commit
7146d1a883
@ -1,6 +1,8 @@
|
|||||||
package background
|
package background
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.fjla.uk/owlboard/timetable-mgr/cif"
|
"git.fjla.uk/owlboard/timetable-mgr/cif"
|
||||||
@ -9,11 +11,16 @@ import (
|
|||||||
"git.fjla.uk/owlboard/timetable-mgr/log"
|
"git.fjla.uk/owlboard/timetable-mgr/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
const frequency = 600 * time.Hour // Figure out a sensible frequency!
|
const frequency = 2 * time.Hour // Figure out a sensible frequency!
|
||||||
|
|
||||||
// Starts a background ticker to run background tasks. Uses the frequency configured in the background/ticker.go file
|
// Starts a background ticker to run background tasks. Uses the frequency configured in the background/ticker.go file
|
||||||
func InitTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
|
func InitTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
|
||||||
go runTicker(cfg, stop)
|
go runTicker(cfg, stop)
|
||||||
|
|
||||||
|
// Run goroutine logging ticker if runtime set to debug
|
||||||
|
if helpers.Runtime == "debug" {
|
||||||
|
go goroutineTicker(stop)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Runs the ticker and handles tick events
|
// Runs the ticker and handles tick events
|
||||||
@ -32,3 +39,18 @@ func runTicker(cfg *helpers.Configuration, stop <-chan struct{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Starts a ticker that logs how many goroutines are running every two seconds
|
||||||
|
func goroutineTicker(stop <-chan struct{}) {
|
||||||
|
log.Msg.Warn("Starting goroutine Tracker ticker - DEBUG USE ONLY")
|
||||||
|
ticker := time.NewTicker(1000 * time.Millisecond)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-stop:
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
fmt.Printf("Number of goroutines running: %d\n", runtime.NumGoroutine())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -32,7 +32,7 @@ func runCifFullDownload(cfg *helpers.Configuration) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drop timetable collection
|
// Drop timetable collection
|
||||||
dbAccess.DropCollection(dbAccess.TimetableCollection)
|
dbAccess.DropCollection(dbAccess.TimetableCollection) // I should edit this to prevent removal of VSTP entries in the database.
|
||||||
|
|
||||||
// Process CIF file
|
// Process CIF file
|
||||||
err = processParsedCif(parsed)
|
err = processParsedCif(parsed)
|
||||||
|
@ -19,7 +19,7 @@ func init() {
|
|||||||
|
|
||||||
// Determine the log level based on the runtime mode
|
// Determine the log level based on the runtime mode
|
||||||
logLevel := zapcore.DebugLevel
|
logLevel := zapcore.DebugLevel
|
||||||
if helpers.Runtime == "production" {
|
if helpers.Runtime != "debug" {
|
||||||
logLevel = zapcore.InfoLevel
|
logLevel = zapcore.InfoLevel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
main.go
11
main.go
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"git.fjla.uk/owlboard/timetable-mgr/background"
|
"git.fjla.uk/owlboard/timetable-mgr/background"
|
||||||
"git.fjla.uk/owlboard/timetable-mgr/cif"
|
"git.fjla.uk/owlboard/timetable-mgr/cif"
|
||||||
|
"git.fjla.uk/owlboard/timetable-mgr/corpus"
|
||||||
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
|
"git.fjla.uk/owlboard/timetable-mgr/dbAccess"
|
||||||
"git.fjla.uk/owlboard/timetable-mgr/helpers"
|
"git.fjla.uk/owlboard/timetable-mgr/helpers"
|
||||||
"git.fjla.uk/owlboard/timetable-mgr/log"
|
"git.fjla.uk/owlboard/timetable-mgr/log"
|
||||||
@ -34,14 +35,16 @@ func main() {
|
|||||||
// Initialise a `stop` channel to signal goroutines to cleanup
|
// Initialise a `stop` channel to signal goroutines to cleanup
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
|
|
||||||
// Handle signals from the OS
|
|
||||||
go handleSignals(cfg, stop)
|
|
||||||
|
|
||||||
// Start CIF Task Ticker
|
// Start CIF Task Ticker
|
||||||
background.InitTicker(cfg, stop)
|
background.InitTicker(cfg, stop)
|
||||||
|
|
||||||
// Test CORPUS Fetching
|
// Handle signals from the OS
|
||||||
|
go handleSignals(cfg, stop)
|
||||||
|
|
||||||
|
// Manually call CIF and CORPUS checks to ensure that they are
|
||||||
|
// not delayed until the first ticker event.
|
||||||
go cif.CheckCif(cfg)
|
go cif.CheckCif(cfg)
|
||||||
|
go corpus.CheckCorpus(cfg)
|
||||||
|
|
||||||
if cfg.VstpOn {
|
if cfg.VstpOn {
|
||||||
messaging.StompInit(cfg)
|
messaging.StompInit(cfg)
|
||||||
|
Loading…
Reference in New Issue
Block a user