Whatsapp-web.js: High memory and CPU usage when logout with many chat account

Created on 29 Feb 2020  路  10Comments  路  Source: pedroslopez/whatsapp-web.js

Hi, when i logout my account with many chat inside, chromium process take high CPU and memory consumption, but when using account with less chat inside. the process is normal.

here my code and screenshot of task manager, thanks

const { Client } = require('whatsapp-web.js');
const client = new Client({
    puppeteer: {
        headless: false,       
    }
});

client.on('qr', (qr) => {
    // Generate and scan this code with your phone
    console.log('QR RECEIVED', qr);
});

client.on('ready', () => {
    console.log('Client is ready!');
});

client.on('message', msg => {
    if (msg.body == '!ping') {
        msg.reply('pong');
    }
});

client.on('disconnect', reason => {
    console.log(reason)

});

client.initialize();

Screenshot_1

stale

All 10 comments

@pedroslopez after made some research this is because window.Store.Msg.on('remove', window.onRemoveMessageEvent); listener i removed this line and try logout with my device with lots of chat, now the CPU usage seem normal.

any idea with this?

Yikes. I added that line.

Fix

Probably same fix can be applied.

Okay, apparently all these event handlers need to be delegated first and not go straight through to a puppeteer function. After yesterday's fix, I saw a lot of improvement in performance and CPU usage when receiving messages and specially on startup. I'll make the fix later today to do this with all event handlers.

Thanks for reporting and the input! @tarikhagustia @Aliyss

For reference, here is the difference I saw before and after yesterday's fix, and the amount of messages coming in has increased as well.

Screen Shot 2020-03-13 at 3 08 20 PM

Wooow! Amazing improvement, i have been tracking this behaviour of high CPU usage but no success, i waiting your PR to test and will post my graphs of performance! I have 17Instances running that code LoL @pedroslopez

That's my actual performance,
Pay attention to high decrease every midnight, i manually proceed restarts on all instances at that time.
Captura de Tela 2020-03-13 a虁s 16 16 11

@joaomirandasa please note that most of the improvements seen with the fix was with CPU usage and not with memory. The utilized memory by chrome still grows steadily over time, unfortunately.

v1.2.3 has now been released. Please check and report your findings @tarikhagustia @joaomirandasa

using latest version fix this issue, thanks for a great job, i'll close this issue

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings