From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp51.i.mail.ru (smtp51.i.mail.ru [94.100.177.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 99AF9440F3C for ; Fri, 15 Nov 2019 18:35:40 +0300 (MSK) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) From: Serge Petrenko In-Reply-To: <5fa2b099f3a4716a8418d2ddd6afd71a8a2f1198.1573828446.git.sergepetrenko@tarantool.org> Date: Fri, 15 Nov 2019 18:35:39 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <5fa2b099f3a4716a8418d2ddd6afd71a8a2f1198.1573828446.git.sergepetrenko@tarantool.org> Subject: Re: [Tarantool-patches] [PATCH v2 2/2] app/fiber: wait till a full event loop iteration ends List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy Cc: tarantool-patches@dev.tarantool.org > 15 =D0=BD=D0=BE=D1=8F=D0=B1. 2019 =D0=B3., =D0=B2 17:58, Serge = Petrenko =D0=BD=D0=B0=D0=BF=D0=B8=D1=81=D0=B0= =D0=BB(=D0=B0): >=20 > 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. >=20 > Follow-up #2694 > =E2=80=94 Sorry, the commit message was outdated here. Fixed it on the branch: ``` app/fiber: wait till a full event loop iteration ends fiber.top() fills in statistics every event loop iteration, so if it was just enabled, fiber.top() returns zero in fiber cpu usage statistics 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=20 #2694 ``` > test/app/fiber.result | 28 +++++++++++++++++++--------- > test/app/fiber.test.lua | 26 ++++++++++++++++++-------- > 2 files changed, 37 insertions(+), 17 deletions(-) >=20 > diff --git a/test/app/fiber.result b/test/app/fiber.result > index 4a094939f..b4e448282 100644 > --- a/test/app/fiber.result > +++ b/test/app/fiber.result > @@ -1469,6 +1469,12 @@ sum =3D 0 > fiber.top_enable() > --- > ... > +-- Wait till a full event loop iteration passes, so that > +-- top() contains meaningful results. On the ev loop iteration > +-- following fiber.top_enable() results will be zero. > +while fiber.top().cpu["1/sched"].instant =3D=3D 0 do fiber.yield() = end > +--- > +... > a =3D fiber.top() > --- > ... > @@ -1504,9 +1510,9 @@ for k, v in pairs(a) do\ > end > --- > ... > -sum_inst > +sum_inst > 99 and sum_inst < 101 or sum_inst > --- > -- 100 > +- true > ... > -- not exact due to accumulated integer division errors > sum_avg > 99 and sum_avg < 101 or sum_avg > @@ -1517,24 +1523,28 @@ tbl =3D nil > --- > ... > f =3D fiber.new(function()\ > - for i =3D 1,1000 do end\ > - fiber.yield()\ > - tbl =3D = fiber.top().cpu[fiber.self().id()..'/'..fiber.self().name()]\ > + local fiber_key =3D fiber.self().id()..'/'..fiber.self().name()\ > + tbl =3D fiber.top().cpu[fiber_key]\ > + while tbl.time =3D=3D 0 do\ > + for i =3D 1,1000 do end\ > + fiber.yield()\ > + tbl =3D fiber.top().cpu[fiber_key]\ > + end\ > end) > --- > ... > -while f:status() ~=3D 'dead' do fiber.sleep(0.01) end > +while f:status() ~=3D 'dead' do fiber.yield() end > --- > ... > -tbl["average"] > 0 > +tbl.average > 0 > --- > - true > ... > -tbl["instant"] > 0 > +tbl.instant > 0 > --- > - true > ... > -tbl["time"] > 0 > +tbl.time > 0 > --- > - true > ... > diff --git a/test/app/fiber.test.lua b/test/app/fiber.test.lua > index 38b85d554..e2834216b 100644 > --- a/test/app/fiber.test.lua > +++ b/test/app/fiber.test.lua > @@ -634,6 +634,12 @@ sum =3D 0 > -- gh-2694 fiber.top() > fiber.top_enable() >=20 > + > +-- Wait till a full event loop iteration passes, so that > +-- top() contains meaningful results. On the ev loop iteration > +-- following fiber.top_enable() results will be zero. > +while fiber.top().cpu["1/sched"].instant =3D=3D 0 do fiber.yield() = end > + > a =3D fiber.top() > type(a) > -- scheduler is present in fiber.top() > @@ -652,19 +658,23 @@ for k, v in pairs(a) do\ > sum_avg =3D sum_avg + v["average"]\ > end >=20 > -sum_inst > +sum_inst > 99 and sum_inst < 101 or sum_inst > -- not exact due to accumulated integer division errors > sum_avg > 99 and sum_avg < 101 or sum_avg > tbl =3D nil > f =3D fiber.new(function()\ > - for i =3D 1,1000 do end\ > - fiber.yield()\ > - tbl =3D = fiber.top().cpu[fiber.self().id()..'/'..fiber.self().name()]\ > + local fiber_key =3D fiber.self().id()..'/'..fiber.self().name()\ > + tbl =3D fiber.top().cpu[fiber_key]\ > + while tbl.time =3D=3D 0 do\ > + for i =3D 1,1000 do end\ > + fiber.yield()\ > + tbl =3D fiber.top().cpu[fiber_key]\ > + end\ > end) > -while f:status() ~=3D 'dead' do fiber.sleep(0.01) end > -tbl["average"] > 0 > -tbl["instant"] > 0 > -tbl["time"] > 0 > +while f:status() ~=3D 'dead' do fiber.yield() end > +tbl.average > 0 > +tbl.instant > 0 > +tbl.time > 0 >=20 > fiber.top_disable() > fiber.top() > --=20 > 2.21.0 (Apple Git-122) >=20 -- Serge Petrenko sergepetrenko@tarantool.org=