ELECTRON-445 (Change the memory refresh logic to auto-refresh after 4Hrs of user inactivity) (#415)

- Change the memory refresh logic to auto refresh after 4Hrs
This commit is contained in:
Kiran Niranjan 2018-07-02 17:17:01 +05:30 committed by Vishwas Shashidhar
parent 9552e83549
commit e6d16241f8
2 changed files with 3 additions and 8 deletions

View File

@ -8,9 +8,7 @@ const { getConfigField } = require('./config');
const maxMemory = 800; const maxMemory = 800;
let maxIdleTime = 15 * 60 * 1000; let maxIdleTime = 4 * 60 * 60 * 1000;
let reloadThreshold = 60 * 60 * 1000;
let reloadedTimeStamp;
let isInMeeting = false; let isInMeeting = false;
// once a minute // once a minute
@ -39,13 +37,10 @@ function gatherMemory() {
*/ */
function optimizeMemory(memoryInfo, cpuUsage) { function optimizeMemory(memoryInfo, cpuUsage) {
const memoryConsumed = (memoryInfo && memoryInfo.workingSetSize / 1024) || 0; const memoryConsumed = (memoryInfo && memoryInfo.workingSetSize / 1024) || 0;
const canReload = (!reloadedTimeStamp || (new Date().getTime() - reloadedTimeStamp) > reloadThreshold);
if (memoryConsumed > maxMemory if (memoryConsumed > maxMemory
&& systemIdleTime.getIdleTime() > maxIdleTime && systemIdleTime.getIdleTime() > maxIdleTime
&& canReload
&& !isInMeeting && !isInMeeting
&& cpuUsage.percentCPUUsage < 1
) { ) {
getConfigField('memoryRefresh') getConfigField('memoryRefresh')
.then((enabled) => { .then((enabled) => {
@ -54,7 +49,6 @@ function optimizeMemory(memoryInfo, cpuUsage) {
if (mainWindow && !mainWindow.isDestroyed()) { if (mainWindow && !mainWindow.isDestroyed()) {
setIsAutoReload(true); setIsAutoReload(true);
reloadedTimeStamp = new Date().getTime();
log.send(logLevels.INFO, 'Reloading the app to optimize memory usage as' + log.send(logLevels.INFO, 'Reloading the app to optimize memory usage as' +
' memory consumption was ' + memoryConsumed + ' memory consumption was ' + memoryConsumed +
' CPU usage percentage was ' + cpuUsage.percentCPUUsage + ' CPU usage percentage was ' + cpuUsage.percentCPUUsage +

View File

@ -22,6 +22,7 @@ const getMediaSource = require('../desktopCapturer/getSource');
const { TitleBar, updateContentHeight } = require('../windowsTitlebar'); const { TitleBar, updateContentHeight } = require('../windowsTitlebar');
const titleBar = new TitleBar(); const titleBar = new TitleBar();
const { buildNumber } = require('../../package.json'); const { buildNumber } = require('../../package.json');
const memoryMonitorInterval = 1000 * 60 * 60;
require('../downloadManager'); require('../downloadManager');
@ -80,7 +81,7 @@ setInterval(() => {
memory: memory, memory: memory,
cpuUsage: cpuUsage cpuUsage: cpuUsage
}); });
}, 1000 * 60 * 15); }, memoryMonitorInterval);
createAPI(); createAPI();