Created
June 20, 2014 15:41
-
-
Save legoscia/e0ac1bd1f640c9489609 to your computer and use it in GitHub Desktop.
Test file:write/2 runtime with varying message queue size
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
%%% This module tests the impact of message queue size on the runtime | |
%%% of file:write/2. | |
%%% | |
%%% The idea is that something somewhere needs more references in a | |
%%% selective receive (OTP-8623, introduced in R14A). | |
-module(filewrite). | |
-export([testit/1, testit_raw/1, testit/2]). | |
testit(NMsgs) -> | |
testit(NMsgs, []). | |
testit_raw(NMsgs) -> | |
testit(NMsgs, [raw]). | |
testit(NMsgs, Options) -> | |
Parent = self(), | |
spawn_link(fun() -> do_testit(Parent, Options, NMsgs) end), | |
receive {result, Result} -> | |
Result | |
end. | |
do_testit(Parent, Options, NMsgs) -> | |
enqueue_messages(NMsgs), | |
io:format("Queued ~b messages~n", [NMsgs]), | |
{ok, FD} = file:open("/tmp/foo.txt", [write] ++ Options), | |
try | |
Result = {_Time, ok} = timer:tc(file, write, [FD, "hello\n"]), | |
Parent ! {result, Result} | |
after | |
file:close(FD) | |
end. | |
enqueue_messages(0) -> | |
ok; | |
enqueue_messages(N) when N > 0 -> | |
self() ! this_is_a_message, | |
enqueue_messages(N - 1). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment