limit memory to 512

This commit is contained in:
Zutatensuppe 2020-12-13 15:38:44 +01:00
parent 6b1c3fb085
commit 219bdb2735
2 changed files with 9 additions and 4 deletions

View file

@ -9,6 +9,7 @@ import Util from './../common/Util.js'
import Game from './Game.js'
import twing from 'twing'
import bodyParser from 'body-parser'
import v8 from 'v8'
const allImages = () => [
...fs.readdirSync('./../data/uploads/').map(f => ({
@ -180,18 +181,22 @@ wss.listen()
const memoryUsageHuman = () => {
const totalHeapSize = v8.getHeapStatistics().total_available_size
let totalHeapSizeInGB = (totalHeapSize / 1024 / 1024 / 1024).toFixed(2)
console.log(`Total heap size (bytes) ${totalHeapSize}, (GB ~${totalHeapSizeInGB})`)
const used = process.memoryUsage().heapUsed / 1024 / 1024
return `${Math.round(used * 100) / 100}M`
console.log(`Mem: ${Math.round(used * 100) / 100}M`)
}
console.log(`Mem: ${memoryUsageHuman()}`)
memoryUsageHuman()
// persist games in fixed interval
const persistInterval = setInterval(() => {
console.log('Persisting games...');
Game.persistChangedGames()
console.log(`Mem: ${memoryUsageHuman()}`)
memoryUsageHuman()
}, config.persistence.interval)
const gracefulShutdown = (signal) => {