Skip to content

Commit

Permalink
fix computation of NUsers (TSUN-199) (and some use case with arrivalr…
Browse files Browse the repository at this point in the history
…ate)
  • Loading branch information
nniclausse committed Oct 13, 2011
1 parent 90512d4 commit c761377
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 10 deletions.
10 changes: 8 additions & 2 deletions examples/thinks.xml.in
Expand Up @@ -11,8 +11,14 @@
</servers>

<load>
<arrivalphase phase="1" duration="10" unit="minute">
<users interarrival="30" unit="second"></users>
<arrivalphase phase="1" duration="600" unit="second">
<users arrivalrate="2" unit="second"></users>
</arrivalphase>
<arrivalphase phase="2" duration="600" unit="second">
<users arrivalrate="2" unit="minute"></users>
</arrivalphase>
<arrivalphase phase="3" duration="6" unit="hour">
<users arrivalrate="2" unit="hour"></users>
</arrivalphase>
</load>

Expand Down
8 changes: 7 additions & 1 deletion examples/thinks2.xml.in
Expand Up @@ -12,7 +12,13 @@

<load>
<arrivalphase phase="1" duration="10" unit="minute">
<users interarrival="30" unit="second"></users>
<users interarrival="0.5" unit="second"></users>
</arrivalphase>
<arrivalphase phase="2" duration="600" unit="second">
<users interarrival="0.5" unit="minute"></users>
</arrivalphase>
<arrivalphase phase="3" duration="6" unit="hour">
<users interarrival="0.5" unit="hour"></users>
</arrivalphase>
</load>

Expand Down
23 changes: 23 additions & 0 deletions src/test/ts_test_config.erl
Expand Up @@ -110,6 +110,29 @@ config_thinktime2_test() ->
random:seed(), % reinit seed for others tests
?assertMatch({random,1000}, Req).

config_arrivalrate_test() ->
myset_env(),
ok = ts_config_server:read_config("./examples/thinks.xml"),
{ok, {[Phase1,Phase2, Phase3],_,_} } = ts_config_server:get_client_config("localhost"),
RealDur = 10 * 60 * 1000,
RealNU = 1200,
RealIntensity = 2 / 1000,
?assertEqual({RealIntensity,RealNU,RealDur}, Phase1),
?assertEqual({RealIntensity/60, RealNU div 60,RealDur}, Phase2),
?assertEqual({RealIntensity/3600,12,RealDur*36}, Phase3).

config_interarrival_test() ->
myset_env(),
ok = ts_config_server:read_config("./examples/thinks2.xml"),
{ok, {[Phase1,Phase2, Phase3],_,_} } = ts_config_server:get_client_config("localhost"),
RealDur = 10 * 60 * 1000,
RealNU = 1200,
RealIntensity = 2 / 1000,
?assertEqual({RealIntensity,RealNU,RealDur}, Phase1),
?assertEqual({RealIntensity/60,RealNU div 60,RealDur}, Phase2),
?assertEqual({RealIntensity/3600,12,RealDur*36}, Phase3).


read_config_maxusers_test() ->
read_config_maxusers({5,15},10,"./src/test/thinkfirst.xml").

Expand Down
13 changes: 9 additions & 4 deletions src/tsung_controller/ts_config.erl
Expand Up @@ -271,7 +271,7 @@ parse(Element = #xmlElement{name=arrivalphase, attributes=Attrs},
Phase = getAttr(integer,Attrs, phase),
IDuration = getAttr(integer, Attrs, duration),
Unit = getAttr(string,Attrs, unit, "second"),
D = 1000 * to_seconds(Unit, IDuration),
D = to_milliseconds(Unit, IDuration),
case lists:keysearch(Phase,#arrivalphase.phase,AList) of
false ->
lists:foldl(fun parse/2,
Expand All @@ -292,7 +292,7 @@ parse(Element = #xmlElement{name=user, attributes=Attrs},
Start = getAttr(float_or_integer,Attrs, start_time),
Unit = getAttr(string,Attrs, unit, "second"),
Session = getAttr(string,Attrs, session),
Delay = to_seconds(Unit,Start)*1000,
Delay = to_milliseconds(Unit,Start),
NewUsers= Users++[{Delay,Session}],
lists:foldl(fun parse/2, Conf#config{static_users = NewUsers},
Element#xmlElement.content);
Expand All @@ -310,9 +310,9 @@ parse(Element = #xmlElement{name=users, attributes=Attrs},
{[],[]} ->
exit({invalid_xml,"arrival or interarrival must be specified"});
{[], Rate} when Rate > 0 ->
to_seconds(Unit,Rate) / 1000;
Rate / to_milliseconds(Unit,1);
{InterArrival,[]} when InterArrival > 0 ->
1/(1000 * to_seconds(Unit,InterArrival));
1/to_milliseconds(Unit,InterArrival);
{_Value, _Value2} ->
exit({invalid_xml,"arrivalrate and interarrival can't be defined simultaneously"})
end,
Expand Down Expand Up @@ -883,6 +883,11 @@ to_seconds("minute", Val)-> Val*60;
to_seconds("hour", Val)-> Val*3600;
to_seconds("millisecond", Val)-> Val/1000.

to_milliseconds("second", Val)-> Val*1000;
to_milliseconds("minute", Val)-> Val*60000;
to_milliseconds("hour", Val)-> Val*3600000;
to_milliseconds("millisecond", Val)-> Val.

%%%----------------------------------------------------------------------
%%% Function: get_default/2
%%%----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/tsung_controller/ts_config_server.erl
Expand Up @@ -539,13 +539,13 @@ choose_session([#session{popularity=P} | SList], Rand, Cur) ->
get_client_cfg(Arrival=#arrivalphase{duration = Duration,
intensity= PhaseIntensity,
curnumber= CurNumber,
maxnumber= MaxNumber },
maxnumber= MaxNumber },
{TotalWeight,Client,IsLast} ) ->
Weight = Client#client.weight,
ClientIntensity = PhaseIntensity * Weight / TotalWeight,
NUsers = round(case MaxNumber of
infinity -> %% only use the duration to set the number of users
Duration * 1000 * ClientIntensity;
Duration * ClientIntensity;
_ ->
TmpMax = case {IsLast,CurNumber == MaxNumber} of
{true,_} ->
Expand All @@ -555,7 +555,7 @@ get_client_cfg(Arrival=#arrivalphase{duration = Duration,
{false,false} ->
lists:max([1,trunc(MaxNumber * Weight / TotalWeight)])
end,
lists:min([TmpMax, Duration*1000*ClientIntensity])
lists:min([TmpMax, Duration*ClientIntensity])
end),
?LOGF("New arrival phase ~p for client ~p (last ? ~p): will start ~p users~n",
[Arrival#arrivalphase.phase,Client#client.host, IsLast,NUsers],?NOTICE),
Expand Down

0 comments on commit c761377

Please sign in to comment.