markdown 限制Chrome可以使用的CPU和内存资源量。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 限制Chrome可以使用的CPU和内存资源量。相关的知识,希望对你有一定的参考价值。

Restrict the amount of CPU and memory resources that Chrome can consume.

*Tested on Ubuntu 16.04/Linux Mint 18.*

---

Install cgroups:

```
sudo apt install cgroup-bin
```

Set up a browser group in `/etc/cgconfig.conf` to limit the amount of resources Chrome can use:
```
group browsers {
  perm {
    task {
      uid = jake;
      gid = users;
    }
    admin {
      uid = jake;
      gid = users;
    }
  }
  cpu {
    # Allow chromium to use 2 CPU cores maximum (current machine has 4 cores).
    # See: https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Resource_Management_Guide/sect-cpu-Example_Usage.html
    cpu.cfs_quota_us =  200000;
    cpu.cfs_period_us = 100000;
  }
  memory {
    # Allow chromium to use 6GB maximum (current machine has 16GB RAM)
    memory.limit_in_bytes = "6G";
    memory.soft_limit_in_bytes = "5G";
  }
}
```

Then add a rule to `/etc/cgrules.conf` so that any new Chrome processes launched by my own user (`jake`) are added to the cgroup `browsers`:

```
# user:process                                        subsystems      group
jake:/usr/lib/chromium-browser/chromium-browser       cpu,memory      browsers
```
Since Ubuntu doesn't provide a systemd service to start cgroups, create your own in `/etc/systemd/system/cgroups.service`:

```
[Unit]
Description=Load cgroup configs
After=remote-fs.target

[Service]
Type=forking
ExecStartPre=/bin/echo "Processing /etc/cgconfig.conf..."
ExecStartPre=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf
ExecStartPre=/bin/echo "Processing /etc/cgrules.conf..."
ExecStart=/usr/sbin/cgrulesengd --logfile=/var/log/cgrulesengd.log
Restart=on-failure

[Install]
WantedBy=multi-user.target
```

Finally, enable & start the service to load up your rules

```
sudo systemctl enable --now cgroups.service
```
---

#### References:
https://gist.github.com/juanje/9861623  
https://wiki.archlinux.org/index.php/cgroups#Persistent_group_configuration  
https://askubuntu.com/questions/836469/install-cgconfig-in-ubuntu-16-04  
https://bugs.launchpad.net/fuel/+bug/1674633   

以上是关于markdown 限制Chrome可以使用的CPU和内存资源量。的主要内容,如果未能解决你的问题,请参考以下文章

cefsharp限制cpu使用比例

Docker: 限制容器可用的 CPU

Chrome MarkDown Preview Plus

docker-限制CPU使用

如何限制CPU使用率?

windows限制进程可以使用的资源cpu 内存