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

Avoid calling ejabberd_sm_backend:get_sessions/3 second time when routing presences #4089

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

arcusfelis
Copy link
Contributor

Old code calls get_session_pid for each presence. Again.
We could avoid it.

Proposed changes include:

  • Introduce get_user_present_resources_and_pids, call it in do_route_no_resource function

Why:

  • Slightly faster, because CETS does not need lookup and call tuple_to_session function again
  • We do a lot of presences (could be 80% of traffic), so an optimisation matters

@mongoose-im
Copy link
Collaborator

mongoose-im commented Aug 9, 2023

elasticsearch_and_cassandra_25 / elasticsearch_and_cassandra_mnesia / 3ea695c
Reports root/ big
OK: 369 / Failed: 0 / User-skipped: 38 / Auto-skipped: 0


small_tests_24 / small_tests / 3ea695c
Reports root / small


small_tests_25 / small_tests / 3ea695c
Reports root / small


small_tests_25_arm64 / small_tests / 3ea695c
Reports root / small


ldap_mnesia_24 / ldap_mnesia / 3ea695c
Reports root/ big
OK: 2258 / Failed: 1 / User-skipped: 831 / Auto-skipped: 3

metrics_c2s_SUITE:single:stanza_one
{error,
  {{xmppStanzaReceived,
     {value,340},
     [{times,25,
        {error,
          {badmatch,{value,341}},
          [{metrics_helper,assert_counter,3,
             [{file,
              "/home/circleci/project/big_tests/tests/metrics_helper.erl"},
            {line,36}]},
           {mongoose_helper,do_wait_until,2,
             [{file,
              "/home/circleci/project/big_tests/tests/mongoose_helper.erl"},
            {line,361}]},
           {escalus_story,story,4,
             [{file,
              "/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
            {line,72}]},
           {test_server,ts_tc,3,
             [{file,"test_server.erl"},{line,1783}]},
           {test_server,run_test_case_eval1,6,
             [{file,"test_server.erl"},{line,1292}]},
           {test_server,run_test_case_eval,9,
             [{file,"test_server.erl"},{line,1224}]}]}}],
     ok},
   [{mongoose_helper,do_wait_until,2,
      [{file,"/home/circleci/project/big_tests/tests/mongoose_helper.erl"},
       {line,358}]},
    {escalus_story,story,4,
      [{file,
         "/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
       {line,72}]},
    {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1783}]},
    {test_server,run_test_case_eval1,6,
      [{file,"test_server.erl"},{line,1292}]},
    {test_server,run_test_case_eval,9,
      [{file,"test_server.erl"},{line,1224}]}]}}

Report log


dynamic_domains_pgsql_mnesia_24 / pgsql_mnesia / 3ea695c
Reports root/ big
OK: 4225 / Failed: 0 / User-skipped: 84 / Auto-skipped: 0


dynamic_domains_mysql_redis_25 / mysql_redis / 3ea695c
Reports root/ big
OK: 4193 / Failed: 0 / User-skipped: 116 / Auto-skipped: 0


ldap_mnesia_25 / ldap_mnesia / 3ea695c
Reports root/ big
OK: 2262 / Failed: 0 / User-skipped: 831 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_25 / pgsql_mnesia / 3ea695c
Reports root/ big
OK: 4225 / Failed: 0 / User-skipped: 84 / Auto-skipped: 0

mam_SUITE:rdbms_async_cache_muc_all:muc_configurable_archiveid:muc_no_elements
{failed,
  {mam_SUITE,end_per_testcase,
    {'EXIT',
      {{room_archive_size,0,[{times,200,1}],ok},
       [{mongoose_helper,do_wait_until,2,
          [{file,
             "/home/circleci/project/big_tests/tests/mongoose_helper.erl"},
           {line,358}]},
        {mam_helper,wait_for_room_archive_size,3,
          [{file,
             "/home/circleci/project/big_tests/tests/mam_helper.erl"},
           {line,789}]},
        {mam_helper,clean_room_archive,1,
          [{file,
             "/home/circleci/project/big_tests/tests/mam_helper.erl"},
           {line,733}]},
        {mam_helper,destroy_room,1,
          [{file,
             "/home/circleci/project/big_tests/tests/mam_helper.erl"},
           {line,726}]},
        {mam_SUITE,end_per_testcase,2,
          [{file,
             "/home/circleci/project/big_tests/tests/mam_SUITE.erl"},
           {line,962}]},
        {test_server,do_end_per_testcase,4,
          [{file,"test_server.erl"},{line,1626}]},
        {test_server,run_test_case_eval1,6,
          [{file,"test_server.erl"},{line,1334}]},
        {test_server,run_test_case_eval,9,
          [{file,"test_server.erl"},{line,1223}]}]}}}}

