From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Thu, 28 Feb 2019 12:01:50 +0300 From: Vladimir Davydov Subject: Re: [PATCH v4] iproto: report active connections number Message-ID: <20190228090150.c5tyy5htr4bp36us@esperanza> References: <20190227143757.30000-1-i.kosarev@tarantool.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190227143757.30000-1-i.kosarev@tarantool.org> To: Ilya Kosarev Cc: tarantool-patches@freelists.org, georgy@tarantool.org, i.kosarev@corp.mail.ru List-ID: On Wed, Feb 27, 2019 at 05:37:57PM +0300, Ilya Kosarev wrote: > Now there is new member in box.stat.net() called "CONNECTIONS" > which is a number of active iproto connections. Please see a few nitpicking comments below. > > Closes #3905 > --- > https://github.com/tarantool/tarantool/tree/i.kosarev/gh-3905-report-connections-number > https://github.com/tarantool/tarantool/issues/3905 > > Changes in v4: > - CONNECTIONS counter doesn't have extra lua tables inside anymore > - refactoring > > src/box/iproto.cc | 6 ++++++ > src/box/iproto.h | 6 ++++++ > src/box/lua/stat.c | 11 +++++++++++ > test/box/stat_net.result | 37 +++++++++++++++++++++++++++++++++++++ > test/box/stat_net.test.lua | 13 +++++++++++++ > 5 files changed, 73 insertions(+) > > diff --git a/src/box/iproto.cc b/src/box/iproto.cc > index 863eb4f06..d6dafe155 100644 > --- a/src/box/iproto.cc > +++ b/src/box/iproto.cc > @@ -2121,6 +2121,12 @@ iproto_mem_used(void) > return slab_cache_used(&net_cord.slabc) + slab_cache_used(&net_slabc); > } > > +size_t > +iproto_connections_n(void) We don't typically use _n in variable names. Please rename to iproto_connection_count() Note, no 's' after 'connection'. > +{ > + return mempool_count(&iproto_connection_pool); > +} > + > void > iproto_reset_stat(void) > { > diff --git a/src/box/iproto.h b/src/box/iproto.h > index 8f3607ffc..0d53d13ed 100644 > --- a/src/box/iproto.h > +++ b/src/box/iproto.h > @@ -62,6 +62,12 @@ extern unsigned iproto_readahead; > size_t > iproto_mem_used(void); > > +/** > + * Return number of active iproto connections /** * Return the number of active iproto connections. */ Note the article and the dot at the end of the comment. Kostja's fussy about comments purity :-) > + */ > +size_t > +iproto_connections_n(void); > + > /** > * Reset network statistics. > */ > diff --git a/src/box/lua/stat.c b/src/box/lua/stat.c > index 3fce81f61..f8b9b581e 100644 > --- a/src/box/lua/stat.c > +++ b/src/box/lua/stat.c > @@ -52,6 +52,8 @@ extern struct rmean *rmean_error; > extern struct rmean *rmean_net; > extern struct rmean *rmean_tx_wal_bus; > > +static const char *conn_n_name = "CONNECTIONS"; > + I don't think there's any point in introducing a variable for this rather than simply using the string literal directly. There are only a couple places where we need it, and we aren't going to change those. > static void > fill_stat_item(struct lua_State *L, int rps, int64_t total) > { > @@ -140,6 +142,10 @@ static int > lbox_stat_net_index(struct lua_State *L) > { > luaL_checkstring(L, -1); > + if (strcmp(conn_n_name, lua_tostring(L, -1)) == 0) { > + lua_pushnumber(L, iproto_connections_n()); > + return 1; > + } > return rmean_foreach(rmean_net, seek_stat_item, L); > } > > @@ -148,6 +154,11 @@ lbox_stat_net_call(struct lua_State *L) > { > lua_newtable(L); > rmean_foreach(rmean_net, set_stat_item, L); > + > + lua_pushstring(L, conn_n_name); > + lua_pushnumber(L, iproto_connections_n()); > + lua_settable(L, -3); > + > return 1; > }