Skip to content
Browse files

work-in-progress on stats merging

Change-Id: I19e0bff4c5a1105081d3efd4eccc54e1b392c96b
  • Loading branch information...
1 parent 9ef077f commit 48db4b378909599429b524c129609c5fbe3aea33 @steveyen steveyen committed Jul 23, 2010
Showing with 22 additions and 14 deletions.
  1. +4 −2 cproxy.h
  2. +2 −1 cproxy_protocol_a2a.c
  3. +2 −1 cproxy_protocol_a2b.c
  4. +2 −1 cproxy_protocol_b2b.c
  5. +12 −9 cproxy_stats.c
View
6 cproxy.h
@@ -650,15 +650,17 @@ void noop_free(void *v);
// Stats handling.
//
-bool protocol_stats_merge_line(genhash_t *merger, char *line);
+bool protocol_stats_merge_line(genhash_t *merger, char *line,
+ int num_servers);
bool protocol_stats_merge_name_val(genhash_t *merger,
char *prefix,
int prefix_len,
char *name,
int name_len,
char *val,
- int val_len);
+ int val_len,
+ int num_servers);
void protocol_stats_foreach_free(const void *key,
const void *value,
View
3 cproxy_protocol_a2a.c
@@ -132,7 +132,8 @@ void cproxy_process_a2a_downstream(conn *c, char *line) {
if (uc != NULL) {
assert(uc->next == NULL);
- if (protocol_stats_merge_line(d->merger, line) == false) {
+ if (protocol_stats_merge_line(d->merger, line,
+ d->downstream_used_start) == false) {
// Forward the line as-is if we couldn't merge it.
//
int nline = strlen(line);
View
3 cproxy_protocol_a2b.c
@@ -1034,7 +1034,8 @@ void a2b_process_downstream_response(conn *c) {
protocol_stats_merge_name_val(d->merger,
"STAT", 4,
ITEM_key(it), it->nkey,
- ITEM_data(it), it->nbytes - 2);
+ ITEM_data(it), it->nbytes - 2,
+ d->downstream_used_start);
}
item_remove(it);
View
3 cproxy_protocol_b2b.c
@@ -421,7 +421,8 @@ void cproxy_process_b2b_downstream_nread(conn *c) {
protocol_stats_merge_name_val(d->merger, "STAT", 4,
key, keylen,
- val, bodylen - keylen - extlen);
+ val, bodylen - keylen - extlen,
+ d-downstream_used_start);
}
conn_set_state(c, conn_new_cmd); // Get next STATS response.
View
21 cproxy_stats.c
@@ -16,11 +16,12 @@
// Special STATS value merging rules, instead of the
// default to just sum the values. Note the trailing space.
//
-char *protocol_stats_keys_first = "pid ";
+char *protocol_stats_keys_one = // These stats only make sense with one server.
+ "pid version libevent "
+ "ep_version ep_dbname ep_storage_type ep_flusher_state ep_warmup_thread ";
char *protocol_stats_keys_smallest =
"uptime "
"time "
- "version "
"pointer_size "
"limit_maxbytes "
"accepting_conns "
@@ -70,7 +71,7 @@ mcache_funcs mcache_key_stats_funcs = {
#define VALUE_TOKEN 2
#define MERGE_BUF_SIZE 300
-bool protocol_stats_merge_line(genhash_t *merger, char *line) {
+bool protocol_stats_merge_line(genhash_t *merger, char *line, int num_servers) {
assert(merger != NULL);
assert(line != NULL);
@@ -102,7 +103,8 @@ bool protocol_stats_merge_line(genhash_t *merger, char *line) {
tokens[PREFIX_TOKEN].length,
name, name_len,
tokens[VALUE_TOKEN].value,
- tokens[VALUE_TOKEN].length);
+ tokens[VALUE_TOKEN].length,
+ num_servers);
}
// TODO: The stats merge assumes an ascii upstream.
@@ -113,7 +115,8 @@ bool protocol_stats_merge_name_val(genhash_t *merger,
char *name,
int name_len,
char *val,
- int val_len) {
+ int val_len,
+ int num_servers) {
assert(merger);
assert(name);
assert(val);
@@ -135,6 +138,10 @@ bool protocol_stats_merge_name_val(genhash_t *merger,
strncpy(buf_name, name, name_len);
buf_name[name_len] = '\0';
+ if (strstr(protocol_stats_keys_first, buf_key) != NULL) {
+ return true;
+ }
+
char *prev = (char *) genhash_find(merger, buf_name);
if (prev == NULL) {
char *hval = malloc(prefix_len + 1 +
@@ -159,10 +166,6 @@ bool protocol_stats_merge_name_val(genhash_t *merger,
strncpy(buf_key, key, key_len);
buf_key[key_len] = '\0';
- if (strstr(protocol_stats_keys_first, buf_key) != NULL) {
- return true;
- }
-
token_t prev_tokens[MAX_TOKENS];
size_t prev_ntokens = scan_tokens(prev, prev_tokens,
MAX_TOKENS, NULL);

0 comments on commit 48db4b3

Please sign in to comment.
Something went wrong with that request. Please try again.