Report log


pgsql_mnesia_24 / pgsql_mnesia / 3ea695c
Reports root/ big
OK: 4610 / Failed: 0 / User-skipped: 91 / Auto-skipped: 0


pgsql_cets_25 / pgsql_cets / 3ea695c
Reports root/ big
OK: 4580 / Failed: 0 / User-skipped: 121 / Auto-skipped: 0


dynamic_domains_mssql_mnesia_25 / odbc_mssql_mnesia / 3ea695c
Reports root/ big
OK: 4222 / Failed: 0 / User-skipped: 87 / Auto-skipped: 0


internal_mnesia_25 / internal_mnesia / 3ea695c
Reports root/ big
OK: 2408 / Failed: 0 / User-skipped: 685 / Auto-skipped: 0


pgsql_mnesia_25 / pgsql_mnesia / 3ea695c
Reports root/ big
OK: 4610 / Failed: 0 / User-skipped: 91 / Auto-skipped: 0


mssql_mnesia_25 / odbc_mssql_mnesia / 3ea695c
Reports root/ big
OK: 4607 / Failed: 0 / User-skipped: 94 / Auto-skipped: 0


mysql_redis_25 / mysql_redis / 3ea695c
Reports root/ big
OK: 4565 / Failed: 8 / User-skipped: 111 / Auto-skipped: 17

