需要“计算”根据我自己的服务器需求优化 ulimit 和 fs.file-max 值

发布于 2024-11-10 16:32:28 字数 466 浏览 4 评论 0原文

需要根据我自己的服务器需求“计算”最佳 ulimit 和 fs.file-max 值。 请不要与“如何在各种 Linux 发行版中设置这些限制”问题相冲突。

我想问:

  1. 有什么好的指南可以详细解释ulimit使用的参数吗? (> 2.6 系列内核)
  2. 是否有任何好的指南来显示 fs.file-max 使用指标?

其实我可以在网上找到一些旧的参考资料: http://www.faqs.org/docs/securing/chap6sec72.html “对于我们拥有的每 4M RAM,合理的值是 256:即对于具有 128 MB RAM 的机器,将其设置为 8192 - 128/4=32 32*256=8192”

任何最新的参考都值得赞赏。

Need to "calculate" optimum ulimit and fs.file-max values according to my own server needs.
Please do not conflict with "how to set those limits in various Linux distros" questions.

I am asking:

  1. Is there any good guide to explain in detail, parameters used for ulimit? (> 2.6 series kernels)
  2. Is there any good guide to show fs.file-max usage metrics?

Actually there are some old reference i could find on the net:
http://www.faqs.org/docs/securing/chap6sec72.html
"something reasonable like 256 for every 4M of RAM we have: i.e. for a machine with 128 MB of RAM, set it to 8192 - 128/4=32 32*256=8192"

Any up to date reference is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

习ぎ惯性依靠 2024-11-17 16:32:28

对于fs.file-max,我认为在几乎所有情况下你都可以不理会它。如果您正在运行某种非常繁忙的服务器并且实际上用完了文件句柄,那么您可以增加它 - 但您需要增加它的值将取决于您正在运行的服务器类型和负载就它而言。一般来说,您只需要增加它,直到您不再用完文件句柄,或者直到您意识到需要更多内存或更多系统来处理负载。通过将 file-max 降低到默认值以下来“调整”事物的收益是如此之小,以至于不值得考虑 - 我的手机在 fs-max 值为 83588 时工作正常。

顺便说一句,现代内核已经使用了根据系统内存量设置 file-max 的经验法则;来自2.6内核中的fs/file_table.c

    /*
     * One file with associated inode and dcache is very roughly 1K.
     * Per default don't use more than 10% of our memory for files. 
     */ 

    n = (mempages * (PAGE_SIZE / 1024)) / 10;
    files_stat.max_files = max_t(unsigned long, n, NR_FILE);

files_stat.max_filesfs.file-max的设置;最终每 1MB 的 RAM 大约需要 100 个。

ulimit 当然是关于限制用户或进程分配的资源。如果您有多个用户或其他类似情况,那么您可以决定如何划分系统资源并限制内存使用、进程数量等。有关您可以设置的限制详细信息的权威指南是setrlimit 手册页(当然还有内核源代码)。

For fs.file-max, I think in almost all cases you can just leave it alone. If you are running a very busy server of some kind and actually running out of file handles, then you can increase it -- but the value you need to increase it to will depend on exactly what kind of server you are running and what the load on it is. In general you would just need to increase it until you don't run out of file handles any more, or until you realize you need more memory or more systems to handle the load. The gain from "tuning" things by reducing file-max below the default is so minimal as to not be worth thinking about -- my phone works fine with an fs-max value of 83588.

By the way, the modern kernel already uses a rule of thumb to set file-max based on the amount of memory in the system; from fs/file_table.c in the 2.6 kernel:

    /*
     * One file with associated inode and dcache is very roughly 1K.
     * Per default don't use more than 10% of our memory for files. 
     */ 

    n = (mempages * (PAGE_SIZE / 1024)) / 10;
    files_stat.max_files = max_t(unsigned long, n, NR_FILE);

and files_stat.max_files is the setting of fs.file-max; this ends up being about 100 for every 1MB of ram.

ulimits of course are about limiting resources allocated by users or processes. If you have multiple users or another situation like that, then you can decide how you want to divide up system resources and limit memory use, number of processes, etc. The definitive guide to the details of the limits you can set is the setrlimit man page (and the kernel source, of course).

七禾 2024-11-17 16:32:28

通常,像 Oracle 或 SAP 这样的大型系统会建议设置非常高的限制,以免受到影响。我只能推荐使用这种方法。数据结构将动态分配,因此只要您不需要它们,它们就不会占用内存。如果您确实需要它们,它不会帮助您限制它们,因为如果达到限制,应用程序通常会崩溃。

fs.file-max = 6815744 # 这大致是 70GB RAM 系统的默认限制

对于用户 rlimits (nofile) 也是如此,您将使用 65535。

请注意,这两个建议仅适用于关键应用程序的专用服务器和受信任的 shell 用户。多用户交互式 shell 主机必须具有限制性的最大设置。

Typically larger systems like Oracle or SAP recommend a very high limit in order to never be affected by it. I can only recommend to use this approach. The data structures will be allocated dynamically, so as long as you dont need them they dont use up memory. If you actually need them it will not help you to limit them, because if the limit is reached the application will normally crash.

fs.file-max = 6815744 # this is roughly the default limit for a 70GB RAM system

The same is true for the user rlimits (nofile), you will use 65535.

Note that both recommendations are only good for dedicated servers with on critical application and trusted shell users. A multi-user interactive shell host must have a restrictive max setting.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文