Skip to content

Commit

Permalink
merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Moon committed Jul 16, 2009
2 parents e712b84 + c014622 commit 50da004
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 19 deletions.
162 changes: 162 additions & 0 deletions NOTES
@@ -0,0 +1,162 @@
=== 2009-07-16 12:52:44 ===

Switched to ets:foldl as suggested by Jim Morris and to calculating timestamps for each message, as per the patch sent by Will Glozer.

Here are the latest timings on my MBP 2.93Ghz. The maximum latency seems to be 2.1-2.2s, not sure what to make of the 1.5s.

---

(debug@biggie.local)1> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::12:24:08 ===
setup: 161030.13ms, good: 20000, bad: 0, run: 168624.54ms
0.9540ms | min
500.0000ms | 4858 - 24.29%
1000.0000ms | 1547 - 7.74%
1500.0000ms | 2551 - 12.75%
2000.0000ms | 8044 - 40.22%
2500.0000ms | 3000 - 15.00%
2181.8090ms | max
ok

(debug@biggie.local)3> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::12:36:02 ===
setup: 14496.73ms, good: 20000, bad: 0, run: 22286.76ms
0.5900ms | min
500.0000ms | 2810 - 14.05%
1000.0000ms | 1228 - 6.14%
1500.0000ms | 2470 - 12.35%
2000.0000ms | 10811 - 54.05%
2500.0000ms | 2681 - 13.41%
2258.7140ms | max
ok

(debug@biggie.local)4> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::12:43:19 ===
setup: 14338.41ms, good: 20000, bad: 0, run: 22433.91ms
0.5340ms | min
500.0000ms | 9485 - 47.42%
1000.0000ms | 6033 - 30.16%
1500.0000ms | 4482 - 22.41%
1483.6170ms | max
ok
(debug@biggie.local)5> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::12:45:08 ===
setup: 14256.80ms, good: 20000, bad: 0, run: 22089.76ms
3.6720ms | min
500.0000ms | 5368 - 26.84%
1000.0000ms | 874 - 4.37%
1500.0000ms | 2688 - 13.44%
2000.0000ms | 9781 - 48.91%
2500.0000ms | 1289 - 6.44%
2210.5790ms | max
ok

=== 2009-07-16 13:08:39 ===

EC2 run, one instance for the server and another one for bots.

=INFO REPORT==== 16-Jul-2009::12:04:05 ===
setup: 3266.72ms, good: 1000, bad: 0, run: 3589.23ms
ok
(debug@ip-10-244-145-238.ec2.internal)2> bot:test(flashbot, 20000, 'ip-10-244-47-97', 8081).

=INFO REPORT==== 16-Jul-2009::12:05:07 ===
setup: 30900.04ms, good: 20000, bad: 0, run: 38579.24ms
-38.6400ms | min
500.0000ms | 2650 - 13.25%
1000.0000ms | 1972 - 9.86%
1500.0000ms | 2234 - 11.17%
2000.0000ms | 4611 - 23.05%
2500.0000ms | 4518 - 22.59%
3000.0000ms | 4015 - 20.08%
2963.5520ms | max
ok
(debug@ip-10-244-145-238.ec2.internal)3> bot:test(flashbot, 20000, 'ip-10-244-47-97', 8081).

=INFO REPORT==== 16-Jul-2009::12:06:29 ===
setup: 55302.13ms, good: 20000, bad: 0, run: 63033.07ms
-41.0070ms | min
500.0000ms | 2836 - 14.18%
1000.0000ms | 1733 - 8.67%
1500.0000ms | 2275 - 11.38%
2000.0000ms | 4142 - 20.71%
2500.0000ms | 4555 - 22.78%
3000.0000ms | 4239 - 21.20%
3500.0000ms | 220 - 1.10%
3075.1930ms | max
ok
(debug@ip-10-244-145-238.ec2.internal)4> bot:test(flashbot, 20000, 'ip-10-244-47-97', 8081).

=INFO REPORT==== 16-Jul-2009::12:07:51 ===
setup: 52532.12ms, good: 20000, bad: 0, run: 60196.70ms
-43.1910ms | min
500.0000ms | 2330 - 11.65%
1000.0000ms | 2205 - 11.03%
1500.0000ms | 2158 - 10.79%
2000.0000ms | 3742 - 18.71%
2500.0000ms | 4371 - 21.86%
3000.0000ms | 4630 - 23.15%
3500.0000ms | 564 - 2.82%
3059.0860ms | max
ok

=== 2009-07-16 16:36:34 ===

MacBook Pro 2.93Ghz

http://github.com/tinycode/janus/commit/19c3cc954fdbc5ecb7c950510a80f56423ab9ec9


(debug@biggie.local)3> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::16:10:26 ===
setup: 154206.92ms, good: 20000, bad: 0, run: 157926.75ms
2.4990ms | min
500.0000ms | 2359 - 11.79%
1000.0000ms | 6323 - 31.61%
1500.0000ms | 4934 - 24.67%
2000.0000ms | 5769 - 28.84%
2500.0000ms | 615 - 3.08%
2078.7770ms | max
ok
(debug@biggie.local)4> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::16:16:36 ===
setup: 150305.92ms, good: 20000, bad: 0, run: 154186.14ms
2.1070ms | min
500.0000ms | 2235 - 11.18%
1000.0000ms | 4840 - 24.20%
1500.0000ms | 5497 - 27.48%
2000.0000ms | 5283 - 26.41%
2500.0000ms | 2145 - 10.72%
2185.3810ms | max
ok
(debug@biggie.local)5> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::16:22:07 ===
setup: 201656.95ms, good: 20000, bad: 0, run: 205959.23ms
2.5690ms | min
500.0000ms | 2573 - 12.86%
1000.0000ms | 2704 - 13.52%
1500.0000ms | 5835 - 29.18%
2000.0000ms | 5527 - 27.63%
2500.0000ms | 3361 - 16.80%
2371.7610ms | max
ok

