Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PoC Couch Stats Resource Tracker for tracking process local resource usage #4812

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
be84279
PoC couch_stats local resource usage tracking
chewbranca Jul 18, 2022
e5e4820
Instrument more stats and rudimentary delta accumulation
chewbranca Oct 23, 2023
ecda8f3
Add more usage tracking and core functionality
chewbranca Oct 30, 2023
73863a7
Embed worker usage deltas in rexi:ping
chewbranca Oct 31, 2023
12e0267
WIP: core delta aggregation working
chewbranca Nov 9, 2023
84be4af
TMP: rewire rexi to fail on unexpected messages
chewbranca Nov 10, 2023
19224af
Add baseline group by and sort by aggregations
chewbranca Nov 14, 2023
cafa512
Add watchdog scanning for unmonitored processes
chewbranca Nov 14, 2023
996c385
Set dbname context properly
chewbranca Nov 15, 2023
1bbf7a9
Add unsafe_foldl for perf testing
chewbranca Nov 16, 2023
e70ba4d
Rework csrt context setting
chewbranca Nov 18, 2023
715b524
WIP: ugly but working HTTP API around groupings
chewbranca Nov 18, 2023
be8ab04
Cleanup debug info
chewbranca Nov 20, 2023
4c05a0f
Make CSRT toggle-able and rework delta sending
chewbranca Nov 20, 2023
eb20b5d
Remove debug exit clause
chewbranca Nov 20, 2023
f4a712c
Declare missing metrics
chewbranca Nov 21, 2023
c758cb7
WIP: relax record constraints...
chewbranca Nov 21, 2023
4f00910
Use Default in config:get/3 on ets table error
chewbranca Nov 30, 2023
887a7f2
Switch to delta extraction from messages
chewbranca Nov 30, 2023
1a1a584
Revert "Use Default in config:get/3 on ets table error"
chewbranca Nov 30, 2023
db1f874
Flush chttpd_db monitor refs on demonitor
chewbranca Dec 9, 2023
50495bf
TMP Hack around issue #4909
chewbranca Dec 18, 2023
9578773
Avoid mem3_rpc:rexi_call selective receive
chewbranca Dec 18, 2023
f77583a
Pass tests and toggle csrt
chewbranca Dec 19, 2023
ac17510
Handle delta in fabric rpc tests
chewbranca Dec 19, 2023
c500f0f
Conditionally log reports
chewbranca Dec 19, 2023
d7e9bd9
Do not persist doc size test config settings
chewbranca Jan 5, 2024
f68005a
Configurable logging and no more io_lib:format
chewbranca Jan 8, 2024
0371589
Limit resource usage output and fix keys
chewbranca Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Limit resource usage output and fix keys
chewbranca committed Feb 12, 2024
commit 03715890285dedbca8c8e4f104a78519af26e603
5 changes: 4 additions & 1 deletion src/chttpd/src/chttpd_misc.erl
Original file line number Diff line number Diff line change
@@ -301,7 +301,10 @@ handle_resource_status_req(#httpd{method = 'POST'} = Req) ->
case Fun() of
Map when is_map(Map) ->
{maps:fold(
fun(K,V,A) -> [{ToJson(K), V} | A] end,
fun
(_K,0,A) -> A; %% TODO: Skip 0 value entries?
(K,V,A) -> [{ToJson(K), V} | A]
end,
[], Map)};
List when is_list(List) ->
List
29 changes: 21 additions & 8 deletions src/couch_stats/src/couch_stats_resource_tracker.erl
Original file line number Diff line number Diff line change
@@ -440,7 +440,13 @@ group_by(KeyFun, ValFun, AggFun, Fold) ->
Val = ValFun(Ele),
CurrVal = maps:get(Key, Acc, 0),
NewVal = AggFun(CurrVal, Val),
maps:put(Key, NewVal, Acc)
%% TODO: should we skip here? how to make this optional?
case NewVal > 0 of
true ->
maps:put(Key, NewVal, Acc);
false ->
Acc
end
end,
Fold(FoldFun, #{}, ?MODULE).

@@ -449,12 +455,15 @@ group_by(KeyFun, ValFun, AggFun, Fold) ->
sorted(Map) when is_map(Map) ->
lists:sort(fun({_K1, A}, {_K2, B}) -> B < A end, maps:to_list(Map)).

shortened(L) ->
lists:sublist(L, 10).


%% eg: sorted_by([username, dbname, mfa], ioq_calls)
%% eg: sorted_by([dbname, mfa], doc_reads)
sorted_by(KeyFun) -> sorted(count_by(KeyFun)).
sorted_by(KeyFun, ValFun) -> sorted(group_by(KeyFun, ValFun)).
sorted_by(KeyFun, ValFun, AggFun) -> sorted(group_by(KeyFun, ValFun, AggFun)).
sorted_by(KeyFun) -> shortened(sorted(count_by(KeyFun))).
sorted_by(KeyFun, ValFun) -> shortened(sorted(group_by(KeyFun, ValFun))).
sorted_by(KeyFun, ValFun, AggFun) -> shortened(sorted(group_by(KeyFun, ValFun, AggFun))).


term_to_flat_json({shutdown, Reason0}) when is_atom(Reason0) ->
@@ -489,7 +498,7 @@ to_flat_json(#rctx{}=Rctx) ->
#rctx{
updated_at = TP,
started_at = TInit,
pid_ref = {Pid, Ref},
pid_ref = {Pid0, Ref0},
mfa = MFA0,
nonce = Nonce0,
from = From0,
@@ -509,7 +518,9 @@ to_flat_json(#rctx{}=Rctx) ->
changes_returned = ChangesReturned,
ioq_calls = IoqCalls
} = Rctx,
PidRef = {term_to_flat_json(Pid), term_to_flat_json(Ref)},
Pid = term_to_flat_json(Pid0),
Ref = term_to_flat_json(Ref0),
PidRef = <<Pid/binary, ":", Ref/binary>>,
MFA = case MFA0 of
{M0, F0, A0} ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{_, _, _} -> convert_mfa(MFA1)

also do we want guards is_atom(M), is_atom(F), is_integer(A), A > 0?

M = atom_to_binary(M0),
@@ -524,8 +535,10 @@ to_flat_json(#rctx{}=Rctx) ->
throw({error, {unexpected, OtherMFA}})
end,
From = case From0 of
{Parent, ParentRef} ->
{term_to_flat_json(Parent), term_to_flat_json(ParentRef)};
{Parent0, ParentRef0} ->
Parent = term_to_flat_json(Parent0),
ParentRef = term_to_flat_json(ParentRef0),
<<Parent/binary, ":", ParentRef/binary>>;
undefined ->
null
end,