[sr-dev] git:master: usrloc(k): option to start own timer processes

Daniel-Constantin Mierla miconda at gmail.com
Thu Apr 19 10:57:41 CEST 2012


Module: sip-router
Branch: master
Commit: c642e5049b8b5a5d3209b8d295207831512160ed
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c642e5049b8b5a5d3209b8d295207831512160ed

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Apr 19 10:53:49 2012 +0200

usrloc(k): option to start own timer processes

- new parameter timer_procs
- default is 0, meaning the core timer process is used (like so far)
- if >0, a number of basic sync timers are started
- each own timer will take care of syncronizing the usrloc records,
  selecting specific slots in the internal hash table (load balancing
  mechanism) - this mode is useful for handling lot of usrloc records

---

 modules_k/usrloc/README               |   18 ++++++++++++++
 modules_k/usrloc/dlist.c              |    4 +-
 modules_k/usrloc/dlist.h              |    2 +-
 modules_k/usrloc/doc/usrloc_admin.xml |   23 ++++++++++++++++++
 modules_k/usrloc/udomain.c            |    4 +-
 modules_k/usrloc/udomain.h            |    4 ++-
 modules_k/usrloc/ul_mi.c              |    2 +-
 modules_k/usrloc/ul_mod.c             |   42 ++++++++++++++++++++++++++++----
 8 files changed, 86 insertions(+), 13 deletions(-)

diff --git a/modules_k/usrloc/README b/modules_k/usrloc/README
index e89392f..06094af 100644
--- a/modules_k/usrloc/README
+++ b/modules_k/usrloc/README
@@ -64,6 +64,7 @@ Bogdan-Andrei Iancu
               3.26. hash_size (integer)
               3.27. preload (string)
               3.28. db_update_as_insert (string)
+              3.29. timer_procs (string)
 
         4. Functions
         5. MI Commands
@@ -136,6 +137,7 @@ Bogdan-Andrei Iancu
    1.26. Set hash_size parameter
    1.27. Set preload parameter
    1.28. Set db_update_as_insert parameter
+   1.29. Set timer_procs parameter
 
 Chapter 1. Admin Guide
 
@@ -180,6 +182,7 @@ Chapter 1. Admin Guide
         3.26. hash_size (integer)
         3.27. preload (string)
         3.28. db_update_as_insert (string)
+        3.29. timer_procs (string)
 
    4. Functions
    5. MI Commands
@@ -284,6 +287,7 @@ Chapter 1. Admin Guide
    3.26. hash_size (integer)
    3.27. preload (string)
    3.28. db_update_as_insert (string)
+   3.29. timer_procs (string)
 
 3.1. nat_bflag (integer)
 
@@ -663,6 +667,20 @@ modparam("usrloc", "preload", "location")
 modparam("usrloc", "db_update_as_insert", 1)
 ...
 
+3.29. timer_procs (string)
+
+   Number of timer processes to be started by module. Timer processes take
+   care of checking expired records and syncronization with database. If
+   set to 0, no dedicated timer is started, the one from core will be
+   used.
+
+   Default value is "0".
+
+   Example 1.29. Set timer_procs parameter
+...
+modparam("usrloc", "timer_procs", 4)
+...
+
 4. Functions
 
    There are no exported functions that could be used in scripts.
diff --git a/modules_k/usrloc/dlist.c b/modules_k/usrloc/dlist.c
index cb6c899..cb25871 100644
--- a/modules_k/usrloc/dlist.c
+++ b/modules_k/usrloc/dlist.c
@@ -605,7 +605,7 @@ unsigned long get_number_of_users(void)
  * \brief Run timer handler of all domains
  * \return 0 if all timer return 0, != 0 otherwise
  */
-int synchronize_all_udomains(void)
+int synchronize_all_udomains(int istart, int istep)
 {
 	int res = 0;
 	dlist_t* ptr;
@@ -617,7 +617,7 @@ int synchronize_all_udomains(void)
 			res |= db_timer_udomain(ptr->d);
 	} else {
 		for( ptr=root ; ptr ; ptr=ptr->next)
-			mem_timer_udomain(ptr->d);
+			mem_timer_udomain(ptr->d, istart, istep);
 	}
 
 	return res;
