Skip to content

Commit be03684

Browse files
committed
Use erlang:whereis/1 for checking if a store is running
A store's process uses its `StoreId` as its registered name. This is a public interface of Ra so we can depend on it. Reading from key metrics counters is already very fast but switching to `whereis/1` eliminates basically all overhead of this function. When used heavily (for example in RabbitMQ while publishing and consuming rapidly) the CPU time spent on `is_store_running/1` disappears from the output of a perf recording and a flamegraph.
1 parent 2d04459 commit be03684

1 file changed

Lines changed: 1 addition & 5 deletions

File tree

src/khepri_cluster.erl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,11 +1576,7 @@ get_store_ids() ->
15761576
%% @doc Indicates if `StoreId' is running or not.
15771577

15781578
is_store_running(StoreId) ->
1579-
ThisNode = node(),
1580-
RaServer = khepri_cluster:node_to_member(StoreId, ThisNode),
1581-
Timeout = khepri_app:get_default_timeout(),
1582-
KeyMetrics = ra:key_metrics(RaServer, Timeout),
1583-
Runs = maps:get(state, KeyMetrics) =/= noproc,
1579+
Runs = erlang:whereis(StoreId) =/= undefined,
15841580

15851581
%% We know the real state of the Ra server. In the case the Ra server
15861582
%% stopped behind the back of Khepri, we update the cached list of running

0 commit comments

Comments
 (0)