Skip to content

Commit

Permalink
Spike/dega 1748 (#7)
Browse files Browse the repository at this point in the history
* new function betree_write_dot added

* new functionality - search with id lists, added

* new test added; using latest be-tree

* new feature with using event created as C object is added

* change betree_make_event to make usage from rtb-gateway more convinient

* some more simplifications for rtb_gateway usage

* betree_make_event returns execution time

* memory allocation for event fixed

* now all betree_search return sorted id list

* using v1.2.1 be-tree

* no changes almost

* betree_search_tests - added tests with multiple Betrees

* added 'with_event' related benchmark functions

* betree.c - re-ordered functions according to 'nif_functions' table

* be-tree tag changed

---------

Co-authored-by: Victor Savkov <[email protected]>
  • Loading branch information
arodionov53 and vs-ads authored Mar 25, 2024
1 parent 35258a7 commit c1cd823
Show file tree
Hide file tree
Showing 8 changed files with 1,237 additions and 448 deletions.
46 changes: 46 additions & 0 deletions benchmarks/be_bm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
iterated_next/2,
iterated_next_stats/3,
iterated_next_output/3,
with_event/2,
with_event_stats/3,
with_event_output/3,

std_betree_search/2,
iterated_betree_search_all/2,
Expand Down Expand Up @@ -109,6 +112,32 @@ iterated_next_output(BetreeFile, EventsFile, EventEvalOutputFile) ->
be_eval:stop(PidEval),
Ret.

with_event(BetreeFile, EventsFile) ->
{ok, PidEval} = be_eval:start_link(),
Ret = be_eval:run(PidEval, "BE-Tree search 'with event'",
BetreeFile, EventsFile,
fun with_event_betree_search/2, fun stats_collector/2),
be_eval:stop(PidEval),
Ret.

with_event_stats(BetreeFile, EventsFile, StatsFile) ->
{ok, PidEval} = be_eval:start_link(),
Ret = be_eval:run(PidEval, "BE-Tree search 'with event'",
BetreeFile,
EventsFile, fun with_event_betree_search/2, _EventEvalOutputFile = undefined,
fun stats_collector/2, StatsFile),
be_eval:stop(PidEval),
Ret.

with_event_output(BetreeFile, EventsFile, EventEvalOutputFile) ->
{ok, PidEval} = be_eval:start_link(),
Ret = be_eval:run(PidEval, "BE-Tree search 'with event'",
BetreeFile,
EventsFile, fun with_event_betree_search/2, EventEvalOutputFile,
fun stats_collector/2, undefined),
be_eval:stop(PidEval),
Ret.

std_betree_search(Term, #be_evaluator{betree = Betree} = Context) ->
Event = [list_to_tuple(
[event | [case N of 1 -> true; _ -> false end|| N <- Term]])],
Expand Down Expand Up @@ -165,6 +194,23 @@ iterated_betree_search_next(Iterator) ->
X -> {error, {search_next, X}}
end.

with_event_betree_search(Term, #be_evaluator{betree = Betree} = Context) ->
Event = [list_to_tuple(
[event | [case N of 1 -> true; _ -> false end|| N <- Term]])],
BeginNano = erlang:monotonic_time(nanosecond),
case erl_betree:betree_make_event(Betree, Event) of
{{ok, Evt}, _} ->
case erl_betree:betree_search(Betree, Evt, 0) of
{{ok, Ids}, _} ->
EndNano = erlang:monotonic_time(nanosecond),
CurrentAllocations = be_bm_utils:betree_allocations(),
DiffNano = EndNano - BeginNano,
{{ok, {Ids, {DiffNano, CurrentAllocations}}}, Context};
X -> {{error, {betree_search_with_event, X}}, Context}
end;
X -> {{error, {betree_make_event, X}}, Context}
end.

stats_collector({DiffNano, Allocations}, #be_evaluator_stats{
info = Info,
index = Index,
Expand Down
2 changes: 2 additions & 0 deletions c_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ CFLAGS = -O3 -std=gnu11 -finline-functions -Wall -Wmissing-prototypes

CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR) -I $(BETREE_INCLUDE_DIR)

# CFLAGS += -Wno-incompatible-pointer-types

LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei -L $(BETREE_LIB_DIR) -lbetree

ifeq ($(UNAME), Darwin)
Expand Down
Loading

0 comments on commit c1cd823

Please sign in to comment.