Hi, author of parallelly here. I'd like to figure out how to make availableCores() reflect the number of CPUs that you get in RStudio Cloud. That is, how can one infer the number of CPUs available from within an RStudio Cloud instance?
... In the case of docker/Kubernetes it however is as "useful" as parallell::detectCores() .
availableCores() queries nproc, and I would expect that to be reflected here too, if you're running Docker. For example,
$ docker run --cpuset-cpus=0 --rm -ti rocker/r-base nproc
1
$ docker run --cpuset-cpus=0,3 --rm -ti rocker/r-base nproc
2
$ docker run --cpuset-cpus=0,3,6,7 --rm -ti rocker/r-base nproc
4
but that's not the case in RStudio Cloud; there nproc reflects whatever the host has set, e.g. I also see 16 on my free nCPU=1 account.
Digging deeper, contrary to above Docker examples, in RStudio Cloud, /sys/fs/cgroup/cpuset/cpuset.cpus returns 0-15 suggesting all CPUs are available.
Is RStudio Cloud throttling with docker run --cpus=<n> ...? If so, continuing, for my nCPU=1 free account, I get:
/cloud/project$ cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us
100000
For someone with, say, nCPU = 4, will they get
/cloud/project$ cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us
400000
? If that is the case, then I think
n=$(cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us)
nCPU=$((n / 100000))
could be one way to infer the "amount" of CPUs available. Is that reasonable?