From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp5.mail.ru (smtp5.mail.ru [94.100.179.24]) (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 3CFF2452566 for ; Sat, 9 Nov 2019 09:53:42 +0300 (MSK) Date: Sat, 9 Nov 2019 09:53:40 +0300 From: Kirill Yukhin Message-ID: <20191109065340.nghum2z473s62qbc@tarantool.org> References: <20191101140523.14580-1-sergepetrenko@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191101140523.14580-1-sergepetrenko@tarantool.org> Subject: Re: [Tarantool-patches] [tarantool-patches] [PATCH v3] lua: add fiber.top() listing fiber cpu consumption List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, tarantool-patches@dev.tarantool.org Hello, On 01 ноя 17:05, Serge Petrenko wrote: > Implement a new function in Lua fiber library: top(). It returns a table > of alive fibers (including the scheduler). Each table entry has two > fields: average cpu consumption, which is calculated with exponential > moving average over event loop iterations, and current cpu consumption, > which shows fiber's cpu usage over the last event loop iteration. > The patch relies on CPU timestamp counter to measure each fiber's time > share. > > Closes #2694 > > @TarantoolBot document > Title: fiber: new function `fiber.top()` > > `fiber.top()` returns a table of all alive fibers and lists their cpu > consumption. Let's take a look at the example: > ``` > tarantool> fiber.top() > --- > - 104/lua: > instant: 18.433514726042 > time: 0.677505865 > average: 21.98826143184 > 103/lua: > instant: 19.131392015951 > time: 0.689521917 > average: 20.807772656431 > 107/lua: > instant: 18.624600174469 > time: 0.681585168 > average: 17.78194117452 > 101/on_shutdown: > instant: 0 > time: 0 > average: 0 > 105/lua: > instant: 18.562289702156 > time: 0.682085309 > average: 15.513811055476 > 106/lua: > instant: 18.441822789017 > time: 0.677320271 > average: 15.427595583115 > 102/interactive: > instant: 0 > time: 0.000367182 > average: 0 > cpu misses: 0 > 1/sched: > instant: 6.8063805923649 > time: 0.253035056 > average: 8.3479789103691 > ... > > ``` > In the table above keys are strings containing fiber ids and names > (the only exception is a single 'cpu misses' key which indicates the > number of times tx thread was rescheduled on a different cpu core. > More on that later). > The three metrics available for each fiber are: > 1) instant (per cent), > which indicates the share of time fiber was executing during the > previous event loop iteration > 2) average (per cent), which is calculated as an exponential moving > average of `instant` values over all previous event loop iterations. > 3) time (seconds), which estimates how much cpu time each fiber spent > processing during its lifetime. > > More info on `cpu misses` field returned by `fiber.top()`: > `cpu misses` indicates the amount of times tx thread detected it was > rescheduled on a different cpu core during the last event loop > iteration. > fiber.top() uses cpu timestamp counter to measure each fiber's execution > time. However, each cpu core may have its own counter value (you can > only rely on counter deltas if both measurements were taken on the same > core, otherwise the delta may even get negative). > When tx thread is rescheduled to a different cpu core, tarantool just > assumes cpu delta was zero for the latest measurement. This loweres > precision of our computations, so the bigger `cpu misses` value the > lower the precision of fiber.top() results. > > Fiber.top() doesn't work on arm architecture at the moment. > > Please note, that enabling fiber.top() slows down fiber switching by > about 15 per cent, so it is disabled by default. > To enable it you need to issue `fiber.top_enable()`. > You can disable it back after you finished debugging using > `fiber.top_disable()`. > "Time" entry is also added to each fibers output in fiber.info() > (it duplicates "time" entry from fiber.top()). > Note, that "time" is only counted while fiber.top is enabled. > --- > https://github.com/tarantool/tarantool/issues/2694 > https://github.com/tarantool/tarantool/tree/sp/gh-2694-fiber-top I've checked your patch into master. -- Regards, Kirill Yukhin