File tree Expand file tree Collapse file tree 6 files changed +15
-43
lines changed
Expand file tree Collapse file tree 6 files changed +15
-43
lines changed Original file line number Diff line number Diff line change 11FROM node:18-alpine as builder
22WORKDIR /app
33COPY indexer yarn.lock ./
4- # Install build dependencies for native modules like heapdump
5- RUN apk add --no-cache python3 make g++
64RUN rm -rf node_modules && yarn install --frozen-lockfile
75RUN npx graphql-codegen
86RUN yarn build
97
108FROM node:18-alpine
119WORKDIR /app
1210COPY indexer/package.json indexer/tsconfig.json yarn.lock ./
13- # Install build dependencies for native modules like heapdump
14- RUN apk add --no-cache python3 make g++
1511RUN yarn install --frozen-lockfile
1612COPY --from=builder /app/dist ./dist
1713COPY --from=builder /app/src/config/global-bundle.pem ./dist/config/global-bundle.pem
1814COPY --from=builder /app/src/kadena-server/config/schema.graphql ./dist/kadena-server/config/schema.graphql
1915COPY --from=builder /app/src/circulating-coins/ ./dist/circulating-coins/
20- # Create snapshots directory for heap dumps
21- RUN mkdir -p /snapshots
2216EXPOSE 3001
2317
2418ARG INDEXER_MODE_PARAM
Original file line number Diff line number Diff line change 5151 "@types/decimal.js" : " ^7.4.3" ,
5252 "@types/eventsource" : " ^1.1.15" ,
5353 "@types/express" : " ^4.17.21" ,
54- "@types/heapdump" : " ^0.3.4" ,
5554 "@types/jest" : " ^29.5.12" ,
5655 "@types/mocha" : " ^10.0.7" ,
5756 "@types/node" : " ^20.11.17" ,
6261 "dotenv" : " ^16.4.4" ,
6362 "dotenv-cli" : " ^8.0.0" ,
6463 "eslint" : " ^8.56.0" ,
65- "heapdump" : " ^0.3.15" ,
6664 "jest" : " ^29.7.0" ,
6765 "mocha" : " ^10.7.3" ,
6866 "module-alias" : " ^2.2.3" ,
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import { startStreaming } from './services/streaming';
2020import { backfillPairEvents } from './services/pair' ;
2121import { setupAssociations } from './models/setup-associations' ;
2222import { PriceUpdaterService } from '@/services/price/price-updater.service' ;
23+ import { initializeMemoryMonitoring } from '@/utils/memory-usage' ;
2324
2425/**
2526 * Command-line interface configuration using Commander.
@@ -51,6 +52,7 @@ async function main() {
5152 try {
5253 console . info ( 'Starting v1.1.0' ) ;
5354 initializeErrorMonitoring ( ) ;
55+ initializeMemoryMonitoring ( ) ;
5456 setupAssociations ( ) ;
5557 PriceUpdaterService . getInstance ( ) ;
5658
Original file line number Diff line number Diff line change 1919 */
2020
2121import './plugins/instrument' ;
22- import heapdump from 'heapdump' ;
2322import { ApolloServer , ApolloServerPlugin } from '@apollo/server' ;
2423import { expressMiddleware } from '@apollo/server/express4' ;
2524import { ApolloServerPluginDrainHttpServer } from '@apollo/server/plugin/drainHttpServer' ;
@@ -510,23 +509,6 @@ export async function startGraphqlServer() {
510509 res . status ( 404 ) . end ( ) ;
511510 } ) ;
512511
513- const logMemoryUsage = ( ) => {
514- const mem = process . memoryUsage ( ) ;
515- console . info (
516- `[INFO][MEMORY] Heap: ${ ( mem . heapUsed / 1024 / 1024 ) . toFixed ( 2 ) } MB / ${ ( mem . heapTotal / 1024 / 1024 ) . toFixed ( 2 ) } MB | External: ${ ( mem . external / 1024 / 1024 ) . toFixed ( 2 ) } MB | RSS: ${ ( mem . rss / 1024 / 1024 ) . toFixed ( 2 ) } MB` ,
517- ) ;
518-
519- // Capture heap snapshot at 1GB memory threshold
520- if ( mem . heapUsed > 1 * 1024 * 1024 * 1024 ) {
521- const filename = `/snapshots/indexer-heap-1GB-${ Date . now ( ) } .heapsnapshot` ;
522- console . error ( `[WARN][MEMORY] 1GB threshold reached! Capturing heap snapshot: ${ filename } ` ) ;
523- heapdump . writeSnapshot ( filename ) ;
524- }
525- } ;
526-
527- // Start periodic memory monitoring every one hour
528- setInterval ( logMemoryUsage , 1000 * 60 * 60 ) ;
529-
530512 // Initialize cache and start the server
531513 await initCache ( context ) ;
532514 await new Promise < void > ( resolve => httpServer . listen ( { port : KADENA_GRAPHQL_API_PORT } , resolve ) ) ;
Original file line number Diff line number Diff line change 1+ export const initializeMemoryMonitoring = ( ) => {
2+ const memoryMonitoringInterval = 1000 * 60 * 30 ; // 30 minutes
3+ setInterval ( monitorMemoryUsage , memoryMonitoringInterval ) ;
4+ } ;
5+
6+ const monitorMemoryUsage = ( ) => {
7+ const mem = process . memoryUsage ( ) ;
8+ const heapUsedMB = mem . heapUsed / 1024 / 1024 ;
9+ const heapInfo = `Heap: ${ heapUsedMB . toFixed ( 2 ) } MB / ${ ( mem . heapTotal / 1024 / 1024 ) . toFixed ( 2 ) } MB` ;
10+ const externalInfo = `External: ${ ( mem . external / 1024 / 1024 ) . toFixed ( 2 ) } MB` ;
11+ const rssInfo = `RSS: ${ ( mem . rss / 1024 / 1024 ) . toFixed ( 2 ) } MB` ;
12+ console . info ( `[INFO][MEMORY] ${ heapInfo } | ${ externalInfo } | ${ rssInfo } ` ) ;
13+ } ;
Original file line number Diff line number Diff line change 26632663 dependencies :
26642664 " @types/node" " *"
26652665
2666- " @types/heapdump@^0.3.4 " :
2667- version "0.3.4"
2668- resolved "https://registry.yarnpkg.com/@types/heapdump/-/heapdump-0.3.4.tgz#59645b30165d832ea654449c8ffbed0c156ad60c"
2669- integrity sha512-gTGn7W7i58F1yzvLZ5+hRE7M/VqgEzgccERJ9ZThC6qor5R8wo3oP7iiHvwgHIZzoqPF22ngu8mBagcqPWMVTg==
2670-
26712666" @types/http-errors@* " :
26722667 version "2.0.4"
26732668 resolved "https://registry.npmjs.org/@types/http-errors/-/http-errors-2.0.4.tgz"
@@ -5350,13 +5345,6 @@ header-case@^2.0.4:
53505345 capital-case "^1.0.4"
53515346 tslib "^2.0.3"
53525347
5353- heapdump@^0.3.15 :
5354- version "0.3.15"
5355- resolved "https://registry.yarnpkg.com/heapdump/-/heapdump-0.3.15.tgz#631a8a2585588ea64778d8ec80a64c6c025f6a08"
5356- integrity sha512-n8aSFscI9r3gfhOcAECAtXFaQ1uy4QSke6bnaL+iymYZ/dWs9cqDqHM+rALfsHUwukUbxsdlECZ0pKmJdQ/4OA==
5357- dependencies :
5358- nan "^2.13.2"
5359-
53605348html-escaper@^2.0.0 :
53615349 version "2.0.2"
53625350 resolved "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz"
67076695 resolved "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz"
67086696 integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==
67096697
6710- nan@^2.13.2 :
6711- version "2.23.0"
6712- resolved "https://registry.yarnpkg.com/nan/-/nan-2.23.0.tgz#24aa4ddffcc37613a2d2935b97683c1ec96093c6"
6713- integrity sha512-1UxuyYGdoQHcGg87Lkqm3FzefucTa0NAiOcuRsDmysep3c1LVCRK2krrUDafMWtjSG04htvAmvg96+SDknOmgQ==
6714-
67156698napi-wasm@^1.1.0 :
67166699 version "1.1.0"
67176700 resolved "https://registry.npmjs.org/napi-wasm/-/napi-wasm-1.1.0.tgz"
You can’t perform that action at this time.
0 commit comments