Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Implement scripts to start multiple replicas of FMKe #41

Merged
merged 36 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
70f7a2e
trying out megaload to test fmk
peterzeller Nov 21, 2016
c2e0283
python script for running megaload
peterzeller Nov 22, 2016
1307107
implement dynamic http ports, test parsing json body for megaload
goncalotomas Nov 24, 2016
7d91e31
adding scripts to start multi fmk
aletomsic Nov 24, 2016
0f3b403
making antidote IP and port configurable
aletomsic Nov 24, 2016
cafe56d
Merge branch 'dynamic-http-port' into multi-fmk2
aletomsic Nov 24, 2016
accd650
scritps for multi fmk instances on a single machine working
aletomsic Nov 24, 2016
8192de3
scritps for multi fmk instances on a single machine working
aletomsic Nov 24, 2016
26fe645
Merge branch 'multi-fmk2' into megaload-test-p
peterzeller Nov 24, 2016
5816e15
added scripts to start multiple megaload loaders
peterzeller Nov 24, 2016
13faea6
removed debug message
peterzeller Nov 24, 2016
10ef0b4
megaload: printing stats
peterzeller Nov 25, 2016
a4e16af
fixed Makefile: choose fmk release
peterzeller Nov 29, 2016
3b894e8
trying out megaload to test fmk
peterzeller Nov 21, 2016
b192371
python script for running megaload
peterzeller Nov 22, 2016
d1192c6
2nd attempt to rebase
goncalotomas Dec 6, 2016
bdbe4eb
adding scripts to start multi fmk
aletomsic Nov 24, 2016
97f7b4e
making antidote IP and port configurable
aletomsic Nov 24, 2016
2ba7898
scritps for multi fmk instances on a single machine working
aletomsic Nov 24, 2016
f36f3b4
scritps for multi fmk instances on a single machine working
aletomsic Nov 24, 2016
8a62b12
added scripts to start multiple megaload loaders
peterzeller Nov 24, 2016
4283b7b
removed debug message
peterzeller Nov 24, 2016
ea130bb
megaload: printing stats
peterzeller Nov 25, 2016
091dbc5
fixed Makefile: choose fmk release
peterzeller Nov 29, 2016
2389de6
trying out megaload to test fmk
peterzeller Nov 21, 2016
74ed194
python script for running megaload
peterzeller Nov 22, 2016
a50ee56
implement dynamic http ports, test parsing json body for megaload
goncalotomas Nov 24, 2016
7a62786
adding scripts to start multi fmk
aletomsic Nov 24, 2016
bfbb957
making antidote IP and port configurable
aletomsic Nov 24, 2016
86c33b9
scritps for multi fmk instances on a single machine working
aletomsic Nov 24, 2016
6f4bc71
scritps for multi fmk instances on a single machine working
aletomsic Nov 24, 2016
db4cb07
removed debug message
peterzeller Nov 24, 2016
8e566e1
rebase with master
goncalotomas Dec 6, 2016
060138a
Merge remote-tracking branch 'origin' into multi-fmk2
goncalotomas Dec 6, 2016
47cc5cd
millionth attempt to rebase
goncalotomas Dec 6, 2016
cf5f64e
fixed merge-conflict in script
peterzeller Dec 6, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ erl_crash.dump
.rebar
logs
_build
deps/
TEST-*
rebar3.crashdump
tests/
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ compile:
mv ${CLIENT}.beam ${EBIN}/

rel:
rm -rf _build/default/rel/fmk/
${REBAR} release
rm -rf _build/default/rel/
${REBAR} release -n fmk

relclean:
rm -rf _build/default/rel
Expand All @@ -24,4 +24,4 @@ bench: compile
-Rscript --vanilla ${BENCH}/priv/summary.r -i tests/current

console: rel
./_build/default/rel/fmk/bin/fmk console
./_build/default/rel/fmk/bin/env console
11 changes: 11 additions & 0 deletions bin/all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

export RELX_REPLACE_OS_VARS=true
i=$1
echo "stopping FMKe instances..."
./bin/stop-nodes.sh ${i}
echo "cleanning old FMKe releases and building new ones..."
./bin/build-releases.sh ${i}
echo "launching FMKe releases..."
./bin/launch-nodes.sh ${i}

8 changes: 8 additions & 0 deletions bin/build-releases.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

export RELX_REPLACE_OS_VARS=true
make relclean
for i in `seq 1 $1`;
do
./rebar3 release -n fmk${i}
done
86 changes: 86 additions & 0 deletions bin/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/bash

# HTTP port.
if [ -z "$HTTP_PORT" ]; then
export HTTP_PORT=9090
fi

# HTTP IP address.
if [ -z "$IP" ]; then
export IP="127.0.0.1"
fi

# Antidote instance port.
if [ -z "$ANTIDOTE_PB_PORT" ]; then
export ANTIDOTE_PB_PORT=8087
fi

# Antidote instance IP address.
if [ -z "$ANTIDOTE_ADDRESS" ]; then
export ANTIDOTE_ADDRESS="127.0.0.1"
fi

# Receive the host name from the parameters
if [ -z "$INSTANCE_NAME" ]; then
export INSTANCE_NAME=fmk
fi

# Choose the hostname for the epmd long name if the hostname exists
# and if it resolves through the resolver; using a resolvable name
# that's only resolvable with resolv.conf won't work for long names.
if [ ! -z "$HOSTNAME" ]; then
if /usr/bin/dig ${HOSTNAME} | grep -q 'NXDOMAIN'
export NODE_NAME=${INSTANCE_NAME}@${HOSTNAME}
then
export NODE_NAME=${INSTANCE_NAME}@${IP}
fi
fi
# Else, default to IP.
if [ -z "$NODE_NAME" ]; then
export NODE_NAME=${INSTANCE_NAME}@${IP}
fi
#
# # Handoff port.
# export HANDOFF_PORT=${PORT1}
#
# # Protocol buffer port.
# export PB_PORT=${PORT2}
#
# # Pub/sub port.
# export PUBSUB_PORT=${PORT3}
#
# # Logeader port.
# export LOGREADER_PORT=${PORT4}
#fi

# Assume 127.0.0.1 as bind host.
if [ -z "$IP" ]; then
echo "IP address not set; defaulting to 127.0.0.1."
export IP=127.0.0.1
fi

if [ -z "$NODE_NAME" ]; then
export NODE_NAME=${INSTANCE_NAME}@${IP}
fi

if [ -z "$COOKIE" ]; then
export COOKIE=antidote
fi

export RELX_REPLACE_OS_VARS=true

echo "PORT0: ${PORT0}"
echo "PORT1: ${PORT1}"
echo "PORT2: ${PORT2}"
echo "PORT3: ${PORT3}"
echo "PORT4: ${PORT4}"


echo "NODE_NAME: ${NODE_NAME}"
echo "COOKIE: ${COOKIE}"
echo "IP: ${IP}"
echo "IP: ${IP}"
echo "HTTP_PORT: ${HTTP_PORT}"

RELNAME="`dirname \"$0\"`"/${INSTANCE_NAME}
exec ${RELNAME} "$@"
7 changes: 7 additions & 0 deletions bin/launch-nodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

export RELX_REPLACE_OS_VARS=true
for i in `seq 1 $1`;
do
HTTP_PORT=9${i}90 INSTANCE_NAME=fmk${i} ANTIDOTE_PB_PORT=8${i}87 COOKIE=antidote _build/default/rel/fmk${i}/bin/env foreground &
done
7 changes: 7 additions & 0 deletions bin/stop-nodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

export RELX_REPLACE_OS_VARS=true
for i in `seq 1 $1`;
do
_build/default/rel/fmk${i}/bin/fmk${i} stop
done
5 changes: 5 additions & 0 deletions config/vars.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%%
%% etc/vm.args
%%
{node, "fmk@127.0.0.1"}.
{cookie, "antidote"}.
4 changes: 2 additions & 2 deletions config/vm.args
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## Name of the node
-name fmk@127.0.0.1
-name ${NODE_NAME}

## Cookie for distributed erlang
-setcookie antidote
-setcookie ${COOKIE}

