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
Use Monotonic time for calculating request latency in Plug.Logger #373
Conversation
I just realized that Plug is supposed to be backward compatible to Elixir 1.0, so... |
@whatyouhide Ah yes, good point. I also came across elixir-lang/elixir#4024 (by you), so it looks like |
As you said, we can't straight use |
Got it, that makes sense. Commit incoming. |
@mje113 please squash everything into single commit. |
@@ -41,6 +42,15 @@ defmodule Plug.Logger do | |||
end) | |||
end | |||
|
|||
# TODO: remove this once Plug supports only Elixir 1.2. | |||
if function_exported?(:erlang, :monotonic_time, 0) do | |||
defp current_time, do: :erlang.monotonic_time |
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.
We should use :erlang.monotonic_time(:micro_seconds)
here and remove convert_time_unit
call.
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.
Let's not do that because we lose precision. The ideal is to always convert later.
❤️ 💚 💙 💛 💜 |
According to http://erlang.org/doc/apps/erts/time_correction.html#Erlang_Monotonic_Time to Measure Elapsed Time: