Skip to content

Commit

Permalink
iproto: report active connections number
Browse files Browse the repository at this point in the history
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.
(cherry picked from commit c96eca3)
  • Loading branch information
PersDep authored and locker committed Feb 28, 2019
1 parent 34b7053 commit 6d4db45
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/box/iproto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2060,6 +2060,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)
{
Expand Down
6 changes: 6 additions & 0 deletions src/box/iproto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
9 changes: 9 additions & 0 deletions src/box/lua/stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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;
}

Expand Down
37 changes: 37 additions & 0 deletions test/box/stat_net.result
Original file line number Diff line number Diff line change
Expand Up @@ -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
---
- []
Expand All @@ -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()
---
Expand All @@ -60,6 +93,10 @@ box.stat.net.RECEIVED.total
---
- 0
...
box.stat.net.CONNECTIONS
---
- 1
...
space:drop() -- tweedledum
---
...
Expand Down
13 changes: 13 additions & 0 deletions test/box/stat_net.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 6d4db45

Please sign in to comment.