feat: introduce new option requestsPerForcedGC
Normally, this setting is not required, but for environments where GC execution is expected to be delayed, an option has been added to explicitly trigger GC every N requests.
app
import { Hono } from 'hono'
import { serve } from '@hono/node-server'
const app = new Hono()
app.get('/', (c) => c.text('OK'))
serve(
{
fetch: app.fetch,
requestsPerForcedGC: 1000, // Explicitly trigger garbage collection every 1000 requests.
},
(info) => {
console.log(`Server is running on http://localhost:${info.port}`)
}
)
runner
$ node --expose-gc dist/index.js
Hi @yusukebe
There's no guarantee that issue #269 will be resolved, but based on our investigation so far, I believe memory is being freed when global.gc() is explicitly called. How about we try implementing this change?
I've been thinking about this for a long time. "Clearing something every certain number of requests" is making me think nostalgically of MaxRequestsPerChild in Apache.
It may be a practical solution. But I wonder if this is a good way for "Node.js"? I checked, and Express doesn't have a function like that. So I am not sure this method is suitable for the Node.js Adapter. It's better to wait; we've got more reports about memory leaks.
Hi @yusukebe, thank you for the review. Yes, I don't think it's an essential fix.
Ideally, we'd eliminate the memory increase caused by AbortSignal...