(debug@biggie.local)6> bot:test(flashbot, 20000).

=INFO REPORT==== 16-Jul-2009::16:29:57 ===
setup: 153129.67ms, good: 20000, bad: 0, run: 157174.14ms
3.4600ms | min
500.0000ms | 2682 - 13.41%
1000.0000ms | 3922 - 19.61%
1500.0000ms | 5523 - 27.62%
2000.0000ms | 4728 - 23.64%
2500.0000ms | 3145 - 15.72%
2295.7770ms | max
ok
11 changes: 10 additions & 1 deletion README.textile
Expand Up @@ -14,12 +14,14 @@ h1. Bounty and rules

2) Final proof has to be from EC2, one small instance for the server and one for the bots.

3) {packet, 0}
3) {packet, 0}, -smp disabled

4) TCP, not UDP.

5) No change of the protocol unless I agree to it.

Note that SMP is disabled since Amazon EC2 small instances have a single core.

h1. Installation

Janus requires at least OTP R13B01.
Expand Down Expand Up @@ -77,6 +79,13 @@ grep ulimit ~/.bash_profile
ulimit -n 30720
</code></pre>

Also, you won't be able to go past 1024 clients with Erlang
on Mac OSX, even with kernel poll enabled (+K true).

Edit FD_SETSIZE in /usr/include/sys/select.h, i.e. change
__DARWIN_FD_SETSIZE in /usr/include/sys/_structs.h
and recompile Erlang with --enable-kernel-poll.

On Linux:

<pre><code>
Expand Down
5 changes: 4 additions & 1 deletion src/bot.erl
Expand Up @@ -23,6 +23,8 @@

-export([run/6, test/1, test/2, test/4, publish/5]).

-include_lib("kernel/include/inet.hrl").

-record(state, {
bot,
barrier,
Expand All @@ -47,6 +49,7 @@
run(Bot, Host, Port, Message, Expected, N)
when is_tuple(Message),
is_integer(N) ->
{ok, #hostent{h_addr_list = [Addr | _]}} = inet:gethostbyname(Host),
{ok, Barrier} = barrier:start(counter, N),
State = #state{
bot = Bot,
Expand All @@ -57,7 +60,7 @@ run(Bot, Host, Port, Message, Expected, N)
min = 99999999,
max = 0,
avg = 0,
host = Host,
host = Addr,
port = Port,
message = Message,
expected = Expected,
Expand Down
32 changes: 15 additions & 17 deletions src/pubsub.erl
Expand Up @@ -29,7 +29,7 @@

-record(state, {
topic,
subs = ets:new(subs, [set])
subs = []
}).

publish(Ref, Msg) ->
Expand Down Expand Up @@ -57,6 +57,7 @@ handle_cast(stop, State) ->
handle_cast({subscribe, Pid, Socket}, State) ->
%% automatically unsubscribe when dead
Ref = erlang:monitor(process, Pid),
L = lists:keydelete(Pid, 1, State#state.subs),
Pid ! ack,
ets:insert(State#state.subs, {Pid, Ref, Socket}),
{noreply, State};
Expand All @@ -65,21 +66,19 @@ handle_cast({unsubscribe, Pid}, State) ->
unsubscribe1(Pid, State);

handle_cast({publish, Msg}, State) ->
io:format("info: ~p~n", [ets:info(State#state.subs)]),
io:format("info: ~p~n", [length(State#state.subs)]),
Start = now(),
{struct, L} = Msg,
JSON = {struct, [{<<"timestamp">>, binary_to_list(term_to_binary(now()))}|L]},
Bin = mochijson2:encode(JSON),
%% F = fun({Pid, _}, _) -> gen_server:cast(Pid, Msg1) end,
F = fun({_Pid, _, Socket}, _) ->
gen_tcp:send(Socket, [Bin, 1])
end,
F1 = fun() ->
process_flag(priority, high),
A = now(),
ets:foldr(F, ignore, State#state.subs),
io:format("time: ~p~n", [timer:now_diff(now(), A) / 1000])
end,
spawn_link(F1),
process_flag(priority, high),
ets:foldr(F, ignore, State#state.subs),
io:format("time: ~p~n", [timer:now_diff(now(), Start) / 1000]),
process_flag(priority, normal),
{noreply, State};

handle_cast(Event, State) ->
Expand All @@ -104,13 +103,12 @@ code_change(_OldVsn, State, _Extra) ->
{ok, State}.

unsubscribe1(Pid, State) ->
case ets:lookup(State#state.subs, Pid) of
[{_, Ref}] ->
erlang:demonitor(Ref),
ets:delete(State#state.subs, Pid);
_ ->
ok
case lists:keyfind(Pid, 1, State#state.subs) of
false ->
ok;
{Pid, Ref} ->
erlang:demonitor(Ref)
end,
{noreply, State}.

L = lists:keydelete(Pid, 1, State#state.subs),
{noreply, State#state{subs = L}}.

4 changes: 4 additions & 0 deletions src/t.erl
Expand Up @@ -25,6 +25,10 @@

-include_lib("stdlib/include/ms_transform.hrl").

%%% t:t(lists), t:t([lists, gb_trees]), t:t({lists,reverse}),
%%% t:t([{lists,reverse}, gb_trees]) or any combination thereof
%%% will enable tracing for you. t:ut() will disable it.

ut() ->
dbg:ctp().

Expand Down

0 comments on commit 50da004

Please sign in to comment.