MacOS – How to stop Chrome from using 100% CPU periodically

cpu usagegoogle-chromemacbook promacososx-yosemite

So when I open up the computer again after standby Chrome starts to use 100% CPU by itself without me doing anything. It lasts for about 10-20 seconds.

The problem is that my battery health is around 50% and because of high CPU usage for long periods the battery can't handle it and the MacBook goes back into sleep and I can't bring it on unless I plug the power adapter even if it's charged > 90%. This is really annoying and I only have this issue because of Chrome. Any other apps I can control the CPU usage so it's not a problem.

=====

FFS, someone please help, I can't stand this anymore. This browser is destroying my life 🙁

In the task manager, it shows that while CPU is maximum network activity is also at max, so obviously, it's "calling home" and sending whatever. How can I block the network request, if I can't block the CPU? I have little snitch but I don't know what rule or what address I need to block.

PS: NOW after some update, it started to do this every 2-3 hours, not just after standby, and it takes about 15% of the battery when the battery is full, or it just makes the laptop go into sleep mode if the battery is below 60%.

enter image description here

Best Answer

Premise

The problem you are facing is not reproducible because it depends on the number of open Chrome windows and tabs and their content. Unfortunately, even if you were more precise by posting all the links pointed to by your browser, it would not be enough because the content of the internet pages varies over time by changing the advertising inside.

However, I encountered the exact same problem with Firefox under Linux.
So not quite the same, not that far anyway.
For a better understandig of the answer read below the section Understanding what is happening. Note: I did not have time to write more succinctly...

Partial or whole solutions, raw or educated.

  • Educated. The fewer the windows open, the fewer the problems. You should decrease the number of open tabs open tabs that will go through the suspend / reactivate process.
    You can use something like One tab[1] an add-on to group open pages (windows and tabs inside) into a kind of link list, without losing them, having the ability to restore them at once (window by window) and a little to manage them. See it as a quicker, cozier alternative somewhere in between with usual bookmarks. I used it and it solved most of my problem.

  • ??? Third parties add-on to refresh automatically (or in this case with one click) all the pages. For example super-easy-auto-refresh or similar. Never used this one but it can be effective.

  • Almost raw: Reload. This has a good chance of breaking the offending scripts. You can reload heavy windows / tabs, the ones with many scripts. Usually F5 or the reload button are enough. Not cozy with many open tabs, but a patch that can result effective.

  • Educated Almost raw. Three buttons instead of one. [+] +R. Deeper than the previous one.
    You may want to use Chrome Dev Tools[3] by pressing F12: right click on the reload button will open a drop down menu.

    This menu gives you the option of doing a hard refresh, or even clearing the cache and do a hard refresh automatically. [3]

    • Ctrl+R for Normal reload (mac: Hold Shift and click the Reload button, or press R).
    • Ctrl+Shift+R for Hard Reload (mac: hold down Cmd, Shift key and then press R).
      Note: hard reload should clear the stored cache for that page.
  • Be nice. Seldom you can have the browser window not responding. With nice-n 19 chrome (renice when it is already running, or top then r for renice...) you will be able to either regain some control over that or other windows of the browser, both to decrease battery consumption, due to the less intense process of mass requests.

  • raw: kill. Raw quick and sudden solution, a sort of last resort but effective.
    You can manually kill chrome, e.g. from command-line, and restart it.
    It should be able to restore your open windows/tabs (there is an option for that inside the settings).

    pkill chrome        ## Do what it says  
    pkill -9 chrome     ## Even more raw
    killall chrome      ## Alternative
    

Understanding what is happening

When you open a window in your browser your computer executes some code from the browser itself, and some other code from the page you are loading. The more pages, the more the code requests.

On the human user's side the computer slows down, until we decide to add some add-ons in order to cut some of the unwanted process executions. Those ad-blockers interrupt some scripts they know, fool others, and globally make the computer recover speed. In this way the human user can start to increase again the number of open pages, and consequently the number of scripts to be executed if not blocked.

We tend to group similar searches and pages into different tabs in the same window, so that we can navigate them faster when needed and keep them grouped together. Those bunches of links are important enough not to be deleted, but not important enough to be bookmarked ... and they stay there longer than they were originally intended to be.

Suspending

When you go to suspend the computer, broadly speaking, the processes are frozen and the contents of the memory dumped. When you wake him up, things get right, or at least they should.

In the between "things get right" and "at least they should" lies the problem.
In almost all the open pages there are scripts that are waiting to be executed periodically (refresh, check on conditions...), and other that are waiting answers from servers. When you wake up your computer all the expected timeouts have expired. From here the spike in the CPU/memory usage and internet use.

Furthermore, such scripts (and part of the pages code) are not always written taking into account the possibility of being suspended. Then they can wait indefinitely to get a response from a server that processes an accepted request: your script knows that the server has received the request and is processing the response, the server expires the request in the meantime, the scripts after the wake-up wait indefinitely or flood requests to the server...

Other possible effects on your computer are bottlenecks due to the mass of requests to run processes simultaneously, requests on the Internet, multiple accesses to the database.

All this without considering unexpected errors in the scripts that could misinterpret a memory address changed in the meantime, a response to a subsequent instance of the same process etc. etc.Use your imagination to think of other ways that things can go wrong, it will never be enough. (One of Murphy's Laws).

Conclusion

Given the non-reproducibility of the problem, the possibility to find scripts coded not considering the consequences of being suspended, the constant chasing between scripts on pages and updates in add-ons to stop them, I am afraid there will always be irresponsible scripts when the computer wakes up. Minimizing the number of pages opened leads however to a lower exposure to this risk.

Furthermore, the choice to update each page opened after a suspension period is absolutely subjective and case depending: I might prefer to have the page with the result of a search carried out before closing the computer, another user to have the updated version after computer waking up...

Related Question