浏览代码

modules_k/rls: Added modparam to limit the number of back-end subscribes

- Specifically, the number of back-end subscribes per RLS subscribe is limited
- By default there is no limit
- Useful to help prevent a Kamailio server being overloaded when subscribers
  have huge contact lists.
Peter Dunkley 13 年之前
父节点
当前提交
c014f8b02e
共有 5 个文件被更改,包括 64 次插入6 次删除
  1. 26 6
      modules_k/rls/README
  2. 24 0
      modules_k/rls/doc/rls_admin.xml
  3. 2 0
      modules_k/rls/rls.c
  4. 1 0
      modules_k/rls/rls.h
  5. 11 0
      modules_k/rls/subscribe.c

+ 26 - 6
modules_k/rls/README

@@ -45,6 +45,7 @@ Anca-Maria Vamanu
               3.20. max_notify_body_length (int)
               3.21. fetch_rows (integer)
               3.22. disable_remote_presence (integer)
+              3.23. max_backend_subs (integer)
 
         4. Functions
 
@@ -80,9 +81,10 @@ Anca-Maria Vamanu
    1.20. Set max_notify_body_length parameter
    1.21. Set fetch_rows parameter
    1.22. Set disable_remote_presence parameter
-   1.23. rls_handle_subscribe usage
-   1.24. rls_handle_notify usage
-   1.25. rls_update_subs usage
+   1.23. Set max_backend_subscribes parameter
+   1.24. rls_handle_subscribe usage
+   1.25. rls_handle_notify usage
+   1.26. rls_update_subs usage
 
 Chapter 1. Admin Guide
 
@@ -118,6 +120,7 @@ Chapter 1. Admin Guide
         3.20. max_notify_body_length (int)
         3.21. fetch_rows (integer)
         3.22. disable_remote_presence (integer)
+        3.23. max_backend_subs (integer)
 
    4. Functions
 
@@ -198,6 +201,7 @@ Chapter 1. Admin Guide
    3.20. max_notify_body_length (int)
    3.21. fetch_rows (integer)
    3.22. disable_remote_presence (integer)
+   3.23. max_backend_subs (integer)
 
 3.1. db_url(str)
 
@@ -488,6 +492,22 @@ modparam("rls", "fetch_rows", 1000)
 modparam("rls", "disable_remote_presence", 1)
 ...
 
+3.23. max_backend_subs (integer)
+
+   When set to a non-zero value RLS will limit the number of back-end
+   SUBSCRIBEs for each RLS SUBSCRIBE to this value. Leaving this at the
+   default of zero means no limit. When people have large contact lists
+   RLS will make lots of back-end subscriptions. This can easily overload
+   a system. This option allows you to limit the number of back-end
+   SUBSCRIBEs to help prevent overload.
+
+   Default value is 0
+
+   Example 1.23. Set max_backend_subscribes parameter
+...
+modparam("rls", "max_backend_subscribes", 30)
+...
+
 4. Functions
 
    4.1. rls_handle_subscribe()
@@ -503,7 +523,7 @@ modparam("rls", "disable_remote_presence", 1)
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1.23. rls_handle_subscribe usage
+   Example 1.24. rls_handle_subscribe usage
 ...
 For presence and rls on the same machine:
         modparam("rls", "to_presence_code", 10)
@@ -531,7 +551,7 @@ For rls only:
 
    This function can be used from REQUEST_ROUTE.
 
-   Example 1.24. rls_handle_notify usage
+   Example 1.25. rls_handle_notify usage
 ...
 if(method=="NOTIFY")
     rls_handle_notify();
@@ -550,7 +570,7 @@ if(method=="NOTIFY")
 
    This function can be used from ANY_ROUTE.
 
-   Example 1.25. rls_update_subs usage
+   Example 1.26. rls_update_subs usage
 ...
 Within event_route[xhttp:request]:
         case "PUT":

+ 24 - 0
modules_k/rls/doc/rls_admin.xml

@@ -557,6 +557,30 @@ modparam("rls", "fetch_rows", 1000)
 ...
 modparam("rls", "disable_remote_presence", 1)
 ...
+</programlisting>
+	    </example>
+	</section>
+	<section>
+	    <title><varname>max_backend_subs</varname> (integer)</title>
+	    <para>
+		When set to a non-zero value RLS will limit the number of back-end
+		SUBSCRIBEs for each RLS SUBSCRIBE to this value.
+		Leaving this at the default of zero means no limit.
+		When people have large contact lists RLS will make lots of back-end
+		subscriptions.  This can easily overload a system.  This option allows
+		you to limit the number of back-end SUBSCRIBEs to help prevent overload.
+	    </para>
+	    <para>
+		<emphasis>
+		    Default value is 0
+		</emphasis>
+	    </para>
+	    <example>
+		<title>Set <varname>max_backend_subscribes</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("rls", "max_backend_subscribes", 30)
+...
 </programlisting>
 	    </example>
 	</section>

+ 2 - 0
modules_k/rls/rls.c

@@ -185,6 +185,7 @@ str rls_outbound_proxy = {0, 0};
 int rls_fetch_rows = 500;
 
 int rls_disable_remote_presence = 0;
+int rls_max_backend_subs = 0;
 
 /** module functions */
 
@@ -235,6 +236,7 @@ static param_export_t params[]={
 	{ "expires_offset",         INT_PARAM,	 &rls_expires_offset             },
 	{ "fetch_rows",             INT_PARAM,   &rls_fetch_rows                 },
 	{ "disable_remote_presence",INT_PARAM,   &rls_disable_remote_presence    },
+	{ "max_backend_subs",       INT_PARAM,   &rls_max_backend_subs           },
 	{0,                         0,           0                               }
 };
 

+ 1 - 0
modules_k/rls/rls.h

@@ -104,6 +104,7 @@ extern int rls_max_notify_body_len;
 extern int rls_expires_offset;
 
 extern int rls_disable_remote_presence;
+extern int rls_max_backend_subs;
 
 extern gen_lock_t *rls_update_subs_lock;
 

+ 11 - 0
modules_k/rls/subscribe.c

@@ -864,6 +864,11 @@ int send_resource_subs(char* uri, void* param)
 		return 1;
 	}
 
+	/* Silently drop subscribes over the limit - will print a single warning
+ 	   later */
+	if (rls_max_backend_subs > 0 && ++counter > rls_max_backend_subs)
+		return 1;
+
 	((subs_info_t*)param)->pres_uri = &pres_uri;
 	((subs_info_t*)param)->remote_target = &pres_uri;
 	return pua_send_subscribe((subs_info_t*)param);
@@ -917,6 +922,8 @@ int resource_subscriptions(subs_t* subs, xmlNodePtr xmlnode)
 	s.extra_headers = &extra_headers;
 
 	s.internal_update_flag = subs->internal_update_flag;
+
+	counter = 0;
 	
 	if(process_list_and_exec(xmlnode, subs->from_user, subs->from_domain,
 			send_resource_subs, (void*)(&s))<0)
@@ -925,6 +932,10 @@ int resource_subscriptions(subs_t* subs, xmlNodePtr xmlnode)
 		goto error;
 	}
 
+	if (rls_max_backend_subs > 0 && counter > rls_max_backend_subs)
+		LM_WARN("%.*s has too many contacts.  Max: %d, has: %d\n",
+			wuri.len, wuri.s, rls_max_backend_subs, counter);
+
 	pkg_free(wuri.s);
 	pkg_free(did_str.s);