Skip to content

Commit

Permalink
Measure packet cache and UDP and TCP handoffs.
Browse files Browse the repository at this point in the history
  • Loading branch information
aeden committed Sep 7, 2013
1 parent 5321c5a commit 8bdd3db
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ebin/erldns.app
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application,erldns,
[{description,"Erlang Authoritative DNS Server"},
{vsn,"3afafd3"},
{vsn,"5321c5a"},
{mod,{erldns_app,[]}},
{applications,[kernel,stdlib,inets,crypto,ssl,folsom]},
{start_phases,[{post_start,[]}]},
Expand Down
13 changes: 12 additions & 1 deletion src/erldns_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,22 @@ get_metrics() ->
end, folsom_metrics:get_metrics()).

get_stats() ->
folsom_metrics:get_histogram_statistics(request_handled_histogram).
Histograms = [udp_handoff_histogram, tcp_handoff_histogram, request_handled_histogram],
lists:map(
fun(Name) ->
{Name, folsom_metrics:get_histogram_statistics(Name)}
end, Histograms).

define_metrics() ->
folsom_metrics:new_histogram(udp_handoff_histogram),
folsom_metrics:new_histogram(tcp_handoff_histogram),

folsom_metrics:new_counter(request_throttled_counter),
folsom_metrics:new_meter(request_throttled_meter),
folsom_metrics:new_histogram(request_handled_histogram),

folsom_metrics:new_meter(cache_hit_meter),
folsom_metrics:new_meter(cache_expired_meter),
folsom_metrics:new_meter(cache_miss_meter),

folsom_metrics:get_metrics().
3 changes: 3 additions & 0 deletions src/erldns_packet_cache.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ handle_call({get_packet, Question, _Host}, _From, State) ->
{_,T,_} = erlang:now(),
case T > ExpiresAt of
true ->
folsom_metrics:notify(cache_expired_meter, 1),
{reply, {error, cache_expired}, State};
false ->
folsom_metrics:notify(cache_hit_meter, 1),
{reply, {ok, Response}, State}
end;
_ ->
folsom_metrics:notify(cache_miss_meter, 1),
{reply, {error, cache_miss}, State}
end;

Expand Down
12 changes: 8 additions & 4 deletions src/erldns_tcp_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
code_change/3
]).

% Internal API
-export([handle_request/2]).

-define(SERVER, ?MODULE).

-record(state, {port, socket}).
Expand All @@ -33,9 +36,7 @@ handle_call(_Request, _From, State) ->
handle_cast(_Message, State) ->
{noreply, State}.
handle_info({tcp, Socket, Bin}, State) ->
poolboy:transaction(tcp_worker_pool, fun(Worker) ->
gen_server:call(Worker, {tcp_query, Socket, Bin})
end),
folsom_metrics:histogram_timed_update(tcp_handoff_histogram, ?MODULE, handle_request, [Socket, Bin]),
{noreply, State};
handle_info(_Message, State) ->
{noreply, State}.
Expand All @@ -49,4 +50,7 @@ new_connection(Socket, State) ->
code_change(_PreviousVersion, State, _Extra) ->
{ok, State}.


handle_request(Socket, Bin) ->
poolboy:transaction(tcp_worker_pool, fun(Worker) ->
gen_server:call(Worker, {tcp_query, Socket, Bin})
end).
2 changes: 1 addition & 1 deletion src/erldns_udp_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ handle_info(timeout, State) ->
%lager:info("UDP instance timed out"),
{noreply, State};
handle_info({udp, Socket, Host, Port, Bin}, State) ->
Response = handle_request(Socket, Host, Port, Bin, State),
Response = folsom_metrics:histogram_timed_update(udp_handoff_histogram, ?MODULE, handle_request, [Socket, Host, Port, Bin, State]),
inet:setopts(State#state.socket, [{active, once}]),
Response;
handle_info(_Message, State) ->
Expand Down

0 comments on commit 8bdd3db

Please sign in to comment.