如何限制Haskell线程的内存使用量 [英] How to cap memory usage of Haskell threads
问题描述
这可能是使用单独的进程和 ulimit
,但是:
-
我宁愿将它保存在一个程序中,以避免进程间通信的复杂性。
-
我需要同时支持Linux和Windows,因此如果可能的话,我宁愿保持其与平台无关。
I would rather keep it in one program, to avoid the complexity of inter-process communication.
I need to support both Linux and Windows, so I would prefer to keep it platform-agnostic if possible.
<解析方案Edward Z. Yang和DavidMazières开发了一个支持动态资源限制的GHC扩展,并在 http://ezyang.com/rlimits.html 他们还提供了一个支持这个版本的GHC 7.8版本。 p>
不幸的是,他们的工作并未包含在GHC上游。
In a Haskell program compiled with GHC, is it possible to programmatically guard against excessive memory usage? That is, have it notify the program when memory usage reaches a specified limit, preferably indicating the offending thread.
For example, suppose I want to write a server, hosting a scripting language interpreter, that users can connect to. It's Turing-complete, so programs could theoretically use unlimited memory or time. Suppose each client is handled with a separate thread. If a client writes an infinite loop that consumes memory very quickly, I want to ensure that the thread consumes no more than, say, 1 MB of memory, before being alerted with an exception. I do not want other users to be affected when that happens.
This is probably possible using separate processes and ulimit
, but:
Edward Z. Yang and David Mazières have developed an extension to GHC that supports dynamic resource limits, and discuss it at http://ezyang.com/rlimits.html They also provide a version of GHC 7.8 that supports this.
Unfortunately, their work was not included in GHC upstream.
这篇关于如何限制Haskell线程的内存使用量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!