]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
sorcery: Add setting object type congestion levels. 88/2988/1
authorRichard Mudgett <rmudgett@digium.com>
Thu, 2 Jun 2016 23:19:13 +0000 (18:19 -0500)
committerRichard Mudgett <rmudgett@digium.com>
Thu, 9 Jun 2016 15:32:07 +0000 (10:32 -0500)
Sorcery creates taskprocessors for object types to process object observer
callbacks.  An API call is needed to be able to set the congestion levels
of these taskprocessors for selected object types.

* Updated PJSIP's contact and contact_status sorcery object type observer
default congestion levels based upon stress testing.  Increased the
congestion levels to reduce the potential for bursty register/unregister
and subscribe/unsubscribe activity from triggering the taskprocessor
overload alert.

ASTERISK-26088
Reported by:  Richard Mudgett

Change-Id: I4542e83b556f0714009bfeff89505c801f1218c6

include/asterisk/sorcery.h
main/sorcery.c
res/res_pjsip/location.c
res/res_pjsip/pjsip_options.c

index 42ecc133ff53054e8899a7449f7da273db663e28..23219ec41cc8dbb8b74795e21af88bbee5c82b13 100644 (file)
@@ -694,6 +694,20 @@ int __ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type,
 #define ast_sorcery_internal_object_register(sorcery, type, alloc, transform, apply) \
        __ast_sorcery_object_register((sorcery), (type), 1, 1, (alloc), (transform), (apply))
 
+/*!
+ * \brief Set the high and low alert water marks of the sorcery object type.
+ * \since 13.10.0
+ *
+ * \param sorcery Pointer to a sorcery structure
+ * \param type Type of object
+ * \param low_water New queue low water mark. (-1 to set as 90% of high_water)
+ * \param high_water New queue high water mark.
+ *
+ * \retval 0 on success.
+ * \retval -1 on error (water marks not changed).
+ */
+int ast_sorcery_object_set_congestion_levels(struct ast_sorcery *sorcery, const char *type, long low_water, long high_water);
+
 /*!
  * \brief Set the copy handler for an object type
  *
index ec340e8273cacaae9e02aa458c52f87725fd414f..6a7b54bbf3164e611e2177f0e9044185be31de66 100644 (file)
@@ -1164,6 +1164,20 @@ int __ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type,
        return 0;
 }
 
+int ast_sorcery_object_set_congestion_levels(struct ast_sorcery *sorcery, const char *type, long low_water, long high_water)
+{
+       struct ast_sorcery_object_type *object_type;
+       int res = -1;
+
+       object_type = ao2_find(sorcery->types, type, OBJ_SEARCH_KEY);
+       if (object_type) {
+               res = ast_taskprocessor_alert_set_levels(object_type->serializer,
+                       low_water, high_water);
+               ao2_ref(object_type, -1);
+       }
+       return res;
+}
+
 void ast_sorcery_object_set_copy_handler(struct ast_sorcery *sorcery, const char *type, sorcery_copy_handler copy)
 {
        RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
index 43e6ea40f4386fdf1a6a014872c16c9d2ba63672..8f8c030c35f27f6fb77ebf90f65973be294562ea 100644 (file)
@@ -25,6 +25,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/paths.h"
 #include "asterisk/sorcery.h"
+#include "asterisk/taskprocessor.h"
 #include "include/res_pjsip_private.h"
 #include "asterisk/res_pjsip_cli.h"
 #include "asterisk/statsd.h"
@@ -1114,6 +1115,8 @@ int ast_sip_initialize_sorcery_location(void)
        ast_pjproject_get_buildopt("PJSIP_MAX_URL_SIZE", "%d", &pjsip_max_url_size);
 
        ast_sorcery_apply_default(sorcery, "contact", "astdb", "registrar");
+       ast_sorcery_object_set_congestion_levels(sorcery, "contact", -1,
+               3 * AST_TASKPROCESSOR_HIGH_WATER_LEVEL);
        ast_sorcery_apply_default(sorcery, "aor", "config", "pjsip.conf,criteria=type=aor");
 
        if (ast_sorcery_object_register(sorcery, "contact", contact_alloc, NULL, contact_apply_handler) ||
index 1114336bd07192d806e430e5407b2f38356fb78c..381de37545c7aed092d819c269bc91d797a0981c 100644 (file)
@@ -31,6 +31,7 @@
 #include "asterisk/test.h"
 #include "asterisk/statsd.h"
 #include "include/res_pjsip_private.h"
+#include "asterisk/taskprocessor.h"
 
 #define DEFAULT_LANGUAGE "en"
 #define DEFAULT_ENCODING "text/plain"
@@ -1004,6 +1005,8 @@ int ast_sip_initialize_sorcery_qualify(void)
 
        /* initialize sorcery ast_sip_contact_status resource */
        ast_sorcery_apply_default(sorcery, CONTACT_STATUS, "memory", NULL);
+       ast_sorcery_object_set_congestion_levels(sorcery, CONTACT_STATUS, -1,
+               3 * AST_TASKPROCESSOR_HIGH_WATER_LEVEL);
 
        if (ast_sorcery_internal_object_register(sorcery, CONTACT_STATUS,
                                        contact_status_alloc, NULL, NULL)) {