@@ -25,6 +25,23 @@ import "./test_utils.js";
25
25
import "./kill.js" ;
26
26
import "./virtual_object_command_interpreter.js" ;
27
27
import * as http2 from "http2" ;
28
+ import * as heapdump from "heapdump" ;
29
+ import path from "path" ;
30
+
31
+ // Optional: trigger a heap snapshot on signal
32
+ process . on ( "SIGUSR2" , ( ) => {
33
+ const filename = path . join ( "/opt" , `heap-${ Date . now ( ) } .heapsnapshot` ) ;
34
+ // eslint-disable-next-line no-console
35
+ console . log ( `Writing snapshot to ${ filename } ...` ) ;
36
+ heapdump . writeSnapshot ( filename , ( err , filename ) => {
37
+ if ( err ) {
38
+ // eslint-disable-next-line no-console
39
+ console . error ( err ) ;
40
+ }
41
+ // eslint-disable-next-line no-console
42
+ else console . log ( `Heap snapshot written to ${ filename } ` ) ;
43
+ } ) ;
44
+ } ) ;
28
45
29
46
import { REGISTRY } from "./services.js" ;
30
47
@@ -35,14 +52,33 @@ const fqdns = new Set(process.env.SERVICES.split(","));
35
52
const endpoint = restate . endpoint ( ) ;
36
53
REGISTRY . register ( fqdns , endpoint ) ;
37
54
55
+ const settings : http2 . Settings = { } ;
56
+ if ( process . env . MAX_CONCURRENT_STREAMS ) {
57
+ settings . maxConcurrentStreams = parseInt ( process . env . MAX_CONCURRENT_STREAMS ) ;
58
+ }
59
+
38
60
if ( process . env . E2E_REQUEST_SIGNING ) {
39
61
endpoint . withIdentityV1 ( ...process . env . E2E_REQUEST_SIGNING . split ( "," ) ) ;
40
62
}
41
63
42
- const server = http2 . createServer ( endpoint . http2Handler ( ) ) ;
43
- const maxConcurrentStreams = parseInt (
44
- process . env . MAX_CONCURRENT_STREAMS || "256"
45
- ) ;
46
- server . updateSettings ( { maxConcurrentStreams : maxConcurrentStreams } ) ;
64
+ let INFLIGHT_REQUESTS = 0 ;
65
+
66
+ const handler = endpoint . http2Handler ( ) ;
67
+ const server = http2 . createServer ( ( req , res ) => {
68
+ INFLIGHT_REQUESTS ++ ;
69
+ res . once ( "close" , ( ) => {
70
+ INFLIGHT_REQUESTS -- ;
71
+ } ) ;
72
+ handler ( req , res ) ;
73
+ } ) ;
74
+
75
+ setInterval ( ( ) => {
76
+ // eslint-disable-next-line no-console
77
+ console . log (
78
+ `${ new Date ( ) . toISOString ( ) } : Inflight requests: ${ INFLIGHT_REQUESTS } `
79
+ ) ;
80
+ } , 30 * 1000 ) ;
81
+
82
+ server . updateSettings ( settings ) ;
47
83
48
84
server . listen ( parseInt ( process . env . PORT || "9080" ) ) ;
0 commit comments