Tarantool development patches archive
 help / color / mirror / Atom feed
From: "Sergey Petrenko" <sergepetrenko@tarantool.org>
To: "Vladislav Shpilevoy" <v.shpilevoy@tarantool.org>
Cc: tarantool-patches@dev.tarantool.org
Subject: Re: [Tarantool-patches] [PATCH 2/2] app/fiber: wait till a full event loop iteration ends.
Date: Thu, 14 Nov 2019 17:21:55 +0300	[thread overview]
Message-ID: <1573741315.750102299@f189.i.mail.ru> (raw)
In-Reply-To: <649a8cbc-6861-1a9f-7463-457c043a6484@tarantool.org>



Hi! Thank you for review!

>Четверг, 14 ноября 2019, 1:45 +03:00 от Vladislav Shpilevoy <v.shpilevoy@tarantool.org>:
>
>Hi! Thanks for the path!
>
>We don't use dots in commit title. I guess this is a typo. 

Fixed.

>
>
>On 13/11/2019 19:04, Serge Petrenko wrote:
>> fiber.top() fills in statistics every event loop iteration,
>> so if it was just enabled, fiber.top() may contain 'inf's and
>> 'nan's in fiber cpu usage averages because total time consumed by
>> the main thread was not yet accounted for.
>> Same stands for viewing top() results for a freshly created fiber:
>> its metrics will be zero since it hasn't lived a full ev loop iteration
>> yet.
>> Fix this by delaying the test till top() results are meaningful and add
>> minor refactoring.
>> 
>> Follow-up #2694
>> ---
>>  test/app/fiber.result   | 35 ++++++++++++++++++++++++++---------
>>  test/app/fiber.test.lua | 31 +++++++++++++++++++++++--------
>>  2 files changed, 49 insertions(+), 17 deletions(-)
>> 
>> diff --git a/test/app/fiber.result b/test/app/fiber.result
>> index 4a094939f..d447a36fc 100644
>> --- a/test/app/fiber.result
>> +++ b/test/app/fiber.result
>> @@ -1469,6 +1469,19 @@ sum = 0
>>  fiber.top_enable()
>>  ---
>>  ...
>> +-- Check that a number is finite.
>> +-- Lua doesn't have this, sorry.
>> +function finite(num)\
>> +    return type(num) == 'number' and num < math.huge and\
>> +           num > -math.huge and tostring(num) ~= 'nan'\
>
>1. A canonical way to check for NaN is compare a value with
>itself. If they are not equal, then it is NaN.

Fixed, thanks!

>
>
>But more important questions are:
>- How can a number from top() have a not 'number' type? 

It can't. I just wanted to implement a caconical is_finite check.
I can remove it, if you want me to.

>
>- How can top() contain a NaN, and an infinite value? 

NaN: you issue fiber.top() on the same iteration you called
fiber.top_enable(). cord()->clock_delta_last and fiber()->clock_delta_last
both are 0, because clock_delta_last contains data from a previous ev loop
iteration. Division gives you NaN.

>
>
>> +end
>> +---
>> +...
>> +-- Wait till a full event loop iteration passes, so that
>> +-- top() contains meaningful results.
>> +while not finite(fiber.top().cpu["1/sched"].instant) do  fiber.yield() end
>
>2. Double whitespace after 'do'.

Fixed, thanks.

Incremental diff follows.

diff --git a/test/app/fiber.result b/test/app/fiber.result
index d447a36fc..8eb506bd5 100644
--- a/test/app/fiber.result
+++ b/test/app/fiber.result
@@ -1469,17 +1469,14 @@ sum = 0
 fiber.top_enable()
 ---
 ...
--- Check that a number is finite.
--- Lua doesn't have this, sorry.
-function finite(num)\
-    return type(num) == 'number' and num < math.huge and\
-           num > -math.huge and tostring(num) ~= 'nan'\
+function isnan(num)\
+    return num ~= num\
 end
 ---
 ...
 -- Wait till a full event loop iteration passes, so that
 -- top() contains meaningful results.
-while not finite(fiber.top().cpu["1/sched"].instant) do  fiber.yield() end
+while isnan(fiber.top().cpu["1/sched"].instant) do fiber.yield() end
 ---
 ...
 a = fiber.top()
diff --git a/test/app/fiber.test.lua b/test/app/fiber.test.lua
index 33ebe063f..24cb8b492 100644
--- a/test/app/fiber.test.lua
+++ b/test/app/fiber.test.lua
@@ -634,16 +634,13 @@ sum = 0
 -- gh-2694 fiber.top()
 fiber.top_enable()
 
--- Check that a number is finite.
--- Lua doesn't have this, sorry.
-function finite(num)\
-    return type(num) == 'number' and num < math.huge and\
-           num > -math.huge and tostring(num) ~= 'nan'\
+function isnan(num)\
+    return num ~= num\
 end
 
 -- Wait till a full event loop iteration passes, so that
 -- top() contains meaningful results.
-while not finite(fiber.top().cpu["1/sched"].instant) do  fiber.yield() end
+while isnan(fiber.top().cpu["1/sched"].instant) do fiber.yield() end
 
 a = fiber.top()
 type(a)
 


Regards,
Sergey Petrenko

  reply	other threads:[~2019-11-14 14:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-13 18:03 [Tarantool-patches] [PATCH 0/2] fiber.top(): minor fixup Serge Petrenko
2019-11-13 18:04 ` [Tarantool-patches] [PATCH 1/2] fiber: reset clock stats on fiber.top_enable() Serge Petrenko
2019-11-13 18:04 ` [Tarantool-patches] [PATCH 2/2] app/fiber: wait till a full event loop iteration ends Serge Petrenko
2019-11-13 22:52   ` Vladislav Shpilevoy
2019-11-14 14:21     ` Sergey Petrenko [this message]
2019-11-14 21:44       ` Vladislav Shpilevoy
2019-11-15 14:59         ` Serge Petrenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1573741315.750102299@f189.i.mail.ru \
    --to=sergepetrenko@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/2] app/fiber: wait till a full event loop iteration ends.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox