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

Mongoose mam id rework #4412

Merged
merged 2 commits into from
Dec 4, 2024
Merged

Mongoose mam id rework #4412

merged 2 commits into from
Dec 4, 2024

Conversation

NelsonVides
Copy link
Collaborator

@NelsonVides NelsonVides commented Dec 3, 2024

Here we rid of all native code, and most critically

Benchmark:

  def next_id() do
    Benchee.run(
      %{
        "native code" => fn list ->
          Enum.map(list, fn t -> :mongoose_mam_id.next_unique(t) end)
        end,
        "pure erlang" => fn list ->
          Enum.map(list, fn t -> :mongoose_mam_id_2.next_unique(t) end)
        end,
      },
      inputs: %{
        "1M monotonic" => monotonic_list(100_000_000)
      },
      formatters:
      [
        {Benchee.Formatters.Console, extended_statistics: true}
      ],
      parallel: 1,
      time: 5,
      warmup: 0
    )
  end

  defp monotonic_list(size) do
    fun = fn(_, [head | _] = acc) ->
      next = head + :rand.uniform(20) - 1
      [next | acc]
    end
    :lists.reverse(:lists.foldl(fun, [:rand.uniform(20)], :lists.seq(1, size)))
  end

returns

Operating System: macOS
CPU Information: Apple M3 Pro
Number of Available Cores: 12
Available memory: 36 GB
Elixir 1.17.3
Erlang 27.1.2
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 0 ns
time: 5 s
memory time: 0 ns
reduction time: 0 ns
parallel: 1
inputs: 1M monotonic
Estimated total run time: 10 s

Benchmarking native code with input 1M monotonic ...
Benchmarking pure erlang with input 1M monotonic ...
Calculating statistics...
Formatting results...

Name                  ips        average  deviation         median         99th %
pure erlang          0.31         3.23 s    ±10.49%         3.23 s         3.47 s
native code          0.28         3.54 s     ±6.26%         3.54 s         3.70 s

Comparison:
pure erlang          0.31
native code          0.28 - 1.10x slower +0.32 s

Extended statistics:

Name                minimum        maximum    sample size                     mode
pure erlang          2.99 s         3.47 s              2                     None
native code          3.39 s         3.70 s              2                     None

@mongoose-im

This comment was marked as outdated.

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.30%. Comparing base (33fe8d6) to head (761b6ee).
Report is 6 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4412      +/-   ##
==========================================
- Coverage   85.31%   85.30%   -0.01%     
==========================================
  Files         550      550              
  Lines       33903    33905       +2     
==========================================
  Hits        28923    28923              
- Misses       4980     4982       +2     

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

@mongoose-im

This comment was marked as outdated.

@mongoose-im

This comment was marked as outdated.

```elixir
  def next_id() do
    Benchee.run(
      %{
        "native code" => fn list ->
          Enum.map(list, fn t -> :mongoose_mam_id.next_unique(t) end)
        end,
        "pure erlang" => fn list ->
          Enum.map(list, fn t -> :mongoose_mam_id_2.next_unique(t) end)
        end,
      },
      inputs: %{
        "1M monotonic" => monotonic_list(100_000_000)
      },
      formatters:
      [
        {Benchee.Formatters.Console, extended_statistics: true}
      ],
      parallel: 1,
      time: 5,
      warmup: 0
    )
  end

  defp monotonic_list(size) do
    fun = fn(_, [head | _] = acc) ->
      next = head + :rand.uniform(20) - 1
      [next | acc]
    end
    :lists.reverse(:lists.foldl(fun, [:rand.uniform(20)], :lists.seq(1, size)))
  end
```

returns

```
Operating System: macOS
CPU Information: Apple M3 Pro
Number of Available Cores: 12
Available memory: 36 GB
Elixir 1.17.3
Erlang 27.1.2
JIT enabled: true

Benchmark suite executing with the following configuration:
warmup: 0 ns
time: 5 s
memory time: 0 ns
reduction time: 0 ns
parallel: 1
inputs: 1M monotonic
Estimated total run time: 10 s

Benchmarking native code with input 1M monotonic ...
Benchmarking pure erlang with input 1M monotonic ...
Calculating statistics...
Formatting results...

Name                  ips        average  deviation         median         99th %
pure erlang          0.31         3.23 s    ±10.49%         3.23 s         3.47 s
native code          0.28         3.54 s     ±6.26%         3.54 s         3.70 s

Comparison:
pure erlang          0.31
native code          0.28 - 1.10x slower +0.32 s

Extended statistics:

Name                minimum        maximum    sample size                     mode
pure erlang          2.99 s         3.47 s              2                     None
native code          3.39 s         3.70 s              2                     None
```
@mongoose-im
Copy link
Collaborator

mongoose-im commented Dec 4, 2024

elasticsearch_and_cassandra_27 / elasticsearch_and_cassandra_mnesia / 761b6ee
Reports root/ big
OK: 473 / Failed: 0 / User-skipped: 49 / Auto-skipped: 0


small_tests_27 / small_tests / 761b6ee
Reports root / small


small_tests_26 / small_tests / 761b6ee
Reports root / small


small_tests_27_arm64 / small_tests / 761b6ee
Reports root / small


ldap_mnesia_26 / ldap_mnesia / 761b6ee
Reports root/ big
OK: 2350 / Failed: 1 / User-skipped: 912 / Auto-skipped: 1

cluster_commands_SUITE:clustered:init_per_group
{'EXIT',
  {{verify_result,[],
     [{times,20,
        [{#{node => mongooseim2@localhost},[mongooseim@localhost],true},
         {#{node => mongooseim@localhost},
        [mongooseim2@localhost],
        true}]}],
     ok},
   [{mongoose_helper,do_wait_until,2,
      [{file,
         "/home/circleci/project/big_tests/../test/common/mongoose_helper.erl"},
       {line,359}]},
    {distributed_helper,verify_result,2,
      [{file,
         "/home/circleci/project/big_tests/../test/common/distributed_helper.erl"},
       {line,72}]},
    {distributed_helper,add_node_to_cluster,2,
      [{file,
         "/home/circleci/project/big_tests/../test/common/distributed_helper.erl"},
       {line,36}]},
    {cluster_commands_SUITE,init_per_group,2,
      [{file,
         "/home/circleci/project/big_tests/tests/cluster_commands_SUITE.erl"},
       {line,96}]},
    {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1793}]},
    {test_server,run_test_case_eval1,6,
      [{file,"test_server.erl"},{line,1390}]},
    {test_server,run_test_case_eval,9,
      [{file,"test_server.erl"},{line,1234}]}]}}

Report log

