summaryrefslogtreecommitdiff
path: root/main/stasis_cache.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2014-06-13 18:24:49 +0000
committerMatthew Jordan <mjordan@digium.com>2014-06-13 18:24:49 +0000
commit9cc1a8e8936760a44def12c30329d6284f4139a8 (patch)
tree00cb0fb5904021052c0b9b6c6bc5c97e008be21f /main/stasis_cache.c
parent0acc6265303822e0c5b4044d8152f38896fdbe83 (diff)
stasis: Reduce creation of channel snapshots to improve performance
During some performance testing of Asterisk with AGI, ARI, and lots of Local channels, we noticed that there's quite a hit in performance during channel creation and releasing to the dialplan (ARI continue). After investigating the performance spike that occurs during channel creation, we discovered that we create a lot of channel snapshots that are technically unnecessary. This includes creating snapshots during: * AGI execution * Returning objects for ARI commands * During some Local channel operations * During some dialling operations * During variable setting * During some bridging operations And more. This patch does the following: - It removes a number of fields from channel snapshots. These fields were rarely used, were expensive to have on the snapshot, and hurt performance. This included formats, translation paths, Log Call ID, callgroup, pickup group, and all channel variables. As a result, AMI Status, "core show channel", "core show channelvar", and "pjsip show channel" were modified to either hit the live channel or not show certain pieces of data. While this is unfortunate, the performance gain from this patch is worth the loss in behaviour. - It adds a mechanism to publish a cached snapshot + blob. A large number of publications were changed to use this, including: - During Dial begin - During Variable assignment (if no AMI variables are emitted - if AMI variables are set, we have to make snapshots when a variable is changed) - During channel pickup - When a channel is put on hold/unhold - When a DTMF digit is begun/ended - When creating a bridge snapshot - When an AOC event is raised - During Local channel optimization/Local bridging - When endpoint snapshots are generated - All AGI events - All ARI responses that return a channel - Events in the AgentPool, MeetMe, and some in Queue - Additionally, some extraneous channel snapshots were being made that were unnecessary. These were removed. - The result of ast_hashtab_hash_string is now cached in stasis_cache. This reduces a large number of calls to ast_hashtab_hash_string, which reduced the amount of time spent in this function in gprof by around 50%. #ASTERISK-23811 #close Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/3568/ ........ Merged revisions 416211 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@416216 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/stasis_cache.c')
-rw-r--r--main/stasis_cache.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/main/stasis_cache.c b/main/stasis_cache.c
index c1dab8539..8b4304e5f 100644
--- a/main/stasis_cache.c
+++ b/main/stasis_cache.c
@@ -127,9 +127,17 @@ struct stasis_caching_topic *stasis_caching_unsubscribe_and_join(struct stasis_c
return NULL;
}
+/*!
+ * \brief The key for an entry in the cache
+ * \note The items in this struct must be immutable for the item in the cache
+ */
struct cache_entry_key {
+ /*! The message type of the item stored in the cache */
struct stasis_message_type *type;
+ /*! The unique ID of the item stored in the cache */
const char *id;
+ /*! The hash, computed from \c type and \c id */
+ unsigned int hash;
};
struct stasis_cache_entry {
@@ -166,6 +174,12 @@ static void cache_entry_dtor(void *obj)
AST_VECTOR_FREE(&entry->remote);
}
+static void cache_entry_compute_hash(struct cache_entry_key *key)
+{
+ key->hash = ast_hashtab_hash_string(stasis_message_type_name(key->type));
+ key->hash += ast_hashtab_hash_string(key->id);
+}
+
static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type *type, const char *id, struct stasis_message *snapshot)
{
struct stasis_cache_entry *entry;
@@ -187,6 +201,7 @@ static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type
return NULL;
}
entry->key.type = ao2_bump(type);
+ cache_entry_compute_hash(&entry->key);
is_remote = ast_eid_cmp(&ast_eid_default, stasis_message_eid(snapshot)) ? 1 : 0;
if (AST_VECTOR_INIT(&entry->remote, is_remote)) {
@@ -211,7 +226,6 @@ static int cache_entry_hash(const void *obj, int flags)
{
const struct stasis_cache_entry *object;
const struct cache_entry_key *key;
- int hash = 0;
switch (flags & OBJ_SEARCH_MASK) {
case OBJ_SEARCH_KEY:
@@ -227,9 +241,7 @@ static int cache_entry_hash(const void *obj, int flags)
return 0;
}
- hash += ast_hashtab_hash_string(stasis_message_type_name(key->type));
- hash += ast_hashtab_hash_string(key->id);
- return hash;
+ return (int)key->hash;
}
static int cache_entry_cmp(void *obj, void *arg, int flags)
@@ -347,6 +359,7 @@ static struct stasis_cache_entry *cache_find(struct ao2_container *entries, stru
search_key.type = type;
search_key.id = id;
+ cache_entry_compute_hash(&search_key);
entry = ao2_find(entries, &search_key, OBJ_SEARCH_KEY | OBJ_NOLOCK);
/* Ensure that what we looked for is what we found. */