src/modules/async/doc/async_admin.xml
bf056081
 <?xml version="1.0" encoding='ISO-8859-1'?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
 
 <!-- Include general documentation entities -->
6deb5fcf
 <!ENTITY % docentities SYSTEM "../../../../doc/docbook/entities.xml">
bf056081
 %docentities;
 
 ]>
 <!-- Module User's Guide -->
 
 <chapter>
15731d40
 
bf056081
 	<title>&adminguide;</title>
15731d40
 
bf056081
 	<section>
 	<title>Overview</title>
 	<para>
6339389b
 		This module provides asynchronous operations for handling SIP requests
 		in the configuration file.
bf056081
 	</para>
 	<para>
6339389b
 		Async uses t_suspend() and t_continue() from the TM and TMX modules.
bf056081
 	</para>
 	<para>
b68fade2
 		Note that after invoking the asynchronous operation, the processing
15731d40
 		will continue later in another application process. Therefore variables
6339389b
 		stored in private memory should not be used, try to use shared memory if you
 		want to get values after the processing is resumed (e.g., $avp(...),
42620ff1
 		$xavp(...), $shv(...), htable $sht(...)).
bf056081
 	</para>
 	</section>
 
 	<section>
 	<title>Dependencies</title>
 	<section>
 		<title>&kamailio; Modules</title>
 		<para>
 		The following modules must be loaded before this module:
 			<itemizedlist>
 			<listitem>
 			<para>
 				<emphasis>tm</emphasis> - transaction management.
 			</para>
4463258d
 			</listitem>
 			<listitem>
6339389b
 			<para>
 				<emphasis>tmx</emphasis> - transaction management extensions.
 			</para>
bf056081
 			</listitem>
 			</itemizedlist>
 		</para>
 	</section>
 	<section>
 		<title>External Libraries or Applications</title>
 		<para>
 		The following libraries or applications must be installed before running
 		&kamailio; with this module loaded:
 			<itemizedlist>
 			<listitem>
 			<para>
 				<emphasis>None</emphasis>
 			</para>
 			</listitem>
 			</itemizedlist>
 		</para>
 	</section>
 	</section>
 	<section>
9114eebc
 	<title>Parameters</title>
eb163386
 	<section id="async.p.workers">
bf056081
 		<title><varname>workers</varname> (int)</title>
 		<para>
6339389b
 			Number of worker processes to be started to handle the asynchronous
15731d40
 			tasks for async_route() and async_sleep().
bf056081
 		</para>
 		<para>
 		<emphasis>
 			Default value is 1.
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>workers</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
 modparam("async", "workers", 2)
 ...
ce710ce1
 </programlisting>
 		</example>
 	</section>
eb163386
 	<section id="async.p.ms_timer">
ce710ce1
 		<title><varname>ms_timer</varname> (int)</title>
 		<para>
 			Enables millisecond timer for async_ms_sleep() and async_ms_route() functions.
7cc2d316
 			The integer value is the timer resolution in milliseconds. A smaller timer
 			resultion will generate a higher load on the system. If you set ms_timer
 			to 1 you will get a timer with 1 millisecond resultion, a setting of 20
 			provides a resultion of 20ms.
ce710ce1
 		</para>
 		<para>
 		<emphasis>
 			Default value is 0.
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>ms_timer</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
7cc2d316
 modparam("async", "ms_timer", 10)
ce710ce1
 ...
bf056081
 </programlisting>
 		</example>
 	</section>
 	</section>
 
 	<section>
9114eebc
 	<title>Functions</title>
272b2373
 	<section id="async.f.async_route">
124a5b16
 		<title>
31b97e44
 		<function moreinfo="none">async_route(routename, seconds)</function>
124a5b16
 		</title>
 		<para>
6339389b
 		Simulate a sleep of 'seconds' and then continue the processing of the SIP
31b97e44
 		request with the route[routename]. In case of internal errors, the
 		function returns false, otherwise the function exits the execution of
6339389b
 		the script at that moment (return 0 behaviour).
31b97e44
 		</para>
 		<para>
 		The routename parameter can be a static string or a dynamic string
 		value with config variables.
 		</para>
 		<para>
6339389b
 		The sleep parameter represent the number of seconds to suspend the
 		processing of a SIP request. Maximum value is 100. The parameter can be
 		a static integer or a variable holding an integer.
31b97e44
 		</para>
 		<para>
 		Since the SIP request handling is resumed in another process,
6339389b
 		the config file execution state is practically lost. Therefore beware
31b97e44
 		that the execution of config after resume will end once the
 		route[routename] is finished.
 		</para>
22278ed6
 		<para>
 		This function can be used from REQUEST_ROUTE.
5176f66a
 		</para>
31b97e44
 		<example>
93a0a29f
 		<title><function>async_route</function> usage</title>
31b97e44
 		<programlisting format="linespecific">
 ...
15731d40
 request_route {
     ...
     async_route("RESUME", "4");
     ...
 }
31b97e44
 route[RESUME] {
    send_reply("404", "Not found");
    exit;
 }
 ...
ce710ce1
 </programlisting>
124a5b16
 		</example>
ce710ce1
 	</section>
 	<section id="async.f.async_ms_route">
124a5b16
 		<title>
ce710ce1
 		<function moreinfo="none">async_ms_route(routename, milliseconds)</function>
124a5b16
 		</title>
 		<para>
