@nxtedition/lib 23.9.15 → 23.9.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/app.js +19 -9
  2. package/package.json +1 -1
package/app.js CHANGED
@@ -1009,20 +1009,28 @@ export function makeApp(appConfig, onTerminate) {
1009
1009
  const utilsBC = new BroadcastChannel('nxt:utils')
1010
1010
  utilsBC.unref()
1011
1011
 
1012
+ function writeHeapSnapshot() {
1013
+ const snapshotPath = `${os.tmpdir()}/heap-${Date.now()}-${serviceName}-${serviceModule}-${serviceInstanceId}-${serviceWorkerId}.heapsnapshot`
1014
+ v8.writeHeapSnapshot(snapshotPath)
1015
+ logger.info({ snapshotPath }, 'heap snapshot')
1016
+ }
1017
+
1018
+ function gc() {
1019
+ if (global.gc) {
1020
+ global.gc()
1021
+ logger.debug('gc')
1022
+ } else {
1023
+ logger.warn('gc not available')
1024
+ }
1025
+ }
1026
+
1012
1027
  utilsBC.onmessage = ({ data }) => {
1013
1028
  const { type } = data
1014
1029
  try {
1015
1030
  if (type === 'utils:gc') {
1016
- if (global.gc) {
1017
- global.gc()
1018
- logger.debug('gc')
1019
- } else {
1020
- logger.warn('gc not available')
1021
- }
1031
+ gc()
1022
1032
  } else if (type === 'utils:writeHeapSnapshot') {
1023
- const snapshotPath = `${os.tmpdir()}/heap-${Date.now()}-${serviceName}-${serviceModule}-${serviceInstanceId}-${serviceWorkerId}.heapsnapshot`
1024
- v8.writeHeapSnapshot(snapshotPath)
1025
- logger.info({ snapshotPath }, 'heap snapshot')
1033
+ writeHeapSnapshot()
1026
1034
  }
1027
1035
  } catch (err) {
1028
1036
  logger.error({ err, type })
@@ -1049,12 +1057,14 @@ export function makeApp(appConfig, onTerminate) {
1049
1057
  }
1050
1058
 
1051
1059
  if (req.method === 'POST' && req.url === '/gc') {
1060
+ gc()
1052
1061
  utilsBC.postMessage({ type: 'utils:gc' })
1053
1062
  res.end()
1054
1063
  return
1055
1064
  }
1056
1065
 
1057
1066
  if (req.method === 'POST' && req.url === '/writeHeapSnapshot') {
1067
+ writeHeapSnapshot()
1058
1068
  utilsBC.postMessage({ type: 'utils:writeHeapSnapshot' })
1059
1069
  res.end()
1060
1070
  return
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.9.15",
3
+ "version": "23.9.16",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",