Skip to content

Commit

Permalink
perf(cu): combine gauges into single gauge with multiple label sets f…
Browse files Browse the repository at this point in the history
…or finer resolution
  • Loading branch information
TillaTheHun0 committed Aug 6, 2024
1 parent b0f543f commit b158429
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
64 changes: 30 additions & 34 deletions servers/cu/src/domain/api/perf.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
import { path, zipObj } from 'ramda'
import { zipObj } from 'ramda'

export function statsWith ({ loadWorkerStats, loadMemoryUsage, loadProcessCacheUsage, gauge }) {
const workerStatGaugesWith = ({ type }) => {
const totalWorkers = path([type, 'totalWorkers'])
const pendingTasks = path([type, 'pendingTasks'])
const activeTasks = path([type, 'activeTasks'])
gauge({
name: 'worker_total',
description: 'The total amount of workers currently spun-up on the Compute Unit',
labelNames: ['worker_type'],
collect: (set) => Promise.resolve()
.then(loadWorkerStats)
.then(({ primary, dryRun }) => {
set(primary.totalWorkers + dryRun.totalWorkers)
set(primary.totalWorkers, { worker_type: 'primary' })
set(dryRun.totalWorkers, { worker_type: 'dry-run' })
})
})

// total workers
gauge({
name: `${type.toLowerCase()}_worker_total`,
description: `The total amount of ${type} workers currently spun-up on the Compute Unit`,
collect: () => Promise.resolve()
.then(loadWorkerStats)
.then(totalWorkers)
})
gauge({
name: 'worker_tasks_total',
description: 'The total amount of worker tasks on the Compute Unit',
labelNames: ['worker_type', 'task_type'],
collect: (set) => Promise.resolve()
.then(loadWorkerStats)
.then(({ primary, dryRun }) => {
// pending
set(primary.pendingTasks + dryRun.pendingTasks)
set(primary.pendingTasks, { worker_type: 'primary', task_type: 'pending' })
set(dryRun.pendingTasks, { worker_type: 'dry-run', task_type: 'pending' })

// pending tasks
gauge({
name: `${type.toLowerCase()}_worker_pending_tasks_total`,
description: `The total amount of ${type} pending tasks on the Compute Unit`,
collect: () => Promise.resolve()
.then(loadWorkerStats)
.then(pendingTasks)
})

// active tasks
gauge({
name: `${type.toLowerCase()}_worker_active_tasks_total`,
description: `The total amount of ${type} active tasks on the Compute Unit`,
collect: () => Promise.resolve()
.then(loadWorkerStats)
.then(activeTasks)
})
}

workerStatGaugesWith({ type: 'dryRun' })
workerStatGaugesWith({ type: 'primary' })
// active
set(primary.activeTasks + dryRun.activeTasks)
set(primary.activeTasks, { worker_type: 'primary', task_type: 'active' })
set(dryRun.activeTasks, { worker_type: 'dry-run', task_type: 'active' })
})
})

return async () => Promise.all([
loadWorkerStats(),
Expand Down
7 changes: 6 additions & 1 deletion servers/cu/src/domain/client/ao-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,12 @@ export async function createProcessMemoryCache ({ MAX_SIZE, TTL, logger, gauge,
gauge({
name: 'ao_process_total',
description: 'The total amount of ao Processes cached on the Compute Unit',
collect: () => lru.size + drainedToFile.size
labelNames: ['cache_type'],
collect: (set) => {
set(lru.size + drainedToFile.size)
set(lru.size, { cache_type: 'memory' })
set(drainedToFile.size, { cache_type: 'file' })
}
})

/**
Expand Down
15 changes: 11 additions & 4 deletions servers/cu/src/domain/client/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,19 @@ export const gaugeWith = ({ prefix = 'ao_cu' } = {}) => {
* We abstract the use of 'this'
* to the collect function here.
*
* This way, the client may provide a function
* that simply returns the collected value to set,
* which will this call set here
* This way, the client may invoke set without
* the common "gotchas" w.r.t 'this'.
*
* Also makes the set api match the inc/dec/set api
* below, where value _then_ labels are passed
*/
...(collect
? { collect: async function () { this.set(await collect()) } }
? {
collect: async function () {
const set = this.set.bind(this)
await collect((value, labels) => set(labels || {}, value))
}
}
: {}
),
labelNames,
Expand Down

0 comments on commit b158429

Please sign in to comment.