在 linux 下限制 R 中的内存使用 [英] limiting memory usage in R under linux

查看:28
本文介绍了在 linux 下限制 R 中的内存使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 Linux 集群环境中运行 R.当用户使用 R 进程无意中占用了所有内存时,头节点会挂起几次.有没有办法限制Linux下的R内存使用?我宁愿不建议全局 ulimits,但这可能是唯一的出路.

We are running R in a linux cluster environment. The head node has had a few hangs when a user has inadvertently taken all the memory using an R process. Is there a way to limit R memory usage under linux? I'd rather not suggest global ulimits, but that may be the only way forward.

推荐答案

unix::rlimit_as() 允许使用 同样的机制 也用于shell 中的ulimit.不支持 Windows 和 macOS.

There's unix::rlimit_as() that allows setting memory limits for a running R process using the same mechanism that is also used for ulimit in the shell. Windows and macOS not supported.

在我的 .Rprofile 我有

unix::rlimit_as(1e12, 1e12)

将内存使用量限制为 ~12 GB.

to limit memory usage to ~12 GB.

我创建了一个小型 R 包,ulimit 具有类似的功能.

I had created a small R package, ulimit with similar functionality.

使用 GitHub 从 GitHub 安装

Install it from GitHub using

devtools::install_github("krlmlr/ulimit")

要将 R 可用的内存限制为 2000 MiB,请调用:

To limit the memory available to R to 2000 MiB, call:

ulimit::memory_limit(2000)

现在:

> rep(0L, 1e9)
Error: cannot allocate vector of size 3.7 Gb

这篇关于在 linux 下限制 R 中的内存使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