Skip to content
Snippets Groups Projects
Commit 0af2a50d authored by Lukasz Kotasa's avatar Lukasz Kotasa
Browse files

limit memory consumption after each call made

After each call, stasis message is created and stored
in memory. This can cause big memory consumption
if many calls are processed. We re-use `csv_max_row`
config (see below) to control how many entries can
be cached in stasis_cache.

/etc/config/asterisk

config cdr 'cdr_options'
  option csv_max_row '100'
parent 0f92aaad
Branches
Tags
1 merge request!132Draft: limit memory consumption after each call made
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "asterisk.h" #include "asterisk.h"
#include "asterisk/astobj2.h" #include "asterisk/astobj2.h"
#include "asterisk/config.h"
#include "asterisk/hashtab.h" #include "asterisk/hashtab.h"
#include "asterisk/stasis_internal.h" #include "asterisk/stasis_internal.h"
#include "asterisk/stasis.h" #include "asterisk/stasis.h"
...@@ -42,6 +43,10 @@ ...@@ -42,6 +43,10 @@
#define NUM_CACHE_BUCKETS 563 #define NUM_CACHE_BUCKETS 563
#endif #endif
/// max count for stasis elements cached is synched with maxrow from cdr
static int maxrow = 100;
static const char config[] = "cdr.conf";
/*! \internal */ /*! \internal */
struct stasis_cache { struct stasis_cache {
struct ao2_container *entries; struct ao2_container *entries;
...@@ -213,6 +218,9 @@ static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type ...@@ -213,6 +218,9 @@ static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type
{ {
struct stasis_cache_entry *entry; struct stasis_cache_entry *entry;
int is_remote; int is_remote;
struct ast_config *cfg;
struct ast_variable *v;
struct ast_flags config_flags = { 0 };
ast_assert(id != NULL); ast_assert(id != NULL);
ast_assert(snapshot != NULL); ast_assert(snapshot != NULL);
...@@ -260,6 +268,20 @@ static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type ...@@ -260,6 +268,20 @@ static struct stasis_cache_entry *cache_entry_create(struct stasis_message_type
} }
ao2_bump(snapshot); ao2_bump(snapshot);
// get maxrow from cdr.conf
if (!(cfg = ast_config_load(config, config_flags))) {
ast_log(LOG_WARNING, "unable to load config: %s\n", config);
}
v = ast_variable_browse(cfg, "csv");
if (v) {
for (; v; v = v->next) {
if (!strcasecmp(v->name, "maxrow")) {
maxrow = atoi(v->value);
}
}
}
ast_config_destroy(cfg);
return entry; return entry;
} }
...@@ -533,7 +555,10 @@ static struct cache_put_snapshots cache_put(struct stasis_cache *cache, ...@@ -533,7 +555,10 @@ static struct cache_put_snapshots cache_put(struct stasis_cache *cache,
/* Insert into the cache */ /* Insert into the cache */
cached_entry = cache_entry_create(type, id, new_snapshot); cached_entry = cache_entry_create(type, id, new_snapshot);
if (cached_entry) { if (cached_entry) {
ao2_link_flags(cache->entries, cached_entry, OBJ_NOLOCK); if (ao2_container_count(cache->entries) >= maxrow)
ast_log(LOG_VERBOSE, "reached max capacity for cache entries: %d out of %d used\n", ao2_container_count(cache->entries), maxrow);
else
ao2_link_flags(cache->entries, cached_entry, OBJ_NOLOCK);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment