Skip to content

Commit

Permalink
Log db and background queue stats (bluesky-social#908)
Browse files Browse the repository at this point in the history
* Log db stats

* Log background queue stats
  • Loading branch information
devinivy authored Apr 26, 2023
1 parent df7cbae commit 4b70b80
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion packages/pds/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import API, { health } from './api'
import Database from './db'
import { ServerAuth } from './auth'
import * as error from './error'
import { loggerMiddleware } from './logger'
import { dbLogger, loggerMiddleware } from './logger'
import { ServerConfig } from './config'
import { ServerMailer } from './mailer'
import { createServer } from './lexicon'
Expand Down Expand Up @@ -48,6 +48,7 @@ export class PDS {
public app: express.Application
public server?: http.Server
private terminator?: HttpTerminator
private dbStatsInterval?: NodeJS.Timer

constructor(opts: {
ctx: AppContext
Expand Down Expand Up @@ -196,6 +197,27 @@ export class PDS {
}

async start(): Promise<http.Server> {
const { db, backgroundQueue } = this.ctx
if (db.cfg.dialect === 'pg') {
const { pool } = db.cfg
this.dbStatsInterval = setInterval(() => {
dbLogger.info(
{
idleCount: pool.idleCount,
totalCount: pool.totalCount,
waitingCount: pool.waitingCount,
},
'db pool stats',
)
dbLogger.info(
{
runningCount: backgroundQueue.queue.pending,
waitingCount: backgroundQueue.queue.size,
},
'background queue stats',
)
}, 10000)
}
this.appViewIndexer.start()
await this.ctx.sequencer.start()
await this.ctx.db.startListeningToChannels()
Expand All @@ -212,6 +234,7 @@ export class PDS {
await this.terminator?.terminate()
await this.ctx.backgroundQueue.destroy()
await this.ctx.db.close()
clearInterval(this.dbStatsInterval)
}
}

Expand Down

0 comments on commit 4b70b80

Please sign in to comment.