Created
May 6, 2015 00:09
-
-
Save videlalvaro/95e91f5596ad50393583 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% run this on the CLI: | |
%% start erlang: erl +K true | |
c(memory). | |
%% file size is arbitrary but too big will make the VM crawl with what follows | |
{ok, Bin} = file:read_file("my_at_least_3MB_file.something"). | |
L = binary_to_list(Bin). | |
Pid = memory:start(). | |
%% keep N low, a value of 100 makes my VM unresponsive in my 16GB of RAM Retina Mac. | |
N = 10. | |
[Pid ! {set, Key, L} || Key <- lists:seq(1, N)]. | |
%% use Activity Monitor or similar to check beam.smp memory usage. | |
%% next line will double memory usage since the dictionary will be duplicaed | |
%% see: https://github.com/erlang/otp/blob/maint/erts/emulator/beam/erl_process_dict.c#L235 | |
erlang:process_info(Pid, dictionary). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(memory). | |
-export([start/0]). | |
start() -> | |
spawn(fun loop/0). | |
loop() -> | |
receive | |
{set, Key, Val} -> | |
put(Key, Val), | |
loop() | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment