Skip to content

Commit 72ce996

Browse files
authored
Merge pull request #82 from eleme/revert-70-feature/SlowLog
Revert "Send slow command to statsd. Close #33"
2 parents e0d211a + ad7be47 commit 72ce996

File tree

8 files changed

+9
-131
lines changed

8 files changed

+9
-131
lines changed

corvus.conf

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,6 @@ syslog 0
3838
#
3939
# statsd localhost:8125
4040
# metric_interval 10
41-
#
42-
# Slowlog:
43-
# Send slow command to statsd. The `slow_threshold` is in microseconds,
44-
# every command whose lantency exceeds `slow_threshold` will be sent.
45-
# Note that the lantency here is the time spent in proxy,
46-
# including redirection caused by MOVED and ASK.
47-
# Set it to negative value to disable slow log.
48-
#
49-
# slow_threshold 1000
5041

5142
# Buffer size allocated each time avoiding fregments
5243
# Buffer used in processing data recieving or sending

src/command.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ enum {
3636
CMD_EXTRA,
3737
};
3838

39+
struct cmd_item {
40+
char *cmd;
41+
int value;
42+
int type;
43+
int access;
44+
};
45+
3946
const char *rep_err = "-ERR Proxy error\r\n";
4047
const char *rep_parse_err = "-ERR Proxy fail to parse command\r\n";
4148
const char *rep_forward_err = "-ERR Proxy fail to forward command\r\n";
@@ -54,8 +61,7 @@ static const char *rep_noauth = "-NOAUTH Authentication required.\r\n";
5461
static const char *rep_auth_err = "-ERR invalid password\r\n";
5562
static const char *rep_auth_not_set = "-ERR Client sent AUTH, but no password is set\r\n";
5663

57-
struct cmd_item cmds[] = {CMD_DO(CMD_BUILD_MAP)};
58-
const size_t CMD_NUM = sizeof(cmds) / sizeof(struct cmd_item);
64+
static struct cmd_item cmds[] = {CMD_DO(CMD_BUILD_MAP)};
5965
static struct dict command_map;
6066

6167
static inline uint8_t *cmd_get_data(struct mbuf *b, struct buf_ptr ptr[], int *len)
@@ -927,10 +933,6 @@ void cmd_stats(struct command *cmd, int64_t end_time)
927933
ATOMIC_INC(ctx->stats.total_latency, latency);
928934
ATOMIC_SET(ctx->last_command_latency, latency);
929935

930-
if (config.slow_threshold >= 0 && latency > config.slow_threshold * 1000) {
931-
ATOMIC_INC(cmd->server->info->slow_cmd_counts[cmd->cmd_type], 1);
932-
}
933-
934936
if (!STAILQ_EMPTY(&cmd->sub_cmds)) {
935937
first = STAILQ_FIRST(&cmd->sub_cmds);
936938
last = STAILQ_LAST(&cmd->sub_cmds, command, sub_cmd_next);

src/command.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,6 @@ struct redirect_info {
231231
int type;
232232
};
233233

234-
struct cmd_item {
235-
char *cmd;
236-
int value;
237-
int type;
238-
int access;
239-
};
240-
241234
/* error responses */
242235
const char *rep_err,
243236
*rep_parse_err,

src/connection.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ static struct connection *conn_create_server(struct context *ctx,
7575
struct connection *server = server_create(ctx, fd);
7676
struct conn_info *info = server->info;
7777
memcpy(&info->addr, addr, sizeof(info->addr));
78-
extern const size_t CMD_NUM;
79-
info->slow_cmd_counts = cv_calloc(CMD_NUM, sizeof(uint32_t));
8078

8179
if (conn_connect(server) == CORVUS_ERR) {
8280
LOG(ERROR, "conn_create_server: fail to connect %s:%d",
@@ -104,7 +102,6 @@ void conn_info_init(struct conn_info *info)
104102
info->readonly = false;
105103
info->readonly_sent = false;
106104
info->quit = false;
107-
info->slow_cmd_counts = NULL;
108105

109106
memset(&info->addr, 0, sizeof(info->addr));
110107
memset(info->dsn, 0, sizeof(info->dsn));

src/connection.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,6 @@ struct conn_info {
6969
long long completed_commands;
7070

7171
int8_t status;
72-
73-
// slow log, only for server connection in worker thread
74-
uint32_t *slow_cmd_counts;
7572
};
7673

7774
TAILQ_HEAD(conn_tqh, connection);

src/corvus.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ void config_init()
3838
config.bufsize = DEFAULT_BUFSIZE;
3939
config.requirepass = NULL;
4040
config.readslave = config.readmasterslave = false;
41-
config.slow_threshold = -1;
4241

4342
memset(config.statsd_addr, 0, sizeof(config.statsd_addr));
4443
config.metric_interval = 10;
@@ -148,8 +147,6 @@ int config_add(char *name, char *value)
148147
config.node.len++;
149148
p = strtok(NULL, ",");
150149
}
151-
} else if (strcmp(name, "slow_threshold") == 0) {
152-
config.slow_threshold = atoi(value);
153150
}
154151
return 0;
155152
}
@@ -344,7 +341,6 @@ void context_free(struct context *ctx)
344341
cmd_iov_free(&conn->info->iov);
345342
conn_free(conn);
346343
conn_buf_free(conn);
347-
cv_free(conn->info->slow_cmd_counts);
348344
cv_free(conn->info);
349345
cv_free(conn);
350346
}

src/corvus.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ struct {
104104
int64_t client_timeout;
105105
int64_t server_timeout;
106106
int bufsize;
107-
int64_t slow_threshold;
108107
} config;
109108

110109
int64_t get_time();

src/stats.c

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "socket.h"
99
#include "logging.h"
1010
#include "slot.h"
11-
#include "alloc.h"
1211

1312
#define HOST_LEN 255
1413

@@ -34,19 +33,6 @@ static struct {
3433
double user;
3534
} used_cpu;
3635

37-
static struct dict slow_counts; // node dsn => slow cmd counts
38-
39-
40-
static void stats_free_slow_counts()
41-
{
42-
struct dict_iter iter = DICT_ITER_INITIALIZER;
43-
DICT_FOREACH(&slow_counts, &iter) {
44-
cv_free(iter.value);
45-
}
46-
47-
dict_free(&slow_counts);
48-
}
49-
5036
static inline void stats_get_cpu_usage(struct stats *stats)
5137
{
5238
struct rusage ru;
@@ -191,7 +177,7 @@ void stats_send_node_info()
191177
{
192178
struct bytes *value;
193179

194-
/* redis-node.127-0-0-1-8000.bytes.{send,recv} */
180+
/* redis-node.127-0-0-1:8000.bytes.{send,recv} */
195181
int len = HOST_LEN + 64;
196182
char name[len];
197183

@@ -230,85 +216,6 @@ void stats_get(struct stats *stats)
230216
}
231217
}
232218

233-
static void stats_send_slow_log()
234-
{
235-
if (config.slow_threshold < 0)
236-
return;
237-
238-
const char *fmt = "redis-node.%s.slow_query.%s";
239-
const char *sum_fmt = "slow_query.%s";
240-
extern struct cmd_item cmds[];
241-
extern const size_t CMD_NUM;
242-
243-
struct connection *server;
244-
struct context *contexts = get_contexts();
245-
246-
{
247-
struct dict_iter iter = DICT_ITER_INITIALIZER;
248-
DICT_FOREACH(&slow_counts, &iter) {
249-
memset(iter.value, 0, CMD_NUM * sizeof(uint32_t));
250-
}
251-
}
252-
253-
uint32_t counts_sum[CMD_NUM];
254-
memset(counts_sum, 0, sizeof(counts_sum));
255-
256-
for (size_t i = 0; i < config.thread; i++) {
257-
TAILQ_FOREACH(server, &contexts[i].servers, next) {
258-
const char *dsn = server->info->dsn;
259-
uint32_t *node_counts = NULL;
260-
for (size_t j = 0; j < CMD_NUM; j++) {
261-
uint32_t count = ATOMIC_IGET(server->info->slow_cmd_counts[j], 0);
262-
if (count == 0) continue;
263-
264-
if (!node_counts) {
265-
node_counts = (uint32_t*)dict_get(&slow_counts, dsn);
266-
if (!node_counts) {
267-
node_counts = cv_calloc(CMD_NUM, sizeof(uint32_t));
268-
dict_set(&slow_counts, dsn, node_counts);
269-
}
270-
}
271-
node_counts[j] += count;
272-
counts_sum[j] += count;
273-
}
274-
}
275-
}
276-
277-
struct dict_iter iter = DICT_ITER_INITIALIZER;
278-
DICT_FOREACH(&slow_counts, &iter) {
279-
const char *dsn = iter.key;
280-
uint32_t *counts = (uint32_t*)iter.value;
281-
282-
char addr[ADDRESS_LEN] = {0};
283-
strncpy(addr, dsn, ADDRESS_LEN);
284-
for (size_t i = 0; i < ADDRESS_LEN; i++) {
285-
if (addr[i] == '.' || addr[i] == ':')
286-
addr[i] = '-';
287-
}
288-
289-
for (size_t i = 0; i < CMD_NUM; i++) {
290-
if(counts[i] == 0) continue;
291-
292-
const char *cmd = cmds[i].cmd;
293-
int n = snprintf(NULL, 0, fmt, addr, cmd);
294-
char buf[n + 1];
295-
snprintf(buf, sizeof(buf), fmt, addr, cmd);
296-
stats_send(buf, counts[i]);
297-
}
298-
}
299-
300-
for (size_t i = 0; i < CMD_NUM; i++) {
301-
uint32_t sum = counts_sum[i];
302-
if (sum) {
303-
const char *cmd = cmds[i].cmd;
304-
int n = snprintf(NULL, 0, sum_fmt, cmd);
305-
char buf[n + 1];
306-
snprintf(buf, sizeof(buf), sum_fmt, cmd);
307-
stats_send(buf, sum);
308-
}
309-
}
310-
}
311-
312219
void *stats_daemon(void *data)
313220
{
314221
/* Make the thread killable at any time can work reliably. */
@@ -319,7 +226,6 @@ void *stats_daemon(void *data)
319226
sleep(config.metric_interval);
320227
stats_send_simple();
321228
stats_send_node_info();
322-
stats_send_slow_log();
323229
LOG(DEBUG, "sending metrics");
324230
}
325231
return NULL;
@@ -344,8 +250,6 @@ int stats_init()
344250
if (hostname[i] == '.') hostname[i] = '-';
345251
}
346252

347-
dict_init(&slow_counts);
348-
349253
LOG(INFO, "starting stats thread");
350254
return thread_spawn(&stats_ctx, stats_daemon);
351255
}
@@ -355,7 +259,6 @@ void stats_kill()
355259
int err;
356260

357261
dict_free(&bytes_map);
358-
stats_free_slow_counts();
359262

360263
if (pthread_cancel(stats_ctx.thread) == 0) {
361264
if ((err = pthread_join(stats_ctx.thread, NULL)) != 0) {

0 commit comments

Comments
 (0)