diff --git a/modules_k/usrloc/dlist.h b/modules_k/usrloc/dlist.h
index 851fca6..149b84c 100644
--- a/modules_k/usrloc/dlist.h
+++ b/modules_k/usrloc/dlist.h
@@ -83,7 +83,7 @@ void print_all_udomains(FILE* _f);
  * \brief Run timer handler of all domains
  * \return 0 if all timer return 0, != 0 otherwise
  */
-int synchronize_all_udomains(void);
+int synchronize_all_udomains(int istart, int istep);
 
 
 /*!
diff --git a/modules_k/usrloc/doc/usrloc_admin.xml b/modules_k/usrloc/doc/usrloc_admin.xml
index e719ad8..6624705 100644
--- a/modules_k/usrloc/doc/usrloc_admin.xml
+++ b/modules_k/usrloc/doc/usrloc_admin.xml
@@ -775,6 +775,29 @@ modparam("usrloc", "db_update_as_insert", 1)
 		</example>
 	</section>
 
+	<section id="timer_procs">
+		<title><varname>timer_procs</varname> (string)</title>
+		<para>
+			Number of timer processes to be started by module. Timer processes
+			take care of checking expired records and syncronization with
+			database. If set to 0, no dedicated timer is started, the one from
+			core will be used.
+		</para>
+		<para>
+		<emphasis>
+			Default value is <quote>0</quote>.
+		</emphasis>
+		</para>
+		<example>
+		<title>Set <varname>timer_procs</varname> parameter</title>
+		<programlisting format="linespecific">
+...
+modparam("usrloc", "timer_procs", 4)
+...
+</programlisting>
+		</example>
+	</section>
+
 	</section>
 
 	<section>
diff --git a/modules_k/usrloc/udomain.c b/modules_k/usrloc/udomain.c
index ca2b256..c812e7a 100644
--- a/modules_k/usrloc/udomain.c
+++ b/modules_k/usrloc/udomain.c
@@ -864,12 +864,12 @@ void mem_delete_urecord(udomain_t* _d, struct urecord* _r)
  * \brief Run timer handler for given domain
  * \param _d domain
  */
