-
Notifications
You must be signed in to change notification settings - Fork 428
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
Conversation
09ba93d
to
cd5702e
Compare
cd5702e
to
0e8e670
Compare
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
This comment has been minimized.
This comment has been minimized.
666f303
to
480bf8f
Compare
7344.1 / Erlang 22.0 / small_tests / 1347427 7344.2 / Erlang 22.0 / internal_mnesia / 1347427 7344.3 / Erlang 22.0 / odbc_mssql_mnesia / 1347427 7344.4 / Erlang 22.0 / mysql_redis / 1347427 7344.7 / Erlang 22.0 / elasticsearch_and_cassandra_mnesia / 1347427 7344.6 / Erlang 22.0 / ldap_mnesia / 1347427 7344.5 / Erlang 22.0 / riak_mnesia / 1347427 7344.9 / Erlang 21.3 / pgsql_mnesia / 1347427 |
There was a problem hiding this 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. :)
There was a problem hiding this 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:
- I can see there is many deprecated time units used: http://erlang.org/doc/man/erlang.html#type-deprecated_time_unit Since the oldest supported Erlang/OTP is 21.2 now, we can use only the correct time units like described here: http://erlang.org/doc/man/erlang.html#type_time_unit I commented many lines regarding this, but not all of them
- In our
rebar.config
we still have this libusec
lib (https://github.com/esl/usec) which was created to deal with conversions from the timestamp format to micro seconds. Do we still use this lib? Can it be replaced with proper use oferlang:system_time
?
@@ -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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated micro_seconds
.
src/mam/mod_mam_utils.erl
Outdated
@@ -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), |
There was a problem hiding this comment.
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_bosh_socket.erl
Outdated
@@ -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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated milli_seconds
.
src/mod_bosh_socket.erl
Outdated
@@ -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), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated milli_seconds
.
src/mod_commands.erl
Outdated
@@ -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), |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
@fenek small tests done, sorry I forgot that 😅 |
7348.1 / Erlang 22.0 / small_tests / 98d94a6 7348.2 / Erlang 22.0 / internal_mnesia / 98d94a6 7348.3 / Erlang 22.0 / odbc_mssql_mnesia / 98d94a6 7348.4 / Erlang 22.0 / mysql_redis / 98d94a6 7348.7 / Erlang 22.0 / elasticsearch_and_cassandra_mnesia / 98d94a6 7348.6 / Erlang 22.0 / ldap_mnesia / 98d94a6 7348.5 / Erlang 22.0 / riak_mnesia / 98d94a6 7348.9 / Erlang 21.3 / pgsql_mnesia / 98d94a6 |
8c845aa
to
318cf32
Compare
7349.1 / Erlang 22.0 / small_tests / f407a76 7349.2 / Erlang 22.0 / internal_mnesia / f407a76 7349.3 / Erlang 22.0 / odbc_mssql_mnesia / f407a76 7349.4 / Erlang 22.0 / mysql_redis / f407a76 7349.7 / Erlang 22.0 / elasticsearch_and_cassandra_mnesia / f407a76 7349.6 / Erlang 22.0 / ldap_mnesia / f407a76 7349.5 / Erlang 22.0 / riak_mnesia / f407a76 7349.9 / Erlang 21.3 / pgsql_mnesia / f407a76 |
There was a problem hiding this 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.
Pretty much a mechanical change. Need to see results from CI.