Sorry for the general explanation of case, but I'm struggling with SSR leaks (probably in my code). The project has only bootstrap-vue and axios as modules, no other nuxt dependencies.
The actual code is (without it seems no leaks)
async asyncData ({ app, store }) {
const [, fetchSecond] = await storeChecker(app,
[
{
state: 'FirstData',
check: current => current && (current.length > 0),
save: (store, data) => store.commit('FirstData', Object.assign({}, data.data)),
promiser: axios => axios.get('/FirstData')
},
{
promiser: axios => axios.get('/SecondData?' + createFilter({
filter: {
limit: 20,
order: 'createdAt desc',
fields: ['name', 'id']
}
}))
}
]
)
// next code is only grouping entities, tried without it with no luck
const categories = convertCategoriesArrays([
item => '/first/' + item.id,
item => '/second/' + item.id
], store.state.FirstData)
return {
firstDataType1: categories[0],
firstDataType2: categories[1],
secondData: fetchSecond.data
}
}
and where storeChecker
is defined as follows:
function storeChecker (app, promisesOptions) {
var awaiters = []
const axios = app.$axios
const store = app.store
for (let index in promisesOptions) {
const option = promisesOptions[index]
if (option.state) {
if (option.check(store.state[option.state])) {
awaiters.push(store.state[option.state])
} else {
awaiters.push(option.promiser(axios).then(data => option.save(store, data)))
}
} else {
awaiters.push(option.promiser(axios))
}
}
return Promise.all(awaiters)
}
Starting pm2's two clustered instances and benchmarking with different ApacheBench requests, such as
ab -n 100 -c 25 -r -k http://localhost:3000/
I see (using pm2 monitor or whatever) memory growth in linear manner. Profiling one instance and comparing the snapshots give me a picture, where context is copied every request... I have a difference between one and 20 request in 20 saved data strings in memory.
I have tried to avoid closures, putting all the code in asyncData method, but no changes in memory consumption are. Searching around the code for a few days didn't give me a hint.
Using the latest nuxt version (rc11). I guess that SSRContext is possibly copied via global between request, but cannot prove. The nearest line in profile, is the Vue.use, but it isn't a hint also.
Any thoughts are appreciated. This is a (my) real problem on server side, cause 50 request (10 concurrent) needs ~500Mb memory each time, and the memory usage summarize.
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c1572">#c1572</a>)</em></sub></div>