[PATCH v3] iproto: report active connections number

Vladimir Davydov vdavydov.dev at gmail.com
Wed Feb 27 11:50:17 MSK 2019


On Tue, Feb 26, 2019 at 09:04:20PM +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
> ---
> https://github.com/tarantool/tarantool/tree/i.kosarev/gh-3905-report-connections-number
> https://github.com/tarantool/tarantool/issues/3905
> 
> Changes in v3:
>   - CONNECTIONS counter is not rmeanish anymore
>   - fiber.sleep replaced with test_run:wait_cond in test
> 
>  src/box/iproto.cc          |  3 ++-
>  src/box/lua/stat.c         | 44 ++++++++++++++++++++++++++++++++++++++
>  test/box/stat_net.result   | 37 ++++++++++++++++++++++++++++++++
>  test/box/stat_net.test.lua | 13 +++++++++++
>  4 files changed, 96 insertions(+), 1 deletion(-)
> 
> diff --git a/src/box/iproto.cc b/src/box/iproto.cc
> index 863eb4f06..1c506d9c8 100644
> --- a/src/box/iproto.cc
> +++ b/src/box/iproto.cc
> @@ -271,6 +271,7 @@ enum rmean_net_name {
>  };
>  
>  const char *rmean_net_strings[IPROTO_LAST] = { "SENT", "RECEIVED" };
> +const char *conn_n_name = "CONNECTIONS";

What's the point in having this string defined in iproto.cc?
It's only used in lua/stat.c.

>  
>  static void
>  tx_process_destroy(struct cmsg *m);
> @@ -475,7 +476,7 @@ struct iproto_connection
>  	char salt[IPROTO_SALT_SIZE];
>  };
>  
> -static struct mempool iproto_connection_pool;
> +struct mempool iproto_connection_pool;
>  static RLIST_HEAD(stopped_connections);
>  
>  /**
> diff --git a/src/box/lua/stat.c b/src/box/lua/stat.c
> index 3fce81f61..cedfaba8a 100644
> --- a/src/box/lua/stat.c
> +++ b/src/box/lua/stat.c
> @@ -45,12 +45,15 @@
>  #include <info.h>
>  #include "lua/info.h"
>  #include "lua/utils.h"
> +#include "small/mempool.h"
>  
>  extern struct rmean *rmean_box;
>  extern struct rmean *rmean_error;
>  /** network statistics (iproto & cbus) */
>  extern struct rmean *rmean_net;
>  extern struct rmean *rmean_tx_wal_bus;
> +extern struct mempool iproto_connection_pool;

No, please don't export iproto_connection_pool. Instead, add a helper
function to report the connection count, similar to iproto_mem_used().

> +extern const char *conn_n_name;
>  
>  static void
>  fill_stat_item(struct lua_State *L, int rps, int64_t total)
> @@ -79,6 +82,29 @@ set_stat_item(const char *name, int rps, int64_t total, void *cb_ctx)
>  	return 0;
>  }
>  
> +static void
> +fill_conn_n(struct lua_State *L)
> +{
> +	lua_pushstring(L, "total");

Why not simply print "CONNECTIONS: 10"? I don't see any point in the
"total" field.

> +	lua_pushnumber(L, mempool_count(&iproto_connection_pool));
> +	lua_settable(L, -3);
> +}
> +
> +static int
> +set_conn_n(void *cb_ctx)
> +{
> +	struct lua_State *L = (struct lua_State *) cb_ctx;
> +
> +	lua_pushstring(L, conn_n_name);
> +	lua_newtable(L);
> +
> +	fill_conn_n(L);
> +
> +	lua_settable(L, -3);
> +
> +	return 0;
> +}
> +
>  /**
>   * A stat_foreach() callback used to handle access to e.g.
>   * box.stats.DELETE.
> @@ -96,6 +122,19 @@ seek_stat_item(const char *name, int rps, int64_t total, void *cb_ctx)
>  	return 1;
>  }
>  
> +static int
> +seek_conn_n(void *cb_ctx)
> +{
> +	struct lua_State *L = (struct lua_State *) cb_ctx;
> +	if (strcmp(conn_n_name, lua_tostring(L, -1)) != 0)
> +		return 0;
> +
> +	lua_newtable(L);
> +	fill_conn_n(L);
> +
> +	return 1;
> +}
> +

What's the point in making these functions look similar to
seek_stat_item/set_stat_item? They aren't callbacks. I don't
think we even need them - they're trivial so we could inline
them without hurting readability.

>  static int
>  lbox_stat_index(struct lua_State *L)
>  {
> @@ -140,6 +179,9 @@ static int
>  lbox_stat_net_index(struct lua_State *L)
>  {
>  	luaL_checkstring(L, -1);
> +	int res = seek_conn_n(L);
> +	if (res)
> +		return res;
>  	return rmean_foreach(rmean_net, seek_stat_item, L);
>  }
>  
> @@ -148,6 +190,8 @@ lbox_stat_net_call(struct lua_State *L)
>  {
>  	lua_newtable(L);
>  	rmean_foreach(rmean_net, set_stat_item, L);
> +	set_conn_n(L);
> +
>  	return 1;
>  }



More information about the Tarantool-patches mailing list