Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH v4] iproto: report active connections number
@ 2019-02-27 14:37 Ilya Kosarev
  2019-02-28  9:01 ` Vladimir Davydov
  2019-02-28 10:28 ` [tarantool-patches] " Konstantin Osipov
  0 siblings, 2 replies; 3+ messages in thread
From: Ilya Kosarev @ 2019-02-27 14:37 UTC (permalink / raw)
  To: tarantool-patches; +Cc: georgy, vdavydov.dev, i.kosarev, Ilya Kosarev

Now there is new member in box.stat.net() called "CONNECTIONS"
which is a number of active iproto connections.

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)
+{
+	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
+ */
+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";
+
 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;
 }
 
diff --git a/test/box/stat_net.result b/test/box/stat_net.result
index b3e3db11f..639a830d8 100644
--- a/test/box/stat_net.result
+++ b/test/box/stat_net.result
@@ -34,6 +34,15 @@ LISTEN = require('uri').parse(box.cfg.listen)
 cn = remote.connect(LISTEN.host, LISTEN.service)
 ---
 ...
+cn1 = remote.connect(LISTEN.host, LISTEN.service)
+---
+...
+cn2 = remote.connect(LISTEN.host, LISTEN.service)
+---
+...
+cn3 = remote.connect(LISTEN.host, LISTEN.service)
+---
+...
 cn.space.tweedledum:select() --small request
 ---
 - []
@@ -46,8 +55,32 @@ box.stat.net.RECEIVED.total > 0
 ---
 - true
 ...
+box.stat.net.CONNECTIONS == 4
+---
+- true
+...
 -- box.stat.net.EVENTS.total > 0
 -- box.stat.net.LOCKS.total > 0
+WAIT_COND_TIMEOUT = 10
+---
+...
+cn1:close()
+---
+...
+cn2:close()
+---
+...
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 2 end, WAIT_COND_TIMEOUT)
+---
+- true
+...
+cn3:close()
+---
+...
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 1 end, WAIT_COND_TIMEOUT)
+---
+- true
+...
 -- reset
 box.stat.reset()
 ---
@@ -60,6 +93,10 @@ box.stat.net.RECEIVED.total
 ---
 - 0
 ...
+box.stat.net.CONNECTIONS
+---
+- 1
+...
 space:drop() -- tweedledum
 ---
 ...
diff --git a/test/box/stat_net.test.lua b/test/box/stat_net.test.lua
index 808bb71e7..997376997 100644
--- a/test/box/stat_net.test.lua
+++ b/test/box/stat_net.test.lua
@@ -13,18 +13,31 @@ remote = require 'net.box'
 
 LISTEN = require('uri').parse(box.cfg.listen)
 cn = remote.connect(LISTEN.host, LISTEN.service)
+cn1 = remote.connect(LISTEN.host, LISTEN.service)
+cn2 = remote.connect(LISTEN.host, LISTEN.service)
+cn3 = remote.connect(LISTEN.host, LISTEN.service)
 
 cn.space.tweedledum:select() --small request
 
 box.stat.net.SENT.total > 0
 box.stat.net.RECEIVED.total > 0
+box.stat.net.CONNECTIONS == 4
 -- box.stat.net.EVENTS.total > 0
 -- box.stat.net.LOCKS.total > 0
 
+WAIT_COND_TIMEOUT = 10
+
+cn1:close()
+cn2:close()
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 2 end, WAIT_COND_TIMEOUT)
+cn3:close()
+test_run:wait_cond(function() return box.stat.net.CONNECTIONS == 1 end, WAIT_COND_TIMEOUT)
+
 -- reset
 box.stat.reset()
 box.stat.net.SENT.total
 box.stat.net.RECEIVED.total
+box.stat.net.CONNECTIONS
 
 space:drop() -- tweedledum
 cn:close()
-- 
2.17.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] iproto: report active connections number
  2019-02-27 14:37 [PATCH v4] iproto: report active connections number Ilya Kosarev
@ 2019-02-28  9:01 ` Vladimir Davydov
  2019-02-28 10:28 ` [tarantool-patches] " Konstantin Osipov
  1 sibling, 0 replies; 3+ messages in thread
From: Vladimir Davydov @ 2019-02-28  9:01 UTC (permalink / raw)
  To: Ilya Kosarev; +Cc: tarantool-patches, georgy, i.kosarev

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;
>  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [tarantool-patches] [PATCH v4] iproto: report active connections number
  2019-02-27 14:37 [PATCH v4] iproto: report active connections number Ilya Kosarev
  2019-02-28  9:01 ` Vladimir Davydov
@ 2019-02-28 10:28 ` Konstantin Osipov
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Osipov @ 2019-02-28 10:28 UTC (permalink / raw)
  To: tarantool-patches; +Cc: georgy, vdavydov.dev, i.kosarev, Ilya Kosarev

* Ilya Kosarev <i.kosarev@tarantool.org> [19/02/27 17:38]:
> Now there is new member in box.stat.net() called "CONNECTIONS"
> which is a number of active iproto connections.
> 
> Closes #3905

Please don't forget a docbot request.


-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-02-28 10:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-27 14:37 [PATCH v4] iproto: report active connections number Ilya Kosarev
2019-02-28  9:01 ` Vladimir Davydov
2019-02-28 10:28 ` [tarantool-patches] " Konstantin Osipov

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