Module: sip-router
Branch: master
Commit: c014f8b02eba3ef08195a22269bbd3c9e9670b30
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c014f8b…
Author: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Committer: Peter Dunkley <peter.dunkley(a)crocodile-rcs.com>
Date: Thu Feb 23 23:09:21 2012 +0000
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.
---
modules_k/rls/README | 32 ++++++++++++++++++++++++++------
modules_k/rls/doc/rls_admin.xml | 24 ++++++++++++++++++++++++
modules_k/rls/rls.c | 2 ++
modules_k/rls/rls.h | 1 +
modules_k/rls/subscribe.c | 11 +++++++++++
5 files changed, 64 insertions(+), 6 deletions(-)
diff --git a/modules_k/rls/README b/modules_k/rls/README
index e2d2ef9..d9da04f 100644
--- a/modules_k/rls/README
+++ b/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":
diff --git a/modules_k/rls/doc/rls_admin.xml b/modules_k/rls/doc/rls_admin.xml
index 72f1606..3bad25f 100644
--- a/modules_k/rls/doc/rls_admin.xml
+++ b/modules_k/rls/doc/rls_admin.xml
@@ -560,6 +560,30 @@ 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>
</section>
diff --git a/modules_k/rls/rls.c b/modules_k/rls/rls.c
index 1d64e26..be28c10 100644
--- a/modules_k/rls/rls.c
+++ b/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 }
};
diff --git a/modules_k/rls/rls.h b/modules_k/rls/rls.h
index 05f5ffb..8bb7a8a 100644
--- a/modules_k/rls/rls.h
+++ b/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;
diff --git a/modules_k/rls/subscribe.c b/modules_k/rls/subscribe.c
index eee4941..c1b73a8 100644
--- a/modules_k/rls/subscribe.c
+++ b/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);