Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH v7] iproto: report active connections number
@ 2019-02-28 14:16 Ilya Kosarev
  2019-02-28 15:31 ` Vladimir Davydov
  0 siblings, 1 reply; 2+ messages in thread
From: Ilya Kosarev @ 2019-02-28 14:16 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

@TarantoolBot document
Title: box.stat.net
Update the documentation for box.stat.net
to reflect the addition of the field
which reports iproto connections number.
---
https://github.com/tarantool/tarantool/tree/i.kosarev/gh-3905-report-connections-number
https://github.com/tarantool/tarantool/issues/3905

Changes in v7:
- reduced line length in commit message

 src/box/iproto.cc          |  6 ++++++
 src/box/iproto.h           |  6 ++++++
 src/box/lua/stat.c         |  9 +++++++++
 test/box/stat_net.result   | 37 +++++++++++++++++++++++++++++++++++++
 test/box/stat_net.test.lua | 13 +++++++++++++
 5 files changed, 71 insertions(+)

diff --git a/src/box/iproto.cc b/src/box/iproto.cc
index 863eb4f06..c8b83b16b 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_connection_count(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..7916705ee 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 the number of active iproto connections.
+ */
+size_t
+iproto_connection_count(void);
+
 /**
  * Reset network statistics.
  */
diff --git a/src/box/lua/stat.c b/src/box/lua/stat.c
index c00315cdd..1015253f4 100644
--- a/src/box/lua/stat.c
+++ b/src/box/lua/stat.c
@@ -140,6 +140,10 @@ static int
 lbox_stat_net_index(struct lua_State *L)
 {
 	luaL_checkstring(L, -1);
+	if (strcmp("CONNECTIONS", lua_tostring(L, -1)) == 0) {
+		lua_pushnumber(L, iproto_connection_count());
+		return 1;
+	}
 	return rmean_foreach(rmean_net, seek_stat_item, L);
 }
 
@@ -148,6 +152,11 @@ lbox_stat_net_call(struct lua_State *L)
 {
 	lua_newtable(L);
 	rmean_foreach(rmean_net, set_stat_item, L);
+
+	lua_pushstring(L, "CONNECTIONS");
+	lua_pushnumber(L, iproto_connection_count());
+	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] 2+ messages in thread

* Re: [PATCH v7] iproto: report active connections number
  2019-02-28 14:16 [PATCH v7] iproto: report active connections number Ilya Kosarev
@ 2019-02-28 15:31 ` Vladimir Davydov
  0 siblings, 0 replies; 2+ messages in thread
From: Vladimir Davydov @ 2019-02-28 15:31 UTC (permalink / raw)
  To: Ilya Kosarev; +Cc: tarantool-patches, georgy, i.kosarev

On Thu, Feb 28, 2019 at 05:16:27PM +0300, Ilya Kosarev wrote:
> Now there is new member in box.stat.net() called "CONNECTIONS"
> which is a number of active iproto connections.
> 
> Closes #3905
> 
> @TarantoolBot document
> Title: box.stat.net
> Update the documentation for box.stat.net
> to reflect the addition of the field
> which reports iproto connections number.
> ---
> https://github.com/tarantool/tarantool/tree/i.kosarev/gh-3905-report-connections-number
> https://github.com/tarantool/tarantool/issues/3905
> 
> Changes in v7:
> - reduced line length in commit message

Please in future retain full change log, like this:

Changes in v7:
 - reduced line length in commit message
Changes in v6:
 - added docbot request to commit message
Changes in v5:
 - review-based polishing
Changes in v4:
 - CONNECTIONS counter doesn't have extra lua tables inside anymore
 - refactoring
...

It's nice to see how the patch evolved.

> 
>  src/box/iproto.cc          |  6 ++++++
>  src/box/iproto.h           |  6 ++++++
>  src/box/lua/stat.c         |  9 +++++++++
>  test/box/stat_net.result   | 37 +++++++++++++++++++++++++++++++++++++
>  test/box/stat_net.test.lua | 13 +++++++++++++
>  5 files changed, 71 insertions(+)
> 

Pushed to 2.1 and 1.10. Thanks!

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

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

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-28 14:16 [PATCH v7] iproto: report active connections number Ilya Kosarev
2019-02-28 15:31 ` Vladimir Davydov

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