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

Replace p1_time_compat with direct OTP functions #2498

Merged
merged 5 commits into from
Oct 18, 2019
Merged

Conversation

NelsonVides
Copy link
Collaborator

Pretty much a mechanical change. Need to see results from CI.

@codecov
Copy link

codecov bot commented Oct 17, 2019

Codecov Report

Merging #2498 into master will decrease coverage by 0.05%.
The diff coverage is 88.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2498      +/-   ##
==========================================
- Coverage   78.93%   78.88%   -0.06%     
==========================================
  Files         340      340              
  Lines       29329    29324       -5     
==========================================
- Hits        23152    23131      -21     
- Misses       6177     6193      +16
Impacted Files Coverage Δ
src/mod_commands.erl 96.07% <ø> (ø) ⬆️
src/jingle_sip/mod_jingle_sip_backend.erl 80% <ø> (ø) ⬆️
src/sasl/cyrsasl_anonymous.erl 75% <ø> (ø) ⬆️
src/mod_offline_mnesia.erl 45.31% <0%> (ø) ⬆️
src/gen_iq_handler.erl 59.09% <0%> (ø) ⬆️
src/mod_muc.erl 75.13% <0%> (ø) ⬆️
src/auth/ejabberd_auth_external.erl 32.38% <0%> (+0.3%) ⬆️
src/mod_time.erl 91.3% <100%> (ø) ⬆️
...rc/stream_management/stream_management_stale_h.erl 71.05% <100%> (ø) ⬆️
src/global_distrib/mod_global_distrib_worker.erl 80.95% <100%> (ø) ⬆️
... and 35 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db22255...318cf32. Read the comment docs.

@mongoose-im

This comment has been minimized.

@mongoose-im
Copy link
Collaborator

7343.1 / Erlang 22.0 / small_tests / 05f0f10
Reports root / small

@mongoose-im
Copy link
Collaborator

mongoose-im commented Oct 17, 2019

7344.1 / Erlang 22.0 / small_tests / 1347427
Reports root / small


7344.2 / Erlang 22.0 / internal_mnesia / 1347427
Reports root/ big
OK: 1267 / Failed: 0 / User-skipped: 136 / Auto-skipped: 0


7344.3 / Erlang 22.0 / odbc_mssql_mnesia / 1347427
Reports root/ big
OK: 2484 / Failed: 0 / User-skipped: 199 / Auto-skipped: 0


7344.4 / Erlang 22.0 / mysql_redis / 1347427
Reports root/ big
OK: 2479 / Failed: 0 / User-skipped: 204 / Auto-skipped: 0


7344.7 / Erlang 22.0 / elasticsearch_and_cassandra_mnesia / 1347427
Reports root/ big
OK: 328 / Failed: 0 / User-skipped: 28 / Auto-skipped: 0


7344.6 / Erlang 22.0 / ldap_mnesia / 1347427
Reports root/ big
OK: 1236 / Failed: 0 / User-skipped: 167 / Auto-skipped: 0


7344.5 / Erlang 22.0 / riak_mnesia / 1347427
Reports root/ big
OK: 1398 / Failed: 0 / User-skipped: 145 / Auto-skipped: 0


7344.9 / Erlang 21.3 / pgsql_mnesia / 1347427
Reports root/ big / small
OK: 2497 / Failed: 0 / User-skipped: 186 / Auto-skipped: 0

Copy link
Member

@fenek fenek left a comment

Choose a reason for hiding this comment

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

There are some p1_time_compat leftovers in small tests. :)

Copy link
Contributor

@michalwski michalwski left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! Few things:

@@ -1151,7 +1151,7 @@ wait_before_reconnect(StateData) ->
undefined_delay ->
%% The initial delay is random between 1 and 15 seconds
%% Return a random integer between 1000 and 15000
{_, _, MicroSecs} = p1_time_compat:timestamp(),
MicroSecs = erlang:system_time(microsecond),
Copy link
Contributor

Choose a reason for hiding this comment

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