-void mem_timer_udomain(udomain_t* _d)
+void mem_timer_udomain(udomain_t* _d, int istart, int istep)
 {
 	struct urecord* ptr, *t;
 	int i;
 
-	for(i=0; i<_d->size; i++)
+	for(i=istart; i<_d->size; i+=istep)
 	{
 		lock_ulslot(_d, i);
 
diff --git a/modules_k/usrloc/udomain.h b/modules_k/usrloc/udomain.h
index 8e83d14..de55b11 100644
--- a/modules_k/usrloc/udomain.h
+++ b/modules_k/usrloc/udomain.h
@@ -117,8 +117,10 @@ int db_timer_udomain(udomain_t* _d);
 /*!
  * \brief Run timer handler for given domain
  * \param _d domain
+ * \param istart index of hash table slot to start processing
+ * \param istep step through hash table slots to process
  */
-void mem_timer_udomain(udomain_t* _d);
+void mem_timer_udomain(udomain_t* _d, int istart, int istep);
 
 
 /*!
diff --git a/modules_k/usrloc/ul_mi.c b/modules_k/usrloc/ul_mi.c
index 7d18e70..1855706 100644
--- a/modules_k/usrloc/ul_mi.c
+++ b/modules_k/usrloc/ul_mi.c
@@ -464,7 +464,7 @@ struct mi_root* mi_usrloc_flush(struct mi_root *cmd, void *param)
 	if (rpl_tree==NULL)
 		return 0;
 
-	synchronize_all_udomains();
+	synchronize_all_udomains(0, 1);
 	return rpl_tree;
 }
 
diff --git a/modules_k/usrloc/ul_mod.c b/modules_k/usrloc/ul_mod.c
index 63539c6..5a05a3d 100644
--- a/modules_k/usrloc/ul_mod.c
+++ b/modules_k/usrloc/ul_mod.c
@@ -57,6 +57,7 @@
 #include "../../dprint.h"
 #include "../../rpc_lookup.h"
 #include "../../timer.h"     /* register_timer */
+#include "../../timer_proc.h" /* register_sync_timer */
 #include "../../globals.h"   /* is_main */
 #include "../../ut.h"        /* str_init */
 #include "dlist.h"           /* register_udomain */
@@ -91,7 +92,8 @@ MODULE_VERSION
 
 static int mod_init(void);                          /*!< Module initialization function */
 static void destroy(void);                          /*!< Module destroy function */
-static void timer(unsigned int ticks, void* param); /*!< Timer handler */
+static void ul_core_timer(unsigned int ticks, void* param);  /*!< Core timer handler */
+static void ul_local_timer(unsigned int ticks, void* param); /*!< Local timer handler */
 static int child_init(int rank);                    /*!< Per-child init function */
 static int mi_child_init(void);
 
@@ -103,6 +105,7 @@ static int ul_preload_param(modparam_t type, void* val);
 extern int bind_usrloc(usrloc_api_t* api);
 extern int ul_locks_no;
 int ul_db_update_as_insert = 0;
+int ul_timer_procs = 0;
 
 /*
  * Module parameters and their default values
@@ -186,6 +189,7 @@ static param_export_t params[] = {
 	{"nat_bflag",           INT_PARAM, &nat_bflag       },
 	{"preload",             STR_PARAM|USE_FUNC_PARAM, (void*)ul_preload_param},
 	{"db_update_as_insert", INT_PARAM, &ul_db_update_as_insert},
+	{"timer_procs",         INT_PARAM, &ul_timer_procs},
 	{0, 0, 0}
 };
 
@@ -301,7 +305,10 @@ static int mod_init(void)
 	}
 
 	/* Register cache timer */
-	register_timer( timer, 0, timer_interval);
+	if(ul_timer_procs<=0)
+		register_timer(ul_core_timer, 0, timer_interval);
+	else
+		register_sync_timers(ul_timer_procs);
 
 	/* init the callbacks list */
 	if ( init_ulcb_list() < 0) {
@@ -350,6 +357,19 @@ static int mod_init(void)
 static int child_init(int _rank)
 {
 	dlist_t* ptr;
+	int i;
+
+	if(_rank==PROC_MAIN && ul_timer_procs>0)
+	{
+		for(i=0; i<ul_timer_procs; i++)
+		{
+			if(fork_sync_timer(PROC_TIMER, "USRLOC Timer", 1 /*socks flag*/,
+					ul_local_timer, (void*)(long)i, timer_interval /*sec*/)<0) {
+				LM_ERR("failed to start timer routine as process\n");
+				return -1; /* error */
+			}
+		}
+	}
 
 	/* connecting to DB ? */
 	switch (db_mode) {
@@ -420,7 +440,7 @@ static void destroy(void)
 	/* we need to sync DB in order to flush the cache */
 	if (ul_dbh) {
 		ul_unlock_locks();
-		if (synchronize_all_udomains() != 0) {
+		if (synchronize_all_udomains(0, 1) != 0) {
 			LM_ERR("flushing cache failed\n");
 		}
 		ul_dbf.close(ul_dbh);
@@ -435,11 +455,21 @@ static void destroy(void)
 
 
 /*! \brief
- * Timer handler
+ * Core timer handler
+ */
+static void ul_core_timer(unsigned int ticks, void* param)
+{
+	if (synchronize_all_udomains(0, 1) != 0) {
+		LM_ERR("synchronizing cache failed\n");
+	}
+}
+
+/*! \brief
+ * Local timer handler
  */
-static void timer(unsigned int ticks, void* param)
+static void ul_local_timer(unsigned int ticks, void* param)
 {
-	if (synchronize_all_udomains() != 0) {
+	if (synchronize_all_udomains((int)(long)param, ul_timer_procs) != 0) {
 		LM_ERR("synchronizing cache failed\n");
 	}
 }




More information about the sr-dev mailing list