cluster_commands_SUITE:join_successful_prompt
{error,
  {{verify_result,[],
     [{times,20,
        [{#{node => mongooseim2@localhost},[mongooseim@localhost],true},
         {#{node => mongooseim@localhost},
        [mongooseim2@localhost],
        true}]}],
     ok},
   [{mongoose_helper,do_wait_until,2,
      [{file,
         "/home/circleci/project/big_tests/../test/common/mongoose_helper.erl"},
       {line,359}]},
    {distributed_helper,verify_result,2,
      [{file,
         "/home/circleci/project/big_tests/../test/common/distributed_helper.erl"},
       {line,72}]},
    {cluster_commands_SUITE,join_successful_prompt,1,
      [{file,
         "/home/circleci/project/big_tests/tests/cluster_commands_SUITE.erl"},
       {line,215}]},
    {test_server,ts_tc,3,[{file,"test_server.erl"},{line,1793}]},
    {test_server,run_test_case_eval1,6,
      [{file,"test_server.erl"},{line,1302}]},
    {test_server,run_test_case_eval,9,
      [{file,"test_server.erl"},{line,1234}]}]}}

Report log


ldap_mnesia_27 / ldap_mnesia / 761b6ee
Reports root/ big
OK: 2352 / Failed: 0 / User-skipped: 912 / Auto-skipped: 0


dynamic_domains_mysql_redis_27 / mysql_redis / 761b6ee
Reports root/ big
OK: 4724 / Failed: 0 / User-skipped: 154 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_26 / pgsql_mnesia / 761b6ee
Reports root/ big
OK: 4759 / Failed: 0 / User-skipped: 119 / Auto-skipped: 0


dynamic_domains_pgsql_mnesia_27 / pgsql_mnesia / 761b6ee
Reports root/ big
OK: 4759 / Failed: 0 / User-skipped: 119 / Auto-skipped: 0


internal_mnesia_27 / internal_mnesia / 761b6ee
Reports root/ big
OK: 2494 / Failed: 0 / User-skipped: 770 / Auto-skipped: 0


pgsql_cets_27 / pgsql_cets / 761b6ee
Reports root/ big
OK: 4849 / Failed: 0 / User-skipped: 188 / Auto-skipped: 0


dynamic_domains_mssql_mnesia_27 / odbc_mssql_mnesia / 761b6ee
Reports root/ big
OK: 4754 / Failed: 0 / User-skipped: 124 / Auto-skipped: 0


cockroachdb_cets_27 / cockroachdb_cets / 761b6ee
Reports root/ big
OK: 4848 / Failed: 1 / User-skipped: 188 / Auto-skipped: 0

adhoc_SUITE:adhoc:disco_info_sm_commands
{error,
  {timeout_when_waiting_for_stanza,
    [{escalus_client,wait_for_stanza,
       [{client,<<"alice_disco_info_sm_commands_43@localhost/res1">>,
          escalus_tcp,<0.2530.0>,
          [{event_manager,<0.2513.0>},
           {server,<<"localhost">>},
           {username,<<"alicE_disco_info_sm_commands_43">>},
           {resource,<<"res1">>}],
          [{event_client,
             [{event_manager,<0.2513.0>},
            {server,<<"localhost">>},
            {username,<<"alicE_disco_info_sm_commands_43">>},
            {resource,<<"res1">>}]},
           {resource,<<"res1">>},
           {username,<<"alice_disco_info_sm_commands_43">>},
           {server,<<"localhost">>},
           {host,<<"localhost">>},
           {port,5222},
           {auth,{escalus_auth,auth_plain}},
           {wspath,undefined},
           {username,<<"alicE_disco_info_sm_commands_43">>},
           {server,<<"localhost">>},
           {password,<<"matygrysa">>},
           {stream_id,<<"d8ad8b5a67a6a3fd">>}]},
        5000],
       [{file,
          "/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_client.erl"},
        {line,136}]},
     {adhoc_SUITE,'-disco_info_sm_commands/1-fun-0-',1,
       [{file,"/home/circleci/project/big_tests/tests/adhoc_SUITE.erl"},
        {line,131}]},
     {escalus_story,story,4,
       [{file,
          "/home/circleci/project/big_tests/_build/default/lib/escalus/src/escalus_story.erl"},
        {line,72}]},
     {test_server,ts_tc...

Report log


pgsql_mnesia_27 / pgsql_mnesia / 761b6ee
Reports root/ big
OK: 5150 / Failed: 0 / User-skipped: 128 / Auto-skipped: 0


mssql_mnesia_27 / odbc_mssql_mnesia / 761b6ee
Reports root/ big
OK: 5145 / Failed: 0 / User-skipped: 133 / Auto-skipped: 0


pgsql_mnesia_26 / pgsql_mnesia / 761b6ee
Reports root/ big
OK: 5150 / Failed: 0 / User-skipped: 128 / Auto-skipped: 0


mysql_redis_27 / mysql_redis / 761b6ee
Reports root/ big
OK: 5129 / Failed: 0 / User-skipped: 149 / Auto-skipped: 0


small_tests_26 / small_tests / 761b6ee
Reports root / small


ldap_mnesia_26 / ldap_mnesia / 761b6ee
Reports root/ big
OK: 2352 / Failed: 0 / User-skipped: 912 / Auto-skipped: 0


cockroachdb_cets_27 / cockroachdb_cets / 761b6ee
Reports root/ big
OK: 4849 / Failed: 0 / User-skipped: 188 / Auto-skipped: 0

Base automatically changed from remove_dead_tools to master December 4, 2024 16:49
@NelsonVides NelsonVides marked this pull request as ready for review December 4, 2024 16:50
Copy link
Contributor

@arcusfelis arcusfelis left a comment

Choose a reason for hiding this comment

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

looks ok

@arcusfelis arcusfelis merged commit d8bb43d into master Dec 4, 2024
4 checks passed
@arcusfelis arcusfelis deleted the mongoose_mam_id branch December 4, 2024 16:53
@jacekwegr jacekwegr added this to the 6.3.1 milestone Dec 23, 2024
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