[Erlang危机](5.1.1)内存
Memory
The memory reported by the Erlang VM in most tools will be a variant of what is reported by?erlang:memory()?:
Erlang VM大多數檢測內存的工具都是通過erlang:memory()來實現的。-------------------------------------------------------------------------------------
1> erlang:memory().
[{total,13772400},
{processes,4390232},
{processes_used,4390112},
{system,9382168},
{atom,194289},
{atom_used,173419},
{binary,979264},
{code,4026603},
{ets,305920}]
--------------------------------------------------------------------------------------
?First of all, all the values returned are in bytes, and they represent memory allocated (memory actively used by the Erlang VM, not the memory set aside by the operating system for the Erlang VM). It will sooner or later look much smaller than what the operating system reports.?這里須要解釋下:
?首先,全部的返回值都是字節(bytes)為單位的,它們表示眼下被分配的內存(Erlang VM實際使用的內存。不是操作系統給Erlang VM分配的內存),所以這個值要比操作系統分配的小非常多。
?The total field contains the sum of the memory used for processes and system (which is incomplete, unless the VM is instrumented!). processes is the memory used by Erlang processes, their stacks and heaps. system is the rest: memory used by ETS tables, atoms in the VM, refc binaries11, and some of the hidden data I mentioned was missing.
?If you want the total amount of memory owned by the virtual machine, as in the amount that will trip system limits (ulimit), this value is more difficult to get from within the VM.
?If you want the data without calling top or htop, you have to dig down into the VM’s memory allocators to find things out12.
?假設你想得到VM在操作系統占用的總內存,這個值在訪問系統的限制下(ulimit),非常難從VM內部獲得。
?假設你想不調用top或htop命令來得到數據,你就不得不深入VM內存管理分配來找到你想要的12。?Fortunately, recon has the function recon_alloc:memory/1 to figure it out, where the argument is:
???used?reports the memory that is actively used for allocated Erlang data;
???allocated?reports the memory that is reserved by the VM. It includes the memory used, but also the memory yet-to-be-used but still given by the OS. This is the amount you want if you’re dealing with ulimit and OS-reported values.
???unused?reports the amount of memory reserved by the VM that is not being allocated. Equivalent to allocated-used.
???usage?returns a percentage (0.0 .. 1.0) of used over allocated memory ratios. There are additional options available, but you’ll likely only need them when investigating memory leaks in chapter 7?只是。非常幸運的是。recon有一個函數:recon_alloc:memory/1能夠解決上述問題,參數例如以下:
? ? ? used:給Erlang data分配的內存?
? ? ? allocated:VM占用的總內存。它包括已使用的內存。也包括還已由OS分配給VM但尚未被分配的內存。假設你在處理ulimit和
OS-reported的值,這個參數就非常實用。
? ? ? unused:OS分配給VM可是尚未被VM分配的那部分內存。
? ? ? ? ?usage:返回各個功能使用內存的百分比。另一些額外的選項,只是你可能僅僅會在第七章的內存泄漏那里使用。
[11] See Section 7.2[12] See Section 7.3.2[注11]:參見章節7.2
[注12]:參見章節7.3.2
轉載于:https://www.cnblogs.com/jhcelue/p/6800565.html
總結
以上是生活随笔為你收集整理的[Erlang危机](5.1.1)内存的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 51nod 1258 序列求和 V4
- 下一篇: ZXing二维码和条形码