forked from 2600hz/kazoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PISTON-841: performance improvements: acdc_queue_handler:presence_pro…
…be (2600hz#5916) * PISTON-841: performance improvements: acdc_queue_handler:presence_probe - filter out Usernames that are not 32 char hex binary (so can't be queue presence probes) - serialize get_account_by_realm lookup to allow cache to warm when Kamailio nodes are restarted and many probes come in due to stale presence cache in Kamailio - request queue_size from queue manager as AMQP queue size will give wrong result due to unacked msgs in consumers * PISTON-821: make fmt * PISTON-841: omit unneeded undefined clause for 32 char hex check
- Loading branch information
1 parent
a6db64d
commit cc39ac0
Showing
4 changed files
with
168 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
%%%----------------------------------------------------------------------------- | ||
%%% @copyright (C) 2019-, Voxter Communications Inc | ||
%%% @doc Serialize requests to look up an account ID by realm in order to reduce | ||
%%% overhead when Kamailio nodes are restarted and presence probes are performed | ||
%%% for all new registrations | ||
%%% | ||
%%% @end | ||
%%% @author Daniel Finke | ||
%%%----------------------------------------------------------------------------- | ||
-module(acdc_presence_realm_lookup). | ||
|
||
-behaviour(gen_server). | ||
|
||
%% API | ||
-export([start_link/0 | ||
,lookup/1 | ||
]). | ||
|
||
%% gen_server callbacks | ||
-export([init/1 | ||
,handle_call/3 | ||
,handle_cast/2 | ||
,handle_info/2 | ||
,terminate/2 | ||
,code_change/3 | ||
]). | ||
|
||
-include("acdc.hrl"). | ||
|
||
-define(SERVER, ?MODULE). | ||
|
||
-record(state, {}). | ||
-type state() :: #state{}. | ||
|
||
%%%============================================================================= | ||
%%% API | ||
%%%============================================================================= | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Starts the server | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec start_link() -> kz_types:startlink_ret(). | ||
start_link() -> | ||
gen_server:start_link({'local', ?SERVER}, ?MODULE, [], []). | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Look up the account ID corresponding to a given realm | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec lookup(kz_term:ne_binary()) -> kz_term:ne_binary() | 'not_found'. | ||
lookup(Realm) -> | ||
gen_server:call(?SERVER, {'lookup', Realm}). | ||
|
||
%%%============================================================================= | ||
%%% gen_server callbacks | ||
%%%============================================================================= | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Initializes the server | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec init([]) -> {'ok', state()}. | ||
init([]) -> | ||
{'ok', #state{}}. | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Handling call messages | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec handle_call(any(), kz_term:pid_ref(), state()) -> kz_types:handle_call_ret_state(state()). | ||
handle_call({'lookup', Realm}, _, State) -> | ||
case kapps_util:get_account_by_realm(Realm) of | ||
{'ok', AcctDb} -> | ||
AccountId = kz_util:format_account_id(AcctDb, 'raw'), | ||
{'reply', AccountId, State}; | ||
_ -> {'reply', 'not_found', State} | ||
end; | ||
handle_call(_Request, _From, State) -> | ||
{'reply', 'ok', State}. | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Handling cast messages | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec handle_cast(any(), state()) -> kz_types:handle_cast_ret_state(state()). | ||
handle_cast(_Msg, State) -> | ||
{'noreply', State}. | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Handling all non call/cast messages | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec handle_info(any(), state()) -> kz_types:handle_info_ret_state(state()). | ||
handle_info(_Info, State) -> | ||
{'noreply', State}. | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc This function is called by a gen_server when it is about to | ||
%% terminate. It should be the opposite of Module:init/1 and do any | ||
%% necessary cleaning up. When it returns, the gen_server terminates | ||
%% with Reason. The return value is ignored. | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec terminate(any(), state()) -> 'ok'. | ||
terminate(_Reason, _State) -> | ||
'ok'. | ||
|
||
%%------------------------------------------------------------------------------ | ||
%% @doc Convert process state when code is changed | ||
%% | ||
%% @end | ||
%%------------------------------------------------------------------------------ | ||
-spec code_change(any(), state(), any()) -> {'ok', state()}. | ||
code_change(_OldVsn, State, _Extra) -> | ||
{'ok', State}. | ||
|
||
%%%============================================================================= | ||
%%% Internal functions | ||
%%%============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters