Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-module(elasticsearch).
-export([autocomplete/1, autocomplete/0,
search/1, search/0,
start/0,
stop/0,
loop/1]).
-on_load(start/0).
%% Return an autocomplete request
autocomplete() ->
autocomplete(true).
autocomplete(_) ->
elasticsearch_autocomplete ! {next, self()},
receive
{ok, Json} -> Json
end.
%% Return a search request
search() ->
search(true).
search(_) ->
elasticsearch_search ! {next, self()},
receive
{ok, Json} -> Json
end.
%% Start/stop file processes
start() ->
true = start(elasticsearch_autocomplete, "/data/tsung/autocomplete4"),
true = start(elasticsearch_search, "/data/tsung/top"),
ok.
start(Process, Table) ->
register(Process,
spawn(?MODULE, loop, [Table])).
stop() ->
true = stop(elasticsearch_autocomplete) and
stop(elasticsearch_search),
ok.
stop(Process) ->
Process ! {kill, self()},
receive
ok -> true;
_ -> false
end.
%% Main loop for file processes
loop(Table) ->
{ok, Ref} = file:open(Table, [read]),
loop(Ref, Table).
loop(Ref, Table) ->
receive
{next, From} ->
send_next_line(Ref, Table, From);
{kill, From} ->
From ! ok
end.
send_next_line(Ref, Table, From) ->
R = file:read_line(Ref),
case R of
{ok, Line} ->
send_next_line(Ref, Table, From, Line);
eof ->
ok = file:close(Ref),
{ok, NRef} = file:open(Table, [read]),
send_next_line(NRef, Table, From)
end.
send_next_line(Ref, Table, From, Line) ->
NLine = string:strip(Line),
case NLine of
"" ->
send_next_line(Ref, Table, From);
_ ->
From ! {ok, NLine},
loop(Ref, Table)
end.
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
<clients>
<client host="bench-02" maxusers="15000" cpu="4"/>
<client host="bench-03" maxusers="15000" cpu="4"/>
<client host="bench-04" maxusers="15000" cpu="4"/>
<client host="bench-05" maxusers="15000" cpu="4"/>
<client host="bench-06" maxusers="15000" cpu="4"/>
<client host="bench-07" maxusers="15000" cpu="4"/>
<client host="bench-08" maxusers="15000" cpu="4"/>
<client host="bench-09" maxusers="15000" cpu="4"/>
</clients>
<servers>
<server host="es-18" port="9200" type="tcp"></server>
<server host="es-19" port="9200" type="tcp"></server>
<server host="es-20" port="9200" type="tcp"></server>
<server host="es-21" port="9200" type="tcp"></server>
<server host="es-22" port="9200" type="tcp"></server>
<server host="es-23" port="9200" type="tcp"></server>
<server host="es-24" port="9200" type="tcp"></server>
<server host="es-25" port="9200" type="tcp"></server>
<server host="es-26" port="9200" type="tcp"></server>
<server host="es-27" port="9200" type="tcp"></server>
<server host="es-28" port="9200" type="tcp"></server>
<server host="es-29" port="9200" type="tcp"></server>
<server host="es-30" port="9200" type="tcp"></server>
</servers>
<monitoring>
<monitor host="es-18" type="snmp"></monitor>
<monitor host="es-19" type="snmp"></monitor>
<monitor host="es-20" type="snmp"></monitor>
<monitor host="es-21" type="snmp"></monitor>
<monitor host="es-22" type="snmp"></monitor>
<monitor host="es-23" type="snmp"></monitor>
<monitor host="es-24" type="snmp"></monitor>
<monitor host="es-25" type="snmp"></monitor>
<monitor host="es-26" type="snmp"></monitor>
<monitor host="es-27" type="snmp"></monitor>
<monitor host="es-28" type="snmp"></monitor>
<monitor host="es-29" type="snmp"></monitor>
<monitor host="es-30" type="snmp"></monitor>
</monitoring>
<load>
<arrivalphase phase="0" duration="30" unit="second">
<users arrivalrate="1000" unit="second"></users>
</arrivalphase>
<arrivalphase phase="1" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="2" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="3" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="4" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="5" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="6" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="7" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="8" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="9" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
<arrivalphase phase="10" duration="30" unit="second">
<users maxnumber="5000" arrivalrate="500" unit="second"></users>
</arrivalphase>
</load>
<options>
<option type="ts_http" name="user_agent">
<user_agent probability="100">Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36</user_agent>
</option>
</options>
<sessions>
<session name="elasticsearch" probability="100" type="ts_http">
<for from="1" to="10000" incr="1" var="counter">
<transaction name="autocomplete">
<request subst="true">
<http url="/autocomplete/suggest/_search" method="POST" version="1.1"
contents="%%elasticsearch:autocomplete%%"
content_type="application/json">
</http>
</request>
</transaction>
<thinktime min="1" max="2" random="true"/>
<transaction name="search">
<request subst="true">
<http url="/video/video/_search" method="POST" version="1.1"
contents="%%elasticsearch:search%%"
content_type="application/json">
</http>
</request>
</transaction>
<thinktime min="1" max="4" random="true"/>
</for>
</session>
</sessions>
</tsung>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.