Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve periodic reload #502

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/load_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func (rt *Router) listenForContentStoreUpdates(ctx context.Context) error {
}

func (rt *Router) PeriodicCSRouteUpdates() {
tick := time.Tick(time.Minute)
tick := time.Tick(5 * time.Second)
for range tick {
if time.Since(rt.csLastReloadTime) > time.Minute {
if time.Since(rt.csLastAttemptReloadTime) > time.Minute {
// This is a non-blocking send, if there is already a notification to reload we don't need to send another one
select {
case rt.CsReloadChan <- true:
Expand Down Expand Up @@ -187,6 +187,8 @@ func (rt *Router) reloadCsRoutes(pool PgxIface) {
timer.ObserveDuration()
}()

rt.csLastAttemptReloadTime = time.Now()

logInfo("router: reloading routes from content store")
newmux := triemux.NewMux()

Expand All @@ -204,5 +206,4 @@ func (rt *Router) reloadCsRoutes(pool PgxIface) {

logInfo(fmt.Sprintf("router: reloaded %d routes from content store", routeCount))
routesCountMetric.WithLabelValues("content-store").Set(float64(routeCount))

}
24 changes: 12 additions & 12 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ const (
// come from, Route and Backend should not contain bson fields.
// MongoReplicaSet, MongoReplicaSetMember etc. should move out of this module.
type Router struct {
backends map[string]http.Handler
mux *triemux.Mux
csMux *triemux.Mux
lock sync.RWMutex
mongoReadToOptime bson.MongoTimestamp
logger logger.Logger
opts Options
ReloadChan chan bool
CsReloadChan chan bool
csMuxSampleRate float64
csLastReloadTime time.Time
pool *pgxpool.Pool
backends map[string]http.Handler
mux *triemux.Mux
csMux *triemux.Mux
lock sync.RWMutex
mongoReadToOptime bson.MongoTimestamp
logger logger.Logger
opts Options
ReloadChan chan bool
CsReloadChan chan bool
csMuxSampleRate float64
csLastAttemptReloadTime time.Time
pool *pgxpool.Pool
}

type Options struct {
Expand Down
Loading