HOW TO: pepperflash in FireFox 2017
0. Get rid of ads, they will save you bandwidth
Replacing your /etc/hosts file will save you A LOT of bandwidth, especially if you have a flash plugin installed. The best on the net is MVPS HOSTS file. Remember to add the contents of your current /etc/hosts file to the top of you new one, which will look like this:
Code: Select all
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback #[IPv6]
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
127.0.1.1 raspberrypi
Code: Select all
0.0.0.0 connect.facebook.net
0.0.0.0 www.facebook.net
0.0.0.0 facebook.net
Code: Select all
[Desktop Entry]
Name=Edit Hosts File
GenericName=Edit Hosts File
Comment=Manage /etc/hosts file enties
Exec=gksudo leafpad /etc/hosts
Icon=kedit
Terminal=false
Type=Application
Categories=System;
StartupNotify=true
1. Limit maximum open windows and tabs, and FAT WEB PAGES:
Especially if you use pages with Flash objects, limit you browser to 5 tabs (or 2 windows).
If you use Gmail, then stop the page load process and click the use standard html interface, which can also be set as your default interface. On Chrome 54 and below, you could "not log out" (by shutting the window), and just url back into Gmail because the cookie was kept. You cant do this in Chrome 55 (look through /usr/bin/chromium-browser), and if you use Gmail on another computer, clicking use standard html interface is a better option.
Facebook.com is FAT. blogger.com is FAT. Wordpress.com is FAT. Any site that uses Wordpress default (read: common) themes is FAT. A lot of blogging sites and news sites are FAT. Be aware that FAT websites can kill your browser, quickly putting it into kernel swap lock. One or Two of these sites in tabs/windows will still get you best performance, most of the time, if you're patient.
Even without Flash content and FAT web pages, over time the browser will become slower to respond to web content and clicks, can be between 2-4 hours, so shut it down periodically, clean the cache, start it up again.
2. Freeing swap memory
Most kernels can get into (what I call) kernel swap lock, espectially with web browsers, especially when pages contain flash objects. Newer kernels seem to hit this problem extremely quickly, and appears worse on SystemD based systems. With SystemD it does not seem to greatly enhance operations to exchange the (Raspian) default 100Mb swap file with a dedicated swap partition, as it does with other init daemons, but even those will succumb to the inevitable kernel swap lock if you run any web browsers for extended periods.
On a regular Raspberry Pi this is because of limited main memory, swap being on a usb device, and a web browser use of cache and/or internal task management, also on a usb device (being the same usb device).
You can manually free any used virtual memory, unless you would rather do a sudo restart. Exiting X-Windows is not enough to free swap memory, but it will free up used memory.
(from: How to Clear RAM Memory Cache, Buffer and Swap Space on Linux)
After all apps a closed, if you want to clear swap space, you can run the following command:1. Clear PageCache only.2. Clear dentries and inodes.Code: Select all
$ sync; echo 1 > /proc/sys/vm/drop_caches3. Clear PageCache, dentries and inodes.Code: Select all
$ sync; echo 2 > /proc/sys/vm/drop_cachesCode: Select all
$ sync; echo 3 > /proc/sys/vm/drop_caches
Code: Select all
$ dphys-swapfile swapoff && dphys-swapfile swaponCode: Select all
$ swapoff -a && swapon -aCode: Select all
$ free
total used free shared buffers cached
Mem: 882780 848036 34744 98324 5476 231128
-/+ buffers/cache: 611432 271348
Swap: 102396 43980 58416Code: Select all
$ free
total used free shared buffers cached
Mem: 882780 48036 834744 98324 5476 231128
-/+ buffers/cache: 611432 271348
Swap: 102396 43980 584163. Clean browser cache before loading browser:
Reduce initial browsing slow-downs caused by waiting for cache by deleting contents of cache before starting browser (not contents of cache database):
Code: Select all
$ mkdir -p ~/bin
$ cd ~/bin
$ echo <<<EOF >~/bin/clean-chrome-cache\
#!/bin/sh\
cd ~/.cache/chromium/Default/Cache\
rm -Rf *\
EOF
$ ln -s clean-chrome-cache cccYou can empty cache before exiting every browser session, which will also clean the cache database (but who remembers to do that everytime)
4. Sandboxing your browser to reduce security breaches, and reduce CPU 100% load and limit use of resources like RAM and SWAP.
Sandbox by installing FireJail in this post:
HOW TO: install FireJail and sandbox any app
1. can be applied to any app, including Chromium-Browser
2. can limit memory usage
3. can limit CPU% usage
4. can limit swap usage
(from firejail man page)
DESKTOP INTEGRATION
A symbolic link to /usr/bin/firejail under the name of a program, will start the program in Firejail sandbox. The symbolic link should be placed in the first $PATH position. On most systems, a good place is /usr/local/bin directory. Example:
Make a firefox symlink to /usr/bin/firejail:Verify $PATHCode: Select all
$ ln -s /usr/bin/firejail /usr/local/bin/firefoxStarting firefox in this moment, automatically invokes “firejail firefox”. This works for clicking on desktop environment icons, menus etc. Use "firejail --tree" to verify the program is sandboxed.Code: Select all
$ which -a firefox /usr/local/bin/firefox /usr/bin/firefoxCode: Select all
$ firejail --tree 1189:netblue:firejail firefox 1190:netblue:firejail firefox 1220:netblue:/bin/sh -c "/usr/lib/firefox/firefox" 1221:netblue:/usr/lib/firefox/firefox
Sandbox using Cgroups and SystemD:
Running Firefox in a cgroup (using systemd)
1. can be applied to any app, including Chromium-Browser
2. can limit memory usage
3. can limit CPU% usage
4. can limit swap usage
(from the above link)
Add /etc/systemd/system/user-firefox.slice:add user-firefox (requires Python)Code: Select all
[Unit] Description=Firefox Slice Before=slices.target [Slice] MemoryAccounting=true MemoryLimit=128M # CPUQuota isn't available in systemd 208 (Fedora 20). CPUAccounting=true CPUQuota=50%You can now run (or add/change firefox.desktop) with:Code: Select all
#!/usr/bin/env python3 import os import pwd user_info = pwd.getpwnam('pi') os.setuid(user_info.pw_uid) env = os.environ.copy() env['HOME'] = user_info.pw_dir os.execle('/usr/bin/firefox', 'Firefox (tame)', env)Code: Select all
sudo systemd-run --slice user-firefox.slice --scope ./user-firefox
5. Tweaking web browser settings.
Starting FireFox in safe mode with plugins disabled can help alot. However that is not practical for a lot of users or use cases, a better more permanent option is under about:config, search for https and change thier urls to h{space}ttps. Note that you might want to keep some of them, like those related to Healthcare, and the Addons link.
(see more here: How does one stop FF from maxing out CPU usage)
Their are alot of settings in Chrome also (chrome://settings), but there are even more under the hood setting in (the shell script) /usr/bin/chromium-browser. However be warned playing with the contents of /usr/bin/chromium-browser could stop Chromium from launching, so at least make a backup of it first.
Cheers
Paul
PS feel free to add your own tips and techniques to this thread
HOW TO: install FireJail and sandbox any app | HOW TO: improve browser experience | HOW TO: pepperflash in FireFox 2017
RE: superblock last write time is in the future | Re: Wine on Raspberry Pi | HOWTO: detached top menu bar (ie Atari ST, Amiga, Mac)
Looking for Grafx2 console art package? | PCManFM right click menu and Open As Root