[Asterisk-Dev] pseudo realtime and load issue

Steven Critchfield critch at basesys.com
Wed Aug 10 10:40:51 MST 2005


When asterisk is run in the pseudo realtime mode, any agi app that runs
also inherits this priority and can compete with asterisk to complete
it's task. While some agi apps may not take long to start up and then
spend a large amount of time waiting for asterisk to reply to events, it
is the start up time of an agi app that can cause problems. 

Specifically we have a complex perl script that was causing up to 1
second of choppy audio on other zap channels when a new call was
started. It would get worse with the more concurrent calls running as
asterisk had more work to do and the perl script still had a fixed
amount of work to get accomplished before it could go to a mostly idle
state.

After discussions with Tilghman about the solution, here is a set of
diffs that I think need a moment more of peer review before being
accepted. 

I do have a disclaimer on file with Digium.

The first two expose the set_priority function for use elsewhere.

Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.125.2.6
diff -u -r1.125.2.6 asterisk.c
--- asterisk.c  5 Apr 2005 09:37:02 -0000       1.125.2.6
+++ asterisk.c  10 Aug 2005 17:28:17 -0000
@@ -480,7 +480,7 @@
                fprintf(stdout, "\033]1;%s\007", text);
 }
 
-static int set_priority(int pri)
+int set_priority(int pri)
 {
        struct sched_param sched;
        memset(&sched, 0, sizeof(sched));
Index: asterisk.h
===================================================================
RCS file: /usr/cvsroot/asterisk/Attic/asterisk.h,v
retrieving revision 1.13
diff -u -r1.13 asterisk.h
--- asterisk.h  7 Sep 2004 15:02:53 -0000       1.13
+++ asterisk.h  10 Aug 2005 17:28:17 -0000
@@ -50,5 +50,7 @@
 extern int term_init(void);
 /* Provided by db.c */
 extern int astdb_init(void);
+/* Provided by asterisk.c */
+extern int set_priority(int);
 
 #endif






This next one uses the set_priority to downgrade the post forked thread
to a normal priority.

Index: res/res_agi.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_agi.c,v
retrieving revision 1.10.2.5
diff -u -r1.10.2.5 res_agi.c
--- res/res_agi.c       5 Apr 2005 10:15:00 -0000       1.10.2.5
+++ res/res_agi.c       10 Aug 2005 17:28:20 -0000
@@ -250,6 +250,9 @@
                return -1;
        }
        if (!pid) {
+               /* drop scheduled priority fast, logging about priority done in set_priority */
+               set_priority(0);
+
                /* Redirect stdin and out, provide enhanced audio channel if desired */
                dup2(fromast[0], STDIN_FILENO);
                dup2(toast[1], STDOUT_FILENO);

  

-- 
Steven Critchfield <critch at basesys.com>




More information about the asterisk-dev mailing list