public
anonymous / srv.erl
Last active

  • Download Gist
srv.erl
Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
-module(srv).
 
-behaviour(gen_server).
 
-compile(export_all).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
 
start() ->
gen_server:start({global, ?MODULE}, ?MODULE, [], []).
 
init(_) ->
{ok, []}.
 
handle_call(ping, _From, State) ->
io:format("# pong~n"),
{reply, ok, State};
handle_call(_Request, _From, State) ->
{reply, ok, State}.
 
handle_cast(_Msg, State) ->
{noreply, State}.
 
handle_info(_Info, State) ->
{noreply, State}.
 
terminate(_Reason, _State) ->
ok.
 
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
tst.erl
Erlang
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
-module(tst).
 
-behaviour(gen_server).
 
-compile(export_all).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
 
start(SrvNode) ->
gen_server:start({local, ?MODULE}, ?MODULE, SrvNode, []).
 
init(SrvNode) ->
ping_srv(SrvNode),
{ok, []}.
 
ping_srv(SrvNode) ->
net_adm:ping(SrvNode),
global:sync(),
 
T1 = now(),
gen_server:call({global, srv}, ping),
io:format("# ~p ms.~n", [timer:now_diff(now(), T1)/1000]).
 
handle_call(_Request, _From, State) ->
{reply, ok, State}.
 
handle_cast(_Msg, State) ->
{noreply, State}.
 
handle_info(_Info, State) ->
{noreply, State}.
 
terminate(_Reason, _State) ->
ok.
 
code_change(_OldVsn, State, _Extra) ->
{ok, State}.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.