ejabberd icon indicating copy to clipboard operation
ejabberd copied to clipboard

add some metrics to the "hooks_type_test" module

Open fdie opened this issue 4 years ago • 4 comments

I found "hooks_type_test" very usefull and added some metrics to evaluate the performance of the various modules on a runnning system. I don't know all the usages of "hooks_type_test", but here is how I use it, maybe helpfull for others ? I generally grab some hook call with redbug :

erl> redbug:start("mod_mam:user_send_packet").

then define the args of the trace

erl> Acc = {{message,...},#{...}}.  % copy paste the args of the call

To feed in the associated hook method in hooks_type_test to get some execution timings:

erl> hooks_type_test:user_send_packet(Acc).
{
   {{message,...}, #{...}},
   % added map with detailed metrics and totals
   #{
      measures => [
       "{microseconds, reductions, {module, function}}",
        {2,14,{mod_privacy,user_send_packet}},
        {1,12,{mod_caps,user_send_packet}},
        {34,335,{mod_mam,user_send_packet}},
        {12,68,{mod_mam,user_send_packet_strip_tag}},
        {1,13,{mod_vcard_xupdate,user_send_packet}},
        {error,14,{mod_service_log,log_user_send}},
        {1,12,{mod_privilege,process_presence_out}},
        {44,28,{mod_ping,user_send}},
        {1,12,{mod_multicast,user_send_packet}},
        {error,12,{mod_metrics,user_send_packet}},
        {121,266,{mod_carboncopy,user_send_packet}}],
      total_microseconds => 217,
      total_reductions => 786
   }
}

I may be wrong, but I don't think this module is used in some specific context, thus it should be possible to modifiy the return values without breaking anything. If I'm wrong the durations may be rather sent to the console to restore the former return value.

I kept the previous version with all the explicit method calls as commented out code.

Here is a sample of the generated code:

%% called at ejabberd_c2s.erl:923
roster_get(Acc0, A) ->
    %% Acc1 = mod_roster:get_user_roster(Acc0, A),
    %% Acc2 = mod_shared_roster_ldap:get_user_roster(Acc1, A),
    %% Acc3 = mod_shared_roster:get_user_roster(Acc2, A),
    %% Acc3.
    run_metrics([Acc0, A], [
          {mod_roster, get_user_roster}
         ,{mod_shared_roster_ldap, get_user_roster}
         ,{mod_shared_roster, get_user_roster}
    ]).

Always run metrics twice, sometimes you may measure without/with caching ;-)

fdie avatar Mar 21 '21 11:03 fdie

Coverage Status

Coverage remained the same at 35.048% when pulling 444e08d160c245986a26637dabb658c6d6e1d8af on fdie:some_hook_metrics into 453d504fb796cc1ac1800287794d86c0242d2d76 on processone:master.

coveralls avatar Mar 21 '21 11:03 coveralls

@prefiks: What do you think?

Neustradamus avatar Jul 04 '21 23:07 Neustradamus

@fdie , did you see https://github.com/processone/ejabberd/pull/3756 ?

badlop avatar Mar 22 '22 12:03 badlop

@fdie: Have you seen the @badlop comment?

Neustradamus avatar Apr 30 '22 21:04 Neustradamus

@fdie: Have you looked previous comments?

Neustradamus avatar Oct 14 '22 17:10 Neustradamus

@fdie: Have you seen the @badlop comment?

Neustradamus avatar May 14 '23 13:05 Neustradamus