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

fix(*) don't crash on throughput when duration is null #1

Closed

Conversation

vbarbaresi
Copy link

I experienced this issue while running clearly tests

    def test_server_filter_workers_empty(mocked_server):
        mocked_server.listener.memory.workers.values.return_value = ()

        gen = mocked_server.filter_workers(clearly_pb2.FilterWorkersRequest(), N
one)
        with pytest.raises(StopIteration):
>           next(gen)

test_server.py:129:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\..\venv\lib\site-packages\clearly\server.py:153: in filter_workers
    for worker in about_time(callback, found_workers):
..\..\venv\lib\site-packages\about_time\about_time.py:91: in counter
    fn(HandleStats(timings, i + 1))
..\..\venv\lib\site-packages\clearly\server.py:151: in callback
    t.count, t.duration_human, t.throughput_human)
..\..\venv\lib\site-packages\about_time\about_time.py:151: in throughput_human
    value = self.throughput
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <about_time.about_time.HandleStats object at 0x03FAD530>

    @property
    def throughput(self):
>       return self.count / self.duration
E       ZeroDivisionError: float division by zero

..\..\venv\lib\site-packages\about_time\about_time.py:147: ZeroDivisionError
===================== 2 failed, 15 passed in 0.25 seconds =====================

With the mocks it was so fast that duration was actually zero. And probably because I'm currently on a Python2.7 + Windows system where the time() precision is crappy.

So I propose returning NaN in this case

avoid the exception here:
    @Property
    def throughput(self):
>       return self.count / self.duration
E       ZeroDivisionError: float division by zero

return NaN instead
@rsalmei
Copy link
Owner

rsalmei commented Oct 25, 2018

Hello @vbarbaresi!
I'm sorry for the long delay to reply to you.

Thank you for catching that, and already proposing a PR!
I did a small research and you are right, the timer resolution in py2.7 windows is more than crappy, is a whopping 💩16ms! 😱

Well, I did fix it in this scenario, but I've made a more involved solution, could you please pip install -U about-time and see if it is ok for you? The changes are at #2.

Also, could you see if you can now run the tests for Clearly?

@vbarbaresi
Copy link
Author

Thanks! Yes, your solution works for me 👌

@vbarbaresi vbarbaresi closed this Oct 28, 2018
@vbarbaresi vbarbaresi deleted the fix_throughput_zerodivision branch October 28, 2018 08:49
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.

None yet

2 participants