dashbitco / broadway_dashboard

Keep track of your Broadway pipelines from Phoenix LiveDashboard
https://elixir-broadway.org/
Apache License 2.0
213 stars 17 forks source link

Fix the calc_workload function to avoid the error due to division by zero #8

Closed leductam closed 3 years ago

leductam commented 3 years ago

This commit to fix the calc_workload function to avoid the error due to division by zero.

The details discussion at #5 .

The cause is Erlang monotonic time can return the same value many times ! Then idle_time and duration might zero at unspecified point in time.

Following https://learnyousomeerlang.com/time:

Erlang monotonic time. This is Erlang's view of the OS monotonic time if available, or the VM's own monotonic version of the system time if not available. This is the adjusted clock that is used for events, timers, and so on. Its stability makes it ideal to count a time interval. Do note that this time is monotonic, but not strictly monotonic, meaning that the clock can't go backwards, but it can return the same value many times!

As mentioned earlier, the Erlang monotonic time is not strictly monotonic: it will possibly return the same number twice if it's called at the same time on two different cores, for example.

And under the hood of Erlang monotonic time are clock_gettime (Linux) , and QueryPerformanceCounter (QPC) (Windows) , the reference about them here.

The code of commit is not beautiful but it can solve the problem :relaxed:

philss commented 3 years ago

@leductam thank you! :purple_heart: