Commit 732a606e authored by Ge Jun's avatar Ge Jun

Show number of connections rather than number of entries in socketmap at…

Show number of connections rather than number of entries in socketmap at client-side & show number of pooled connections after protocol names
parent 508b06f9
......@@ -30,6 +30,8 @@
namespace brpc {
int64_t GetChannelConnectionCount();
DEFINE_bool(show_hostname_instead_of_ip, false,
"/connections shows hostname instead of ip");
BRPC_VALIDATE_GFLAG(show_hostname_instead_of_ip, PassValidate);
......@@ -136,7 +138,7 @@ void ConnectionsService::PrintConnections(
if (need_local) {
os << "Local|";
}
os << "SSL|Protocol |fd |"
os << "SSL|Protocol |fd |"
"InBytes/s|In/s |InBytes/m |In/m |"
"OutBytes/s|Out/s |OutBytes/m|Out/m |"
"Rtt/Var(ms)|SocketId\n";
......@@ -173,7 +175,7 @@ void ConnectionsService::PrintConnections(
os << min_width(ptr->local_side().port, 5) << bar;
}
os << min_width("-", 3) << bar
<< min_width("-", 9) << bar
<< min_width("-", 12) << bar
<< min_width("-", 5) << bar
<< min_width("-", 9) << bar
<< min_width("-", 6) << bar
......@@ -190,13 +192,14 @@ void ConnectionsService::PrintConnections(
// slow (because we have many connections here).
int pref_index = ptr->preferred_index();
SocketUniquePtr first_sub;
if (pref_index < 0) {
int numfree = 0;
int numinflight = 0;
if (ptr->fd() < 0) {
ptr->GetPooledSocketStats(&numfree, &numinflight);
// Check preferred_index of any pooled sockets.
ptr->ListPooledSockets(&first_id, 1);
if (!first_id.empty()) {
if (Socket::Address(first_id[0], &first_sub) == 0) {
pref_index = first_sub->preferred_index();
}
Socket::Address(first_id[0], &first_sub);
}
}
const char* pref_prot = "-";
......@@ -255,15 +258,22 @@ void ConnectionsService::PrintConnections(
if (ptr->local_side().port > 0) {
os << min_width(ptr->local_side().port, 5) << bar;
} else {
os << min_width((first_sub ? "*" : "-"), 5) << bar;
os << min_width("-", 5) << bar;
}
}
os << SSLStateToYesNo(ptr->ssl_state(), use_html) << bar
<< min_width(pref_prot, 9) << bar;
os << SSLStateToYesNo(ptr->ssl_state(), use_html) << bar;
char protname[32];
if (!ptr->CreatedByConnect()) {
snprintf(protname, sizeof(protname), "%s", pref_prot);
} else {
snprintf(protname, sizeof(protname), "%s*%d", pref_prot,
numfree + numinflight);
}
os << min_width(protname, 12) << bar;
if (ptr->fd() >= 0) {
os << min_width(ptr->fd(), 5) << bar;
} else {
os << min_width((first_sub ? "*" : "-"), 5) << bar;
os << min_width("-", 5) << bar;
}
os << min_width(stat.in_size_s, 9) << bar
<< min_width(stat.in_num_messages_s, 6) << bar
......@@ -343,7 +353,7 @@ void ConnectionsService::default_method(
}
conns.insert(conns.end(), internal_conns.begin(), internal_conns.end());
}
os << "server_socket_count: " << num_conns << '\n';
os << "server_connection_count: " << num_conns << '\n';
PrintConnections(os, conns, use_html, server, false/*need_local*/);
if (has_uncopied) {
// Notice that we don't put the link of givemeall directly because
......@@ -356,7 +366,7 @@ void ConnectionsService::default_method(
SocketMapList(&conns);
os << (use_html ? "<br>\n" : "\n")
<< "channel_socket_count: " << conns.size() << '\n';
<< "channel_connection_count: " << GetChannelConnectionCount() << '\n';
PrintConnections(os, conns, use_html, server, true/*need_local*/);
if (use_html) {
......
......@@ -59,9 +59,9 @@ const size_t MAX_ONCE_READ = 524288;
ParseResult InputMessenger::CutInputMessage(
Socket* m, size_t* index, bool read_eof) {
const int preferred = m->_preferred_index;
const int preferred = m->preferred_index();
const int max_index = (int)_max_index.load(butil::memory_order_acquire);
// Try preferred handler first. The _preferred_index is set on last
// Try preferred handler first. The preferred_index is set on last
// selection or by client.
if (preferred >= 0 && preferred <= max_index
&& _handlers[preferred].parse != NULL) {
......@@ -95,7 +95,7 @@ ParseResult InputMessenger::CutInputMessage(
if (m->parsing_context()) {
m->reset_parsing_context(NULL);
}
m->_preferred_index = -1;
m->set_preferred_index(-1);
}
for (int i = 0; i <= max_index; ++i) {
if (i == preferred || _handlers[i].parse == NULL) {
......@@ -105,7 +105,7 @@ ParseResult InputMessenger::CutInputMessage(
ParseResult result = _handlers[i].parse(&m->_read_buf, m, read_eof, _handlers[i].arg);
if (result.is_ok() ||
result.error() == PARSE_ERROR_NOT_ENOUGH_DATA) {
m->_preferred_index = i;
m->set_preferred_index(i);
*index = i;
return result;
} else if (result.error() != PARSE_ERROR_TRY_OTHERS) {
......
......@@ -414,6 +414,9 @@ public:
// Put all sockets in _shared_part->socket_pool into `list'.
void ListPooledSockets(std::vector<SocketId>* list, size_t max_count = 0);
// Return true on success
bool GetPooledSocketStats(int* numfree, int* numinflight);
// Create a socket connecting to the same place of main_socket.
static int GetShortSocket(Socket* main_socket,
SocketUniquePtr* short_socket);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment