summaryrefslogtreecommitdiff
path: root/main/stasis_channels.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_channels.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_channels.c')
-rw-r--r--main/stasis_channels.c71
1 files changed, 38 insertions, 33 deletions
diff --git a/main/stasis_channels.c b/main/stasis_channels.c
index f38edb0e1..ad9da50cf 100644
--- a/main/stasis_channels.c
+++ b/main/stasis_channels.c
@@ -195,18 +195,12 @@ static void channel_snapshot_dtor(void *obj)
ast_string_field_free_memory(snapshot);
ao2_cleanup(snapshot->manager_vars);
- ao2_cleanup(snapshot->channel_vars);
}
struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *chan)
{
struct ast_channel_snapshot *snapshot;
struct ast_bridge *bridge;
- char nativeformats[256];
- struct ast_str *write_transpath = ast_str_alloca(256);
- struct ast_str *read_transpath = ast_str_alloca(256);
- struct ast_party_id effective_connected_id;
- struct ast_callid *callid;
/* no snapshots for dummy channels */
if (!ast_channel_tech(chan)) {
@@ -263,38 +257,16 @@ struct ast_channel_snapshot *ast_channel_snapshot_create(struct ast_channel *cha
ao2_cleanup(bridge);
}
- ast_string_field_set(snapshot, nativeformats, ast_getformatname_multiple(nativeformats, sizeof(nativeformats),
- ast_channel_nativeformats(chan)));
- ast_string_field_set(snapshot, readformat, ast_getformatname(ast_channel_readformat(chan)));
- ast_string_field_set(snapshot, writeformat, ast_getformatname(ast_channel_writeformat(chan)));
- ast_string_field_set(snapshot, writetrans, ast_translate_path_to_str(ast_channel_writetrans(chan), &write_transpath));
- ast_string_field_set(snapshot, readtrans, ast_translate_path_to_str(ast_channel_readtrans(chan), &read_transpath));
-
- effective_connected_id = ast_channel_connected_effective_id(chan);
- ast_string_field_set(snapshot, effective_name,
- S_COR(effective_connected_id.name.valid, effective_connected_id.name.str, ""));
- ast_string_field_set(snapshot, effective_number,
- S_COR(effective_connected_id.number.valid, effective_connected_id.number.str, ""));
-
- if ((callid = ast_channel_callid(chan))) {
- ast_callid_strnprint(snapshot->callid, sizeof(snapshot->callid), callid);
- ast_callid_unref(callid);
- }
-
snapshot->creationtime = ast_channel_creationtime(chan);
- snapshot->hanguptime = *(ast_channel_whentohangup(chan));
snapshot->state = ast_channel_state(chan);
snapshot->priority = ast_channel_priority(chan);
snapshot->amaflags = ast_channel_amaflags(chan);
snapshot->hangupcause = ast_channel_hangupcause(chan);
ast_copy_flags(&snapshot->flags, ast_channel_flags(chan), 0xFFFFFFFF);
snapshot->caller_pres = ast_party_id_presentation(&ast_channel_caller(chan)->id);
- snapshot->callgroup = ast_channel_callgroup(chan);
- snapshot->pickupgroup = ast_channel_pickupgroup(chan);
ast_set_flag(&snapshot->softhangup_flags, ast_channel_softhangup_internal_flag(chan));
snapshot->manager_vars = ast_channel_get_manager_vars(chan);
- snapshot->channel_vars = ast_channel_get_vars(chan);
snapshot->tech_properties = ast_channel_tech(chan)->properties;
return snapshot;
@@ -347,7 +319,11 @@ void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_cha
if (caller) {
ast_channel_lock(caller);
- caller_snapshot = ast_channel_snapshot_create(caller);
+ if (ast_strlen_zero(dialstatus)) {
+ caller_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(caller));
+ } else {
+ caller_snapshot = ast_channel_snapshot_create(caller);
+ }
ast_channel_unlock(caller);
if (!caller_snapshot) {
return;
@@ -356,7 +332,11 @@ void ast_channel_publish_dial_forward(struct ast_channel *caller, struct ast_cha
}
ast_channel_lock(peer);
- peer_snapshot = ast_channel_snapshot_create(peer);
+ if (ast_strlen_zero(dialstatus)) {
+ peer_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(peer));
+ } else {
+ peer_snapshot = ast_channel_snapshot_create(peer);
+ }
ast_channel_unlock(peer);
if (!peer_snapshot) {
return;
@@ -682,9 +662,24 @@ void ast_channel_publish_snapshot(struct ast_channel *chan)
stasis_publish(ast_channel_topic(chan), message);
}
+void ast_channel_publish_cached_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
+{
+ struct stasis_message *message;
+
+ if (!blob) {
+ blob = ast_json_null();
+ }
+
+ message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan), type, blob);
+ if (message) {
+ stasis_publish(ast_channel_topic(chan), message);
+ }
+ ao2_cleanup(message);
+}
+
void ast_channel_publish_blob(struct ast_channel *chan, struct stasis_message_type *type, struct ast_json *blob)
{
- RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+ struct stasis_message *message;
if (!blob) {
blob = ast_json_null();
@@ -694,11 +689,12 @@ void ast_channel_publish_blob(struct ast_channel *chan, struct stasis_message_ty
if (message) {
stasis_publish(ast_channel_topic(chan), message);
}
+ ao2_cleanup(message);
}
void ast_channel_publish_varset(struct ast_channel *chan, const char *name, const char *value)
{
- RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+ struct ast_json *blob;
ast_assert(name != NULL);
ast_assert(value != NULL);
@@ -711,7 +707,15 @@ void ast_channel_publish_varset(struct ast_channel *chan, const char *name, cons
return;
}
- ast_channel_publish_blob(chan, ast_channel_varset_type(), blob);
+ if (chan && !ast_channel_has_manager_vars()) {
+ ast_channel_publish_cached_blob(chan, ast_channel_varset_type(), blob);
+ } else {
+ /* This function is NULL safe. If there are manager variables,
+ * we have to produce the full snapshot.
+ */
+ ast_channel_publish_blob(chan, ast_channel_varset_type(), blob);
+ }
+ ast_json_unref(blob);
}
static struct ast_manager_event_blob *varset_to_ami(struct stasis_message *msg)
@@ -1179,3 +1183,4 @@ int ast_stasis_channels_init(void)
return res;
}
+