## Directories with compiled modules
-pa ./_build/default/lib/*/ebin
Expand Down
3 changes: 2 additions & 1 deletion include/fmk.hrl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-define(ANTIDOTE, 'antidote@127.0.0.1').
%%-define(ANTIDOTE, 'antidote@127.0.0.1').
-define(DEFAULT_ANTIDOTE_PORT, 8087).
-define(DEFAULT_ANTIDOTE_ADDRESS, "127.0.0.1").
-define (DEFAULT_FMKE_HTTP_PORT, 9090).
-define (APP, fmke).
-define (VAR_ANTIDOTE_PB_PID, antidote_pb_pid).
-define (VAR_ANTIDOTE_PB_ADDRESS, antidote_pb_address).
Expand Down
16 changes: 13 additions & 3 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@
{antidote_pb, {git, "https://github.com/SyncFree/antidote_pb", {tag, "erlang19"}}},
{mochiweb, {git, "https://github.com/mochi/mochiweb", {tag, "master"}}},
{poolboy, {git, "https://github.com/devinus/poolboy", {tag, "1.5.1"}}},
{cowboy, {git, "https://github.com/ninenines/cowboy", {tag, "master"}}}
{cowboy, {git, "https://github.com/ninenines/cowboy", {tag, "master"}}},
{jsx, {git, "https://github.com/talentdeficit/jsx.git", {tag, "v2.8.0"}}}
]}.

{relx, [{release, {fmk, "0.0.1"},
[fmk]},
{relx, [
{release, {fmk, "0.0.1"}, [fmk]},
{release, {fmk1, "0.0.1"}, [fmk]},
{release, {fmk2, "0.0.1"}, [fmk]},
{release, {fmk3, "0.0.1"}, [fmk]},
{release, {fmk4, "0.0.1"}, [fmk]},
{release, {fmk5, "0.0.1"}, [fmk]},
{vm_args, "config/vm.args"},
{dev_mode, true},
{include_erts, false},

{overlay, [
{copy, "bin/env", "bin"}]},

{overlay_vars, "config/vars.config"},
{extended_start_script, true}]}.
4 changes: 2 additions & 2 deletions runBenchLocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ make all

# Start FMK:
echo "Starting FMK"
_build/default/rel/fmk/bin/fmk start
_build/default/rel/fmk/bin/env start

# wait for FMK to start (TODO better way?)
echo "Waiting for FMK to start"
Expand All @@ -76,7 +76,7 @@ echo "Benchmark done"

# Stop FMK
echo "Stopping FMK"
_build/default/rel/fmk/bin/fmk stop
_build/default/rel/fmk/bin/env stop

if [ -n "$ANTIDOTE_FOLDER" ]; then
# Stop Antidote
Expand Down
8 changes: 4 additions & 4 deletions src/antidote_pool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ with_connection(Fun) ->
%%% Supervisor callbacks
%%%===================================================================

init(Options) ->
Hostname = proplists:get_value(hostname, Options, "localhost"),
Port = proplists:get_value(port, Options, 8087),
init(_Options) ->
AntidotePort = list_to_integer(fmk_config:get(antidote_port, "8087")),
AntidoteAddress = fmk_config:get(antidote_address,'127.0.0.1'),
PoolArgs = [
{name, {local, antidote_connection_pool}},
{worker_module, ?MODULE},
{size, 15},
{max_overflow, 0}
],
WorkerArgs = [Hostname, Port],
WorkerArgs = [AntidoteAddress, AntidotePort],
PoolSpec = poolboy:child_spec(antidote_connection_pool, PoolArgs, WorkerArgs),
{ok, {{one_for_one, 10, 10}, [PoolSpec]}}.

Expand Down
5 changes: 3 additions & 2 deletions src/fmk.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
antidote_pb,
riak_pb,
poolboy,
cowboy
cowboy,
jsx
]},
{env,[]},

{modules, []},

{maintainers, []},
Expand Down
37 changes: 20 additions & 17 deletions src/fmk_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@
%%====================================================================

start(_StartType, _StartArgs) ->
Dispatch = cowboy_router:compile([
{'_', [
{"/prescriptions/[:id]", prescription_handler, []},
{"/patients/[:id]", patient_handler, []},
{"/pharmacies/[:id]", pharmacy_handler, []},
{"/facilities/[:id]", facility_handler, []},
{"/treatments/[:id]", treatment_handler, []},
{"/events/[:id]", event_handler, []},
{"/staff/[:id]", staff_handler, []}
]}
]),
{ok, _} = cowboy:start_clear(http, 100, [{port, 9090}], #{
env => #{dispatch => Dispatch}
}),
case fmk_sup:start_link() of
Result = case fmk_sup:start_link() of
{ok, Pid} ->
case open_antidote_socket() of
ok -> {ok, Pid};
_ -> {error, cannot_open_protobuff_socket}
end;
{error, Reason} ->
{error, Reason}
end.
end,
Dispatch = cowboy_router:compile([
{'_', [
{"/prescriptions/[:id]", prescription_handler, []},
{"/patients/[:id]", patient_handler, []},
{"/pharmacies/[:id]", pharmacy_handler, []},
{"/facilities/[:id]", facility_handler, []},
{"/treatments/[:id]", treatment_handler, []},
{"/events/[:id]", event_handler, []},
{"/staff/[:id]", staff_handler, []}
]}
]),
HttpPort = list_to_integer(fmk_config:get(http_port,9090)),
{ok, _} = cowboy:start_clear(http, 100, [{port, HttpPort}], #{
env => #{dispatch => Dispatch}
}),
Result.

%%--------------------------------------------------------------------
stop(_State) ->
Expand All @@ -55,8 +57,9 @@ set_application_variable(ApplicationVariable, EnvironmentVariable, EnvironmentDe
Value.

open_antidote_socket() ->
set_application_variable(http_port,"HTTP_PORT",?DEFAULT_FMKE_HTTP_PORT),
set_application_variable(antidote_address,"ANTIDOTE_ADDRESS",?DEFAULT_ANTIDOTE_ADDRESS),
set_application_variable(antidote_port,"ANTIDOTE_PORT",?DEFAULT_ANTIDOTE_PORT),
set_application_variable(antidote_port,"ANTIDOTE_PB_PORT",?DEFAULT_ANTIDOTE_PORT),
AntidoteNodeAddress = fmk_config:get_env(?VAR_ANTIDOTE_PB_ADDRESS,?DEFAULT_ANTIDOTE_ADDRESS),
AntidoteNodePort = fmk_config:get_env(?VAR_ANTIDOTE_PB_PORT,?DEFAULT_ANTIDOTE_PORT),
{ok, _} =antidote_pool:start([{hostname, AntidoteNodeAddress}, {port, AntidoteNodePort}]),
Expand Down
15 changes: 10 additions & 5 deletions src/patient_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ handle_req(<<"GET">>, false, Req) ->
get_patient(Req).

create_patient(Req) ->
{ok, [{<<"id">>, Id},
{<<"name">>, Name},
{<<"address">>, Address}
], _Req0} = cowboy_req:read_urlencoded_body(Req),
IntegerId = binary_to_integer(Id),
{ok, Data, _Req2} = cowboy_req:read_body(Req),
Json = jsx:decode(Data),
Id = proplists:get_value(<<"id">>, Json),
Name = proplists:get_value(<<"name">>, Json),
Address = proplists:get_value(<<"address">>, Json),
IntegerId =
if
is_binary(Id) -> list_to_integer(binary_to_list(Id));
true -> Id
end,
case IntegerId =< ?MIN_ID of
true ->
cowboy_req:reply(400, [], ?ERR_INVALID_PATIENT_ID, Req);
Expand Down
1 change: 1 addition & 0 deletions test/basho_bench_driver_fmkclient.erl
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,6 @@ run(get_prescription, _GeneratedKey, _GeneratedValue, State) ->
Error -> {error, Error, State}
end.


run_op(FmkNode,Op,Params) ->
rpc:call(FmkNode,fmk_core,Op,Params).
29 changes: 29 additions & 0 deletions test/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[{"test" : {"id" : "FMKeTest",
"phases" : ["Phase1"],
"plugins" : ["LocalFMKeNode"]
}},

{"plugin" : {"id" : "LocalFMKeNode",
"plugin_info" : {"http-plugin" : {"servers" : [{"host" : "localhost",
"port" : 9090,
"ssl" : false}
],
"stats_per_url" : true
}}
}},

{"phase" : {"id" : "Phase1",
"arrival_rate" : 10,
"duration" : 60,
"concurrent_scenarios" : 250,
"rate" : 500,
"scenarios" : [{"Scenario1" : 1}]}},

{"scenario" : {"id" : "Scenario1",
"keepalive" : true,
"actions" : [ {"http-request" : {"plugin_id" : "LocalFMKeNode",
"method" : "GET",
"path" : "/patients/1"
}
}]}}
]