Navigation Menu

Skip to content

Commit

Permalink
two new troubleshooting stats
Browse files Browse the repository at this point in the history
accepting_conns for completeness, and listen_disabled_num to see how many
times you've hit maxconns and disabled incoming connections. probably a good
stat to monitor and flip out on.
  • Loading branch information
dormando authored and dustin committed Mar 30, 2009
1 parent 534466e commit 3d540bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
19 changes: 16 additions & 3 deletions memcached.c
Expand Up @@ -160,7 +160,8 @@ static rel_time_t realtime(const time_t exptime) {
static void stats_init(void) {
stats.curr_items = stats.total_items = stats.curr_conns = stats.total_conns = stats.conn_structs = 0;
stats.get_cmds = stats.set_cmds = stats.get_hits = stats.get_misses = stats.evictions = 0;
stats.curr_bytes = 0;
stats.curr_bytes = stats.listen_disabled_num = 0;
stats.accepting_conns = 1; /* assuming we start in this state. */

/* make the time we started always be 2 seconds before we really
did, so time(0) - time.started is never zero. if so, things
Expand Down Expand Up @@ -2224,7 +2225,8 @@ static char *server_stats(uint32_t (*add_stats)(char *buf, const char *key,
APPEND_STAT("bytes_read", "%llu", (unsigned long long)thread_stats.bytes_read);
APPEND_STAT("bytes_written", "%llu", (unsigned long long)thread_stats.bytes_written);
APPEND_STAT("limit_maxbytes", "%llu", (unsigned long long)settings.maxbytes);
APPEND_STAT("bytes_written", "%llu", (unsigned long long)thread_stats.bytes_written);
APPEND_STAT("accepting_conns", "%u", stats.accepting_conns);
APPEND_STAT("listen_disabled_num", "%llu", (unsigned long long)stats.listen_disabled_num);
APPEND_STAT("threads", "%d", settings.num_threads);

if(*buflen > 0 && (buf = malloc(*buflen)) == NULL) {
Expand Down Expand Up @@ -3242,7 +3244,18 @@ void accept_new_conns(const bool do_accept) {
perror("listen");
}
}
}
}

if (do_accept) {
STATS_LOCK();
stats.accepting_conns = 1;
STATS_UNLOCK();
} else {
STATS_LOCK();
stats.accepting_conns = 0;
stats.listen_disabled_num++;
STATS_UNLOCK();
}
}

/*
Expand Down
3 changes: 3 additions & 0 deletions memcached.h
Expand Up @@ -108,6 +108,9 @@ struct stats {
uint64_t get_hits;
uint64_t get_misses;
uint64_t evictions;
time_t started; /* when the process was started */
unsigned int accepting_conns; /* whether we are currently accepting */
uint64_t listen_disabled_num;
};

#define MAX_VERBOSITY_LEVEL 2
Expand Down
7 changes: 4 additions & 3 deletions t/stats.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl

use strict;
use Test::More tests => 91;
use Test::More tests => 93;
use FindBin qw($Bin);
use lib "$Bin/lib";
use MemcachedTest;
Expand Down Expand Up @@ -47,14 +47,15 @@ my $sock = $server->sock;
my $stats = mem_stats($sock);

# Test number of keys
is(scalar(keys(%$stats)), 32, "32 stats values");
is(scalar(keys(%$stats)), 34, "34 stats values");

# Test initial state
foreach my $key (qw(curr_items total_items bytes cmd_get cmd_set get_hits evictions get_misses
bytes_written delete_hits delete_misses incr_hits incr_misses decr_hits
decr_misses)) {
decr_misses listen_disabled_num)) {
is($stats->{$key}, 0, "initial $key is zero");
}
is($stats->{accepting_conns}, 1, "initial accepting_conns is one");

# Do some operations

Expand Down

0 comments on commit 3d540bd

Please sign in to comment.