ce710ce1
 		Simulate a sleep of 'milliseconds' and then continue the processing of the SIP
 		request with the route[routename]. In case of internal errors, the
 		function returns false, otherwise the function exits the execution of
 		the script at that moment (return 0 behaviour).
 		This function works only if the ms_timer parameter has a value greater then 0.
 		</para>
 		<para>
 		The routename parameter can be a static string or a dynamic string
 		value with config variables.
 		</para>
 		<para>
 		The sleep parameter represent the number of milliseconds to suspend the
 		processing of a SIP request. Maximum value is 30000 (30 sec). The parameter can be
 		a static integer or a variable holding an integer.
 		</para>
 		<para>
 		Since the SIP request handling is resumed in another process,
 		the config file execution state is practically lost. Therefore beware
 		that the execution of config after resume will end once the
 		route[routename] is finished.
 		</para>
 		<para>
 		This function can be used from REQUEST_ROUTE.
 		</para>
 		<example>
 		<title><function>async_ms_route</function> usage</title>
 		<programlisting format="linespecific">
 ...
 request_route {
     ...
     async_ms_route("RESUME", "250");
     ...
 }
 route[RESUME] {
    send_reply("404", "Not found");
    exit;
 }
 ...
31b97e44
 </programlisting>
124a5b16
 		</example>
31b97e44
 	</section>
 
272b2373
 	<section id="async.f.async_sleep">
124a5b16
 		<title>
bf056081
 		<function moreinfo="none">async_sleep(seconds)</function>
124a5b16
 		</title>
 		<para>
bf056081
 		Simulate a sleep of 'seconds' and then continue the processing of SIP
 		request with the next action. In case of internal errors, the function
6339389b
 		returns false.
bf056081
 		</para>
 		<para>
6339389b
 		The sleep parameter represent the number of seconds to suspend the
bf056081
 		processing of SIP request. Maximum value is 100. The parameter can be
6339389b
 		a static integer or a variable holding an integer.
bf056081
 		</para>
22278ed6
 		<para>
 		This function can be used from REQUEST_ROUTE.
5176f66a
 		</para>
bf056081
 		<example>
 		<title><function>async_sleep</function> usage</title>
 		<programlisting format="linespecific">
 ...
 async_sleep("4");
 send_reply("404", "Not found");
 exit;
 ...
272b2373
 </programlisting>
124a5b16
 		</example>
272b2373
 	</section>
 
ce710ce1
 	<section id="async.f.async_ms_sleep">
124a5b16
 		<title>
ce710ce1
 		<function moreinfo="none">async_ms_sleep(milliseconds)</function>
124a5b16
 		</title>
 		<para>
ce710ce1
 		Simulate a sleep of 'milliseconds' and then continue the processing of SIP
 		request with the next action. In case of internal errors, the function
 		returns false.
 		This function works only if the ms_timer parameter has a value greater then 0.
 		</para>
 		<para>
 		The sleep parameter represent the number of milliseconds to suspend the
 		processing of SIP request. Maximum value is 30000 (30 sec). The parameter can be
 		a static integer or a variable holding an integer.
 		</para>
 		<para>
 		This function can be used from REQUEST_ROUTE.
 		</para>
 		<example>
 		<title><function>async_ms_sleep</function> usage</title>
 		<programlisting format="linespecific">
 ...
 route[REQUESTSHAPER] {
124a5b16
 	$var(res) = http_connect("leakybucket",
 			"/add?key=$fd", $null, $null,"$avp(delay)");
 	$var(d) = $(avp(delay){s.int});
 	if ($var(d) &gt; 0) {
ce710ce1
 		# Delay the request by $avp(delay) ms
 		async_ms_sleep("$var(d)");
 		if (!t_relay()) {
 			sl_reply_error();
 		}
 		exit;
124a5b16
 	}
ce710ce1
 	# No delay
 	if (!t_relay()) {
 		sl_reply_error();
 	}
124a5b16
 	exit;
ce710ce1
 }
 ...
 </programlisting>
124a5b16
 		</example>
ce710ce1
 	</section>
 
272b2373
 	<section id="async.f.async_task_route">
124a5b16
 		<title>
272b2373
 		<function moreinfo="none">async_task_route(routename)</function>
124a5b16
 		</title>
 		<para>
272b2373
 		Continue the processing of the SIP request with the route[routename]
 		in one of the processes from core asynchronous framework. The core
 		parameter async_workers has to be set to enable asynchronous
 		framework. The task is executed as soon as a process from asynchronous
 		framework is idle, there is no wait time for the task like for
 		async_route(...).
06557a25
 		</para>
 		<para>
 		To enable the core asynchronous framework, you need to set the
 		<emphasis>async_workers</emphasis> core parameter in the configuration
 		file. See the core cookbook for more information.
 		<example>
 		<title><function>async_workers</function> usage</title>
 		<programlisting format="linespecific">
 ...
15731d40
 # Enable 8 worker processes used by async and other modules
06557a25
 async_workers=8
 ...
 </programlisting>
124a5b16
 		</example>
272b2373
 		</para>
 		<para>
 		In case of internal errors, the function returns false, otherwise the
 		function exits the execution of the script at that moment (return
 		0 behaviour).
 		</para>
 		<para>
 		The routename parameter can be a static string or a dynamic string
 		value with config variables.
 		</para>
 		<para>
 		Since the SIP request handling is resumed in another process,
 		the config file execution state is practically lost. Therefore beware
 		that the execution of config after resume will end once the
 		route[routename] is finished.
 		</para>
 		<para>
 		This function can be used from REQUEST_ROUTE.
 		</para>
 		<example>
 		<title><function>async_task_route</function> usage</title>
 		<programlisting format="linespecific">
 ...
15731d40
 request_route {
     ...
     async_task_route("RESUME");
     ...
 }
272b2373
 route[RESUME] {
46f33424
    t_relay();
272b2373
    exit;
 }
 ...
bf056081
 </programlisting>
124a5b16
 	</example>
bf056081
 	</section>
 	</section>
 </chapter>