mongooseimctl_SUITE:accounts:ban_account
{error,{{badmatch,{"Problem 'exit {{{{badmatch,{error,timeout}},\n         [{mysql_conn,execute_stmt,5,\n            [{file,\n               \"/home/circleci/project/_build/default/lib/mysql/src/mysql_conn.erl\"},\n             {line,569}]},\n          {mysql_conn,handle_call,3,\n            [{file,\n               \"/home/circleci/project/_build/default/lib/mysql/src/mysql_conn.erl\"},\n             {line,350}]},\n          {gen_server,try_handle_call,4,\n            [{file,\"gen_server.erl\"},{line,1149}]},\n          {gen_server,handle_msg,6,\n            [{file,\"gen_server.erl\"},{line,1178}]},\n          {proc_lib,init_p_do_apply,3,\n            [{file,\"proc_lib.erl\"},{line,240}]}]},\n        {gen_server,call,\n          [<0.16399.0>,\n           {execute,auth_set_password_scram,\n             [<<>>,\n              <<\"==MULTI_SCRAM==,64,==SHA256==/lFGNLHjP/UrftSwZF8VPA==|6CrXx+7zRKPGE/+rMo/IE7bSM21h0Mi3PeS8P3seQC8=|UyecPZp/GmByncp0cgnWWON+bPIOSxrbNZt+U2ZvHgY=\">>,\n              <<\"localhost\">>,<<\"mike\">>],\n             no_filtermap_fun,default_timeout},\n           infinity]}},\n         {gen_server,call,\n           ['wpool_pool-mongoose_wpool$rdbms$global$default-1',\n          {sql_cmd,\n            {sql_execute,auth_set_password_scram,\n              [<<>>,\n               <<\"==MULTI_SCRAM==,64,==SHA256==/lFGNLHjP/UrftSwZF8VPA==|6CrXx+7zRKPGE/+rMo/IE7bSM21h0Mi3PeS8P3seQC8=|UyecPZp/GmByncp0cgnWWON+bPIOSxrbNZt+U2ZvHgY=\">>,\n               <<\"localhost\">>,...

Report log

mongooseimctl_SUITE:sessions:status
{error,
  {{badmatch,
     {error,
       {connection_step_failed,
         {{escalus_session,authenticate},
          {client,<<"mike@localhost/res1">>,escalus_tcp,<0.732.2>,
            undefined,
            [{event_client,
               [{event_manager,<0.730.2>},
              {server,<<"localhost">>},
              {username,<<"mike">>},
              {resource,<<"res1">>}]},
             {resource,<<"res1">>},
             {username,<<"mike">>},
             {server,<<"localhost">>},
             {host,<<"localhost">>},
             {port,5222},
             {auth,{escalus_auth,auth_plain}},
             {wspath,undefined},
             {username,<<"mike">>},
             {server,<<"localhost">>},
             {password,<<"nicniema">>},
             {stream_id,<<"e4175943b89fc90e">>}]},
          [{compression,false},
           {starttls,true},
           {stream_management,true},
           {advanced_message_processing,true},
           {client_state_indication,false},
           {sasl_mechanisms,[<<"SCRAM-SHA-256">>,<<"PLAIN">>]},
           {caps,undefined}]},
         {auth_failed,<<"mike">>,
           {xmlel,<<"failure">>,
             [{<<"xmlns">>,
               <<"urn:ietf:params:xml:ns:xmpp-sasl">>}],
             [{xmlel,<<"not-authorized">>,[],[]}]}}}}},
   [{escalus_story,'-start_ready_clients/2-fun-0-',3,
      [{file,
         "/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
       {line,131}]},
    {lists,foldl,3,...

Report log

mongooseimctl_SUITE:stats:stats_global
{error,{{badmatch,{"16\n",0}},
    [{mongooseimctl_SUITE,'-stats_global/1-fun-0-',3,
                [{file,"/home/circleci/project/big_tests/tests/mongooseimctl_SUITE.erl"},
                 {line,1120}]},
     {escalus_story,story,4,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
             {line,72}]},
     {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
     {test_server,run_test_case_eval1,6,
            [{file,"test_server.erl"},{line,1291}]},
     {test_server,run_test_case_eval,9,
            [{file,"test_server.erl"},{line,1223}]}]}}

Report log

mongooseimctl_SUITE:basic:remove_expired_messages_test
{error,
  {{badmatch,
     {error,
       {connection_step_failed,
         {{escalus_session,authenticate},
          {client,<<"mike@localhost/res1">>,escalus_tcp,<0.1067.2>,
            undefined,
            [{event_client,
               [{event_manager,<0.1066.2>},
              {server,<<"localhost">>},
              {username,<<"mike">>},
              {resource,<<"res1">>}]},
             {resource,<<"res1">>},
             {username,<<"mike">>},
             {server,<<"localhost">>},
             {host,<<"localhost">>},
             {port,5222},
             {auth,{escalus_auth,auth_plain}},
             {wspath,undefined},
             {username,<<"mike">>},
             {server,<<"localhost">>},
             {password,<<"nicniema">>},
             {stream_id,<<"69dff9a409b54ee6">>}]},
          [{compression,false},
           {starttls,true},
           {stream_management,true},
           {advanced_message_processing,true},
           {client_state_indication,false},
           {sasl_mechanisms,[<<"SCRAM-SHA-256">>,<<"PLAIN">>]},
           {caps,undefined}]},
         {auth_failed,<<"mike">>,
           {xmlel,<<"failure">>,
             [{<<"xmlns">>,
               <<"urn:ietf:params:xml:ns:xmpp-sasl">>}],
             [{xmlel,<<"not-authorized">>,[],[]}]}}}}},
   [{escalus_story,'-start_ready_clients/2-fun-0-',3,
      [{file,
         "/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
       {line,131}]},
    {lists,foldl,...

Report log

muc_SUITE:room_registration_race_condition:check_presence_route_to_offline_room
{error,{{badrpc,timeout},
    [{escalus_rpc,call_with_cookie_match,
            [mongooseim@localhost,ejabberd_admin,register,
             [<<"alicE_unnamed_2508_check_presence_route_to_offline_room_2509">>,
            <<"localhost">>,<<"matygrysa">>],
             3000,mongooseim],
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_rpc.erl"},
             {line,34}]},
     {lists,foreach_1,2,[{file,"lists.erl"},{line,1442}]},
     {escalus_ejabberd,create_users,2,
               [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_ejabberd.erl"},
              {line,211}]},
     {escalus_fresh,create_users,2,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_fresh.erl"},
             {line,62}]},
     {escalus_fresh,story,3,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_fresh.erl"},
             {line,27}]},
     {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
     {test_server,run_test_case_eval1,6,
            [{file,"test_server.erl"},{line,1291}]},
     {test_server,run_test_case_eval,9,
            [{file,"test_server.erl"},{line,1223}]}]}}

Report log

muc_SUITE:room_registration_race_condition:check_message_route_to_offline_room
{error,{{badrpc,timeout},
    [{escalus_rpc,call_with_cookie_match,
            [mongooseim@localhost,ejabberd_admin,register,
             [<<"alicE_unnamed_2508_check_message_route_to_offline_room_2510">>,
            <<"localhost">>,<<"matygrysa">>],
             3000,mongooseim],
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_rpc.erl"},
             {line,34}]},
     {lists,foreach_1,2,[{file,"lists.erl"},{line,1442}]},
     {escalus_ejabberd,create_users,2,
               [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_ejabberd.erl"},
              {line,211}]},
     {escalus_fresh,create_users,2,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_fresh.erl"},
             {line,62}]},
     {escalus_fresh,story,3,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_fresh.erl"},
             {line,27}]},
     {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
     {test_server,run_test_case_eval1,6,
            [{file,"test_server.erl"},{line,1291}]},
     {test_server,run_test_case_eval,9,
            [{file,"test_server.erl"},{line,1223}]}]}}

Report log

muc_SUITE:register:init_per_group
{'EXIT',{{badrpc,timeout},
     [{escalus_rpc,call_with_cookie_match,
             [mongooseim@localhost,ejabberd_admin,register,
            [<<"alicE">>,<<"localhost">>,<<"matygrysa">>],
            3000,mongooseim],
             [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_rpc.erl"},
            {line,34}]},
      {lists,foreach_1,2,[{file,"lists.erl"},{line,1442}]},
      {escalus_ejabberd,create_users,2,
              [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_ejabberd.erl"},
               {line,211}]},
      {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
      {test_server,run_test_case_eval1,6,
             [{file,"test_server.erl"},{line,1379}]},
      {test_server,run_test_case_eval,9,
             [{file,"test_server.erl"},{line,1223}]}]}}

Report log

pubsub_SUITE:tree+node_config:disable_payload_test
{error,{{badrpc,timeout},
    [{escalus_rpc,call_with_cookie_match,
            [mongooseim@localhost,ejabberd_admin,register,
             [<<"bOb_disable_payload_test_2724">>,<<"localhost">>,
            <<"makrolika">>],
             3000,mongooseim],
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_rpc.erl"},
             {line,34}]},
     {lists,foreach_1,2,[{file,"lists.erl"},{line,1442}]},
     {escalus_ejabberd,create_users,2,
               [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_ejabberd.erl"},
              {line,211}]},
     {escalus_fresh,create_users,2,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_fresh.erl"},
             {line,62}]},
     {escalus_fresh,story,3,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_fresh.erl"},
             {line,27}]},
     {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
     {test_server,run_test_case_eval1,6,
            [{file,"test_server.erl"},{line,1291}]},
     {test_server,run_test_case_eval,9,
            [{file,"test_server.erl"},{line,1223}]}]}}

Report log

pubsub_SUITE:tree+hometree_specific:can_create_node_with_existing_parent_path
{error,{{badmatch,false},
    [{pubsub_tools,check_response,2,
             [{file,"/home/circleci/project/big_tests/tests/pubsub_tools.erl"},
            {line,444}]},
     {pubsub_tools,receive_response,3,
             [{file,"/home/circleci/project/big_tests/tests/pubsub_tools.erl"},
            {line,434}]},
     {pubsub_tools,receive_and_check_response,4,
             [{file,"/home/circleci/project/big_tests/tests/pubsub_tools.erl"},
            {line,424}]},
     {pubsub_SUITE,'-can_create_node_with_existing_parent_path/1-fun-0-',
             1,
             [{file,"/home/circleci/project/big_tests/tests/pubsub_SUITE.erl"},
            {line,1783}]},
     {escalus_story,story,4,
            [{file,"/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
             {line,72}]},
     {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1782}]},
     {test_server,run_test_case_eval1,6,
            [{file,"test_server.erl"},{line,1291}]},
     {test_server,run_test_case_eval,9,
            [{file,"test_server.erl"},{line,1223}]}]}}

Report log

@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.50% 🎉

Comparison is base (257371d) 83.37% compared to head (594eb9b) 83.87%.
Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4089      +/-   ##
==========================================
+ Coverage   83.37%   83.87%   +0.50%     
==========================================
  Files         551      551              
  Lines       33544    33548       +4     
==========================================
+ Hits        27967    28139     +172     
+ Misses       5577     5409     -168     
Files Changed Coverage Δ
src/ejabberd_sm.erl 88.40% <100.00%> (-0.20%) ⬇️

... and 27 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…ting presences

Old code calls get_session_pid for each presence
We could avoid it
@arcusfelis arcusfelis force-pushed the no-extra-get-session-call-for-presences branch from 3ea695c to 594eb9b Compare August 9, 2023 14:09
@mongoose-im
Copy link
Collaborator

mongoose-im commented Aug 9, 2023

elasticsearch_and_cassandra_25 / elasticsearch_and_cassandra_mnesia / 594eb9b
Reports root/ big
OK: 369 / Failed: 0 / User-skipped: 38 / Auto-skipped: 0


small_tests_24 / small_tests / 594eb9b
Reports root / small


small_tests_25_arm64 / small_tests / 594eb9b
Reports root / small


small_tests_25 / small_tests / 594eb9b
Reports root / small


ldap_mnesia_24 / ldap_mnesia / 594eb9b
Reports root/ big
OK: 2262 / Failed: 0 / User-skipped: 831 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_24 / pgsql_mnesia / 594eb9b
Reports root/ big
OK: 4225 / Failed: 0 / User-skipped: 84 / Auto-skipped: 0


dynamic_domains_mysql_redis_25 / mysql_redis / 594eb9b
Reports root/ big
OK: 4193 / Failed: 0 / User-skipped: 116 / Auto-skipped: 0


ldap_mnesia_25 / ldap_mnesia / 594eb9b
Reports root/ big
OK: 2262 / Failed: 0 / User-skipped: 831 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_25 / pgsql_mnesia / 594eb9b
Reports root/ big
OK: 4225 / Failed: 0 / User-skipped: 84 / Auto-skipped: 0


dynamic_domains_mssql_mnesia_25 / odbc_mssql_mnesia / 594eb9b
Reports root/ big
OK: 4222 / Failed: 0 / User-skipped: 87 / Auto-skipped: 0


pgsql_cets_25 / pgsql_cets / 594eb9b
Reports root/ big
OK: 4580 / Failed: 0 / User-skipped: 121 / Auto-skipped: 0


internal_mnesia_25 / internal_mnesia / 594eb9b
Reports root/ big
OK: 2408 / Failed: 0 / User-skipped: 685 / Auto-skipped: 0


pgsql_mnesia_24 / pgsql_mnesia / 594eb9b
Reports root/ big
OK: 4610 / Failed: 0 / User-skipped: 91 / Auto-skipped: 0


mysql_redis_25 / mysql_redis / 594eb9b
Reports root/ big
OK: 4590 / Failed: 0 / User-skipped: 111 / Auto-skipped: 0


pgsql_mnesia_25 / pgsql_mnesia / 594eb9b
Reports root/ big
OK: 4610 / Failed: 0 / User-skipped: 91 / Auto-skipped: 0


mssql_mnesia_25 / odbc_mssql_mnesia / 594eb9b
Reports root/ big
OK: 4607 / Failed: 0 / User-skipped: 94 / Auto-skipped: 0

@arcusfelis arcusfelis marked this pull request as ready for review August 9, 2023 14:40
Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

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

Looks good 👍

Copy link
Collaborator

@NelsonVides NelsonVides left a comment

Choose a reason for hiding this comment

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

Ah, fantastic! 🔥

@NelsonVides NelsonVides merged commit 04f9591 into master Aug 9, 2023
4 checks passed
@NelsonVides NelsonVides deleted the no-extra-get-session-call-for-presences branch August 9, 2023 15:24
@chrzaszcz chrzaszcz added this to the 6.2.0 milestone Dec 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants