Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladimir Davydov <vdavydov.dev@gmail.com>
To: Ilya Kosarev <i.kosarev@tarantool.org>
Cc: tarantool-patches@freelists.org, georgy@tarantool.org,
	i.kosarev@corp.mail.ru
Subject: Re: [PATCH v3] iproto: report active connections number
Date: Wed, 27 Feb 2019 11:50:17 +0300	[thread overview]
Message-ID: <20190227085017.xscldynpdvpmgmwx@esperanza> (raw)
In-Reply-To: <20190226180420.3129-1-i.kosarev@tarantool.org>

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

      reply	other threads:[~2019-02-27  8:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-26 18:04 Ilya Kosarev
2019-02-27  8:50 ` Vladimir Davydov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190227085017.xscldynpdvpmgmwx@esperanza \
    --to=vdavydov.dev@gmail.com \
    --cc=georgy@tarantool.org \
    --cc=i.kosarev@corp.mail.ru \
    --cc=i.kosarev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [PATCH v3] iproto: report active connections number' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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