Taking into account the comment above, current implementation is less random as far as I can reason about it. Also since we want a random number, maybe there is a better way than calculate it from a timestamp?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure this makes much of a difference, it's not a place were cryptographically safe randomization makes any difference. We just want to wait some random amount of time between 1 an 15 seconds. The fact that this function might run at unpredictable times makes it sufficiently random for our purposes I think 🙁
An option would be to do X = rand:uniform(14000), X+1000, but the performance is pretty much the same (I've just measure it on my laptop with timer:tc over a 10M repeats), and rand is saving seeds into the process dictionary. If you prefer that I can quickly change it, but I don't think it matters much 🤷‍♂️

@@ -39,7 +39,7 @@
-spec start(Host :: jid:lserver(), Opts :: proplists:proplist()) -> any().
start(Host, Opts0) ->
ResendAfterMs = proplists:get_value(resend_after_ms, Opts0, 200),
ResendAfter = p1_time_compat:convert_time_unit(ResendAfterMs, milli_seconds, native),
ResendAfter = erlang:convert_time_unit(ResendAfterMs, milli_seconds, native),
Copy link
Contributor

Choose a reason for hiding this comment

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

The milli_seconds is a deprecated time unit. See: http://erlang.org/doc/man/erlang.html#type-deprecated_time_unit it was used in Erlang/OTP 18 as far as I remember and changed to millisecond in later. See: http://erlang.org/doc/man/erlang.html#type_time_unit

@@ -103,10 +103,10 @@ maybe_store_message({From, To, Acc0, Packet} = FPacket) ->
?DEBUG("Storing global message id=~s from=~s to=~s to "
"resend after ~B ms (bounce_ttl=~B)",
[ID, jid:to_binary(From), jid:to_binary(To),
p1_time_compat:convert_time_unit(opt(resend_after), native, milli_seconds),
erlang:convert_time_unit(opt(resend_after), native, milli_seconds),
Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecated milli_seconds

QueueTimeNative = p1_time_compat:monotonic_time() - Stamp,
QueueTimeUS = p1_time_compat:convert_time_unit(QueueTimeNative, native, micro_seconds),
QueueTimeNative = erlang:monotonic_time() - Stamp,
QueueTimeUS = erlang:convert_time_unit(QueueTimeNative, native, micro_seconds),
Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecated micro_seconds.

mongoose_metrics:update(global, ?GLOBAL_DISTRIB_SEND_QUEUE_TIME(ToHost), QueueTimeUS),
ClockTime = p1_time_compat:system_time(micro_seconds),
ClockTime = erlang:system_time(micro_seconds),
Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecated micro_seconds.

@@ -194,7 +194,7 @@ microseconds_to_datetime(MicroSeconds) when is_integer(MicroSeconds) ->
-spec generate_message_id() -> integer().
generate_message_id() ->
{ok, NodeId} = ejabberd_node_id:node_id(),
CandidateStamp = p1_time_compat:os_system_time(micro_seconds),
CandidateStamp = erlang:system_time(micro_seconds),
Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecated micro_seconds.

@@ -544,7 +544,7 @@ schedule_report(Ack, #state{sent = Sent} = S) ->
ReportRid = Ack + 1,
try
{ReportRid, TimeSent, _} = lists:keyfind(ReportRid, 1, Sent),
ElapsedTimeMillis = p1_time_compat:monotonic_time(milli_seconds) - TimeSent,
ElapsedTimeMillis = erlang:monotonic_time(milli_seconds) - TimeSent,
Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecated milli_seconds.

@@ -670,7 +670,7 @@ send_to_handler({_, Pid}, #xmlel{name = <<"body">>} = Wrapped, State) ->
send_wrapped_to_handler(Pid, Wrapped, State);
send_to_handler({Rid, Pid}, Data, State) ->
{Wrapped, NS} = bosh_wrap(Data, Rid, State),
NS2 = cache_response({Rid, p1_time_compat:monotonic_time(milli_seconds), Wrapped}, NS),
NS2 = cache_response({Rid, erlang:monotonic_time(milli_seconds), Wrapped}, NS),
Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecated milli_seconds.

@@ -379,7 +379,7 @@ lookup_recent_messages(ArcJID, WithJID, Before, Limit) ->
rsm => #rsm_in{direction = before, id = undefined}, % last msgs
start_ts => undefined,
end_ts => Before * 1000000,
now => p1_time_compat:os_system_time(micro_seconds),
now => os:system_time(micro_seconds),
Copy link
Contributor

Choose a reason for hiding this comment

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

Deprecated micro_seconds.

src/mod_last.erl Outdated
@@ -131,7 +131,7 @@ process_local_iq(_From, _To, Acc,
get_node_uptime() ->
case ejabberd_config:get_local_option(node_start) of
{_, _, _} = StartNow ->
now_to_seconds(p1_time_compat:timestamp()) - now_to_seconds(StartNow);
erlang:system_time(seconds) - now_to_seconds(StartNow);
Copy link
Contributor

Choose a reason for hiding this comment

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

I realized just now, that seconds is also deprecated time unit :) the correct one is just second without the s. I'm not going back to all the previous places where seconds unit were used, I sure you'll find them easily. Also I stop pointing other deprecated time units unless I spot one I didn't comment yet.

@NelsonVides
Copy link
Collaborator Author

@fenek small tests done, sorry I forgot that 😅
@michalwski about user, I was having a look at that, and I think it gets quite complicated, I think out of the scope of p1_time_compat. It's used in tons of places and the values it returns are passed along a ton of others, not a mechanical change perhaps 😞
Also, the damn deprecated time_units, that surprised me xD

@mongoose-im
Copy link
Collaborator

mongoose-im commented Oct 17, 2019

7348.1 / Erlang 22.0 / small_tests / 98d94a6
Reports root / small


7348.2 / Erlang 22.0 / internal_mnesia / 98d94a6
Reports root/ big
OK: 1269 / Failed: 0 / User-skipped: 136 / Auto-skipped: 0


7348.3 / Erlang 22.0 / odbc_mssql_mnesia / 98d94a6
Reports root/ big
OK: 2486 / Failed: 0 / User-skipped: 199 / Auto-skipped: 0


7348.4 / Erlang 22.0 / mysql_redis / 98d94a6
Reports root/ big
OK: 2481 / Failed: 0 / User-skipped: 204 / Auto-skipped: 0


7348.7 / Erlang 22.0 / elasticsearch_and_cassandra_mnesia / 98d94a6
Reports root/ big
OK: 328 / Failed: 0 / User-skipped: 28 / Auto-skipped: 0


7348.6 / Erlang 22.0 / ldap_mnesia / 98d94a6
Reports root/ big
OK: 1238 / Failed: 0 / User-skipped: 167 / Auto-skipped: 0


7348.5 / Erlang 22.0 / riak_mnesia / 98d94a6
Reports root/ big
OK: 1400 / Failed: 0 / User-skipped: 145 / Auto-skipped: 0


7348.9 / Erlang 21.3 / pgsql_mnesia / 98d94a6
Reports root/ big / small
OK: 2499 / Failed: 0 / User-skipped: 186 / Auto-skipped: 0

@mongoose-im
Copy link
Collaborator

mongoose-im commented Oct 18, 2019

7349.1 / Erlang 22.0 / small_tests / f407a76
Reports root / small


7349.2 / Erlang 22.0 / internal_mnesia / f407a76
Reports root/ big
OK: 1269 / Failed: 0 / User-skipped: 136 / Auto-skipped: 0


7349.3 / Erlang 22.0 / odbc_mssql_mnesia / f407a76
Reports root/ big
OK: 2486 / Failed: 0 / User-skipped: 199 / Auto-skipped: 0


7349.4 / Erlang 22.0 / mysql_redis / f407a76
Reports root/ big
OK: 2481 / Failed: 0 / User-skipped: 204 / Auto-skipped: 0


7349.7 / Erlang 22.0 / elasticsearch_and_cassandra_mnesia / f407a76
Reports root/ big
OK: 328 / Failed: 0 / User-skipped: 28 / Auto-skipped: 0


7349.6 / Erlang 22.0 / ldap_mnesia / f407a76
Reports root/ big
OK: 1238 / Failed: 0 / User-skipped: 167 / Auto-skipped: 0


7349.5 / Erlang 22.0 / riak_mnesia / f407a76
Reports root/ big
OK: 1400 / Failed: 0 / User-skipped: 145 / Auto-skipped: 0


7349.9 / Erlang 21.3 / pgsql_mnesia / f407a76
Reports root/ big / small
OK: 2499 / Failed: 0 / User-skipped: 186 / Auto-skipped: 0

Copy link
Contributor

@michalwski michalwski 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 to be merged now.

I think we can live with usec for now. Maybe sometime in the future we'll remove it as well.

Regarding the randomization, it can be like it is now. It just looks a bit awkward to see random number is calculated from time but it does the job. Most probably back then it was far more efficient then using proper random generator.

@michalwski michalwski merged commit 2a3b68c into master Oct 18, 2019
@michalwski michalwski deleted the out_p1_time_compat branch October 18, 2019 08:20
@michalwski michalwski added this to the 3.6.0 milestone Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants