Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move pool and client stats into util/stats
  • Loading branch information
tdeekens committed Apr 13, 2025
commit ab942e49f42858f639ac6ab064deb05b1ac993da
28 changes: 0 additions & 28 deletions lib/dispatcher/client-stats.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const assert = require('node:assert')
const net = require('node:net')
const http = require('node:http')
const util = require('../core/util.js')
const { ClientStats } = require('../util/stats.js')
const { channels } = require('../core/diagnostics.js')
const Request = require('../core/request.js')
const DispatcherBase = require('./dispatcher-base')
const ClientStats = require('./client-stats')
const {
InvalidArgumentError,
InformationalError,
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatcher/pool-base.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const { PoolStats } = require('../util/stats.js')
const DispatcherBase = require('./dispatcher-base')
const FixedQueue = require('./fixed-queue')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch, kStats } = require('../core/symbols')
const PoolStats = require('./pool-stats')

const kClients = Symbol('clients')
const kNeedDrain = Symbol('needDrain')
Expand Down
36 changes: 0 additions & 36 deletions lib/dispatcher/pool-stats.js

This file was deleted.

67 changes: 67 additions & 0 deletions lib/util/stats.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
'use strict'

const {
kConnected,
kPending,
kRunning,
kSize,
kFree,
kQueued
} = require('../core/symbols')

const kPool = Symbol('pool')
const kClient = Symbol('client')

class ClientStats {
constructor (client) {
this[kClient] = client
}

get connected () {
return this[kClient][kConnected]
}

get pending () {
return this[kClient][kPending]
}

get running () {
return this[kClient][kRunning]
}

get size () {
return this[kClient][kSize]
}
}

class PoolStats {
constructor (pool) {
this[kPool] = pool
}

get connected () {
return this[kPool][kConnected]
}

get free () {
return this[kPool][kFree]
}

get pending () {
return this[kPool][kPending]
}

get queued () {
return this[kPool][kQueued]
}

get running () {
return this[kPool][kRunning]
}

get size () {
return this[kPool][kSize]
}
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand this design. Instead of using getters, I would allocate new objects. This ensures that data is stable in time without having to copy them.

Copy link
Copy Markdown
Contributor Author

@tdeekens tdeekens Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be fair I also didn't but this it the current implementation and I am following it assuming it has reasoning. In that this code is just moved from elsewhere as requested by @metcoder95.

Do you wish to have this changed here or as a follow up?

Copy link
Copy Markdown
Contributor Author

@tdeekens tdeekens Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋🏼 What's the implicit agreement here? Refactor as a follow-up, not at all or here? I understand the issue that the using getters can cause inconsistent as a whole with single values. I assume we would return an object of a "stats bag" in the pool and agent. Just not sure when/where to implement it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@metcoder95 what's missing on this PR to land this? Anything expected from my side?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just applying the suggested refactor from getters to a plain object (it can also come from a class, but avoiding the getters/setters).

Copy link
Copy Markdown
Contributor Author

@tdeekens tdeekens Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. From what I understand 7ac13ff is what you had in mind?


module.exports = { ClientStats, PoolStats }
2 changes: 2 additions & 0 deletions mise.toml
Comment thread
tdeekens marked this conversation as resolved.
Outdated
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[tools]
node = "22"