Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add maximum duration option for a tsung test (TSUN-143)

  • Loading branch information...
commit c4355b0edbc0af2253b45ddbf8455b41918374bd 1 parent 239c2c3
@nniclausse nniclausse authored
View
19 doc/user_manual.tex
@@ -918,6 +918,25 @@ \subsubsection{Statically generated users}
session), one starting after 10 minutes, and a last one starting after
11 minutes (using the \userinput{foo} session this time)
+\subsubsection{Duration of the load test}
+
+By default, tsung will end when all started users have finished their
+session. So it can be much longer than the duration of
+arrivalphases. If you want to stop Tsung after a given duration
+(even if phases are not finised or if some sessions are stil actives),
+you can do this with the \varname{duration} attribute in \varname{load}:
+\begin{Verbatim}
+ <load duration="1" unit="hour">
+ <arrivalphase phase="1" duration="10" unit="minute">
+ <users interarrival="2" unit="second"></users>
+ </arrivalphase>
+</load>
+\end{Verbatim}
+
+Currently, the maximum value for duration is a little bit less than 50
+days. \varname{unit} can be \userinput{second}, \userinput{minute} or
+\userinput{hour}.
+
\subsection{Setting options}
\par Default values can be set-up globally: \varname{thinktime} between requests
View
1  include/ts_config.hrl
@@ -35,6 +35,7 @@
-record(config, {
name,
+ duration, % max duration of test (by default: end when all clients are done)
loglevel = ?WARN,
dump = none,
stats_backend,
View
7 src/tsung_controller/ts_config.erl
@@ -160,8 +160,11 @@ parse(Element = #xmlElement{name=monitor, attributes=Attrs},
%%
parse(Element = #xmlElement{name=load, attributes=Attrs}, Conf) ->
- Loop = getAttr(integer, Attrs, loop, 0),
- lists:foldl(fun parse/2, Conf#config{load_loop=Loop},
+ Loop = getAttr(integer, Attrs, loop, 0),
+ IDuration = getAttr(integer, Attrs, duration, 0),
+ Unit = getAttr(string, Attrs, unit, "second"),
+ Duration = to_seconds(Unit, IDuration),
+ lists:foldl(fun parse/2, Conf#config{load_loop=Loop,duration=Duration},
Element#xmlElement.content);
View
14 src/tsung_controller/ts_config_server.erl
@@ -207,6 +207,7 @@ handle_call({read_config, ConfigFile}, _From, State=#state{logdir=LogDir}) ->
%% start the file server (if defined) using a separate process (it can be long)
spawn(?MODULE, start_file_server, [Config]),
NewConfig=loop_load(sort_static(Config#config{sessions=[NewLast]++Sessions})),
+ set_max_duration(Config#config.duration),
{reply, ok, State#state{config=NewConfig, static_users=NewConfig#config.static_users,total_weight = Sum}};
{error, Reason} ->
?LOGF("Error while checking config: ~p~n",[Reason],?EMERG),
@@ -406,6 +407,10 @@ handle_cast(Msg, State) ->
%% {noreply, State, Timeout} |
%% {stop, Reason, State} (terminate/2 is called)
%%--------------------------------------------------------------------
+handle_info({timeout, _Ref, end_tsung}, State) ->
+ ts_mon:abort(),
+ ?LOG("Tsung test max duration reached, exits ! ~n",?EMERG),
+ {stop, normal, State};
handle_info({'EXIT', _Pid, {slave_failure,timeout}}, State) ->
ts_mon:abort(),
?LOG("Abort ! ~n",?EMERG),
@@ -719,3 +724,12 @@ set_nodename(NodeId) when is_integer(NodeId)->
Id++"_"
end,
"tsung"++ CId++ integer_to_list(NodeId).
+
+%% @spec set_max_duration(integer()) -> ok
+%% @doc start a timer for the maximum duration of the load test. The
+%% maximum duration is 49 days
+set_max_duration(0) -> ok; % nothing to do
+set_max_duration(Duration) when Duration =< 4294967 ->
+ ?LOGF("Set max duration of test: ~p s ~n",[Duration],?NOTICE),
+ erlang:start_timer(Duration*1000, self(), end_tsung ).
+
View
2  tsung-1.0.dtd
@@ -55,6 +55,8 @@
<!ELEMENT load (arrivalphase | user)+>
<!ATTLIST load
+ duration NMTOKEN #IMPLIED
+ unit (hour | minute | second) "second"
loop NMTOKEN "0"
>
Please sign in to comment.
Something went wrong with that request. Please try again.