1
0
Fork 0
mirror of https://github.com/dragonflydb/dragonfly.git synced 2024-12-14 11:58:02 +00:00

chore(server): improve error logging if info command fails. (#196)

Related to #195.

Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
Roman Gershman 2022-07-09 09:17:42 +03:00 committed by GitHub
parent 1c81bfa66c
commit 9e36197742
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 54 deletions

View file

@ -89,45 +89,38 @@ void Sample(int64_t start, int64_t end, base::Histogram* hist) {
hist->Add((end - start) / 1000);
}
void BenchDash() {
Dash64 udt;
DashSds sds_dt;
base::Histogram hist;
void BenchDash(time_t start) {
uint64_t num = GetFlag(FLAGS_n);
Dash64 dt;
base::Histogram hist;
time_t start = absl::GetCurrentTimeNanos();
for (uint64_t i = 0; i < num; ++i) {
dt.Insert(i, 0);
udt.Insert(i, 0);
time_t end = absl::GetCurrentTimeNanos();
Sample(start, end, &hist);
start = end;
}
CONSOLE_INFO << hist.ToString();
}
inline sds Prefix() {
return sdsnew("xxxxxxxxxxxxxxxxxxxxxxx");
}
void BenchDashSds() {
void BenchDashSds(time_t start) {
uint64_t num = GetFlag(FLAGS_n);
base::Histogram hist;
sds key = sdscatsds(Prefix(), sdsfromlonglong(0));
DashSds dt;
time_t start = absl::GetCurrentTimeNanos();
for (uint64_t i = 0; i < num; ++i) {
dt.Insert(key, 0);
sds_dt.Insert(key, 0);
time_t end = absl::GetCurrentTimeNanos();
Sample(start, end, &hist);
key = sdscatsds(Prefix(), sdsfromlonglong(i + 1));
start = absl::GetCurrentTimeNanos();
}
CONSOLE_INFO << hist.ToString();
}
static uint64_t callbackHash(const void* key) {
@ -136,42 +129,33 @@ static uint64_t callbackHash(const void* key) {
static dictType IntDict = {callbackHash, NULL, NULL, NULL, NULL, NULL, NULL};
void BenchDict() {
dict* redis_dict = nullptr;
void BenchDict(time_t start) {
uint64_t num = GetFlag(FLAGS_n);
base::Histogram hist;
time_t start = absl::GetCurrentTimeNanos();
dict* d = dictCreate(&IntDict);
redis_dict = dictCreate(&IntDict);
for (uint64_t i = 0; i < num; ++i) {
dictAdd(d, (void*)i, nullptr);
dictAdd(redis_dict, (void*)i, nullptr);
time_t end = absl::GetCurrentTimeNanos();
Sample(start, end, &hist);
start = end;
}
dictRelease(d);
CONSOLE_INFO << hist.ToString();
}
void BenchDictSds() {
void BenchDictSds(time_t start) {
uint64_t num = GetFlag(FLAGS_n);
base::Histogram hist;
sds key = sdscat(Prefix(), sdsfromlonglong(0));
dict* d = dictCreate(&SdsDict);
redis_dict = dictCreate(&SdsDict);
time_t start = absl::GetCurrentTimeNanos();
for (uint64_t i = 0; i < num; ++i) {
dictAdd(d, key, nullptr);
dictAdd(redis_dict, key, nullptr);
time_t end = absl::GetCurrentTimeNanos();
Sample(start, end, &hist);
key = sdscatsds(Prefix(), sdsfromlonglong(i + 1));
start = absl::GetCurrentTimeNanos();
}
dictRelease(d);
CONSOLE_INFO << hist.ToString();
}
} // namespace dfly
@ -184,20 +168,23 @@ int main(int argc, char* argv[]) {
bool is_dash = GetFlag(FLAGS_dash);
bool is_sds = GetFlag(FLAGS_sds);
uint64_t start = absl::GetCurrentTimeNanos();
if (is_dash) {
if (is_sds) {
BenchDashSds();
BenchDashSds(start);
} else {
BenchDash();
BenchDash(start);
}
} else {
if (is_sds) {
BenchDictSds();
BenchDictSds(start);
} else {
BenchDict();
BenchDict(start);
}
}
CONSOLE_INFO << "latencies histogram (usec):\n" << hist.ToString();
uint64_t delta = (absl::GetCurrentTimeNanos() - start) / 1000000;
CONSOLE_INFO << "Took " << delta << " ms";
return 0;
}

View file

@ -344,12 +344,14 @@ void PrintPrometheusMetrics(const Metrics& m, StringResponse* resp) {
MetricType::GAUGE, &resp->body());
// Memory metrics
AppendMetricWithoutLabels("memory_used_bytes", "", m.heap_used_bytes, MetricType::GAUGE, &resp->body());
AppendMetricWithoutLabels("memory_used_bytes", "", m.heap_used_bytes, MetricType::GAUGE,
&resp->body());
AppendMetricWithoutLabels("memory_used_peak_bytes", "", used_mem_peak.load(memory_order_relaxed),
MetricType::GAUGE, &resp->body());
AppendMetricWithoutLabels("comitted_memory", "", _mi_stats_main.committed.current,
MetricType::GAUGE, &resp->body());
AppendMetricWithoutLabels("memory_max_bytes", "", max_memory_limit, MetricType::GAUGE, &resp->body());
AppendMetricWithoutLabels("memory_max_bytes", "", max_memory_limit, MetricType::GAUGE,
&resp->body());
AppendMetricWithoutLabels("commands_processed_total", "", m.conn_stats.command_cnt,
MetricType::COUNTER, &resp->body());
@ -817,7 +819,8 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
append("used_memory_rss", sdata_res->vm_rss);
append("used_memory_rss_human", HumanReadableNumBytes(sdata_res->vm_rss));
} else {
LOG(ERROR) << "Error fetching /proc/self/status stats";
LOG_FIRST_N(ERROR, 10) << "Error fetching /proc/self/status stats. error "
<< sdata_res.error().message();
}
// Blob - all these cases where the key/objects are represented by a single blob allocated on
@ -950,17 +953,17 @@ void ServerFamily::Info(CmdArgList args, ConnectionContext* cntx) {
}
if (should_enter("CPU")) {
ADD_HEADER("# CPU");
struct rusage ru, cu, tu;
getrusage(RUSAGE_SELF, &ru);
getrusage(RUSAGE_CHILDREN, &cu);
getrusage(RUSAGE_THREAD, &tu);
append("used_cpu_sys", StrCat(ru.ru_stime.tv_sec, ".", ru.ru_stime.tv_usec));
append("used_cpu_user", StrCat(ru.ru_utime.tv_sec, ".", ru.ru_utime.tv_usec));
append("used_cpu_sys_children", StrCat(cu.ru_stime.tv_sec, ".", cu.ru_stime.tv_usec));
append("used_cpu_user_children", StrCat(cu.ru_utime.tv_sec, ".", cu.ru_utime.tv_usec));
append("used_cpu_sys_main_thread", StrCat(tu.ru_stime.tv_sec, ".", tu.ru_stime.tv_usec));
append("used_cpu_user_main_thread", StrCat(tu.ru_utime.tv_sec, ".", tu.ru_utime.tv_usec));
ADD_HEADER("# CPU");
struct rusage ru, cu, tu;
getrusage(RUSAGE_SELF, &ru);
getrusage(RUSAGE_CHILDREN, &cu);
getrusage(RUSAGE_THREAD, &tu);
append("used_cpu_sys", StrCat(ru.ru_stime.tv_sec, ".", ru.ru_stime.tv_usec));
append("used_cpu_user", StrCat(ru.ru_utime.tv_sec, ".", ru.ru_utime.tv_usec));
append("used_cpu_sys_children", StrCat(cu.ru_stime.tv_sec, ".", cu.ru_stime.tv_usec));
append("used_cpu_user_children", StrCat(cu.ru_utime.tv_sec, ".", cu.ru_utime.tv_usec));
append("used_cpu_sys_main_thread", StrCat(tu.ru_stime.tv_sec, ".", tu.ru_stime.tv_usec));
append("used_cpu_user_main_thread", StrCat(tu.ru_utime.tv_sec, ".", tu.ru_utime.tv_usec));
}
(*cntx)->SendBulkString(info);
@ -994,7 +997,6 @@ void ServerFamily::Hello(CmdArgList args, ConnectionContext* cntx) {
(*cntx)->SendBulkString("standalone");
(*cntx)->SendBulkString("role");
(*cntx)->SendBulkString((*ServerState::tlocal()).is_master ? "master" : "slave");
}
void ServerFamily::ReplicaOf(CmdArgList args, ConnectionContext* cntx) {
@ -1137,8 +1139,7 @@ void ServerFamily::Register(CommandRegistry* registry) {
<< CI{"INFO", CO::LOADING, -1, 0, 0, 0}.HFUNC(Info)
<< CI{"HELLO", CO::LOADING, -1, 0, 0, 0}.HFUNC(Hello)
<< CI{"LASTSAVE", CO::LOADING | CO::FAST, 1, 0, 0, 0}.HFUNC(LastSave)
<< CI{"LATENCY", CO::NOSCRIPT | CO::LOADING | CO::FAST, -2, 0, 0, 0}.HFUNC(
Latency)
<< CI{"LATENCY", CO::NOSCRIPT | CO::LOADING | CO::FAST, -2, 0, 0, 0}.HFUNC(Latency)
<< CI{"MEMORY", kMemOpts, -2, 0, 0, 0}.HFUNC(Memory)
<< CI{"SAVE", CO::ADMIN | CO::GLOBAL_TRANS, 1, 0, 0, 0}.HFUNC(Save)
<< CI{"SHUTDOWN", CO::ADMIN | CO::NOSCRIPT | CO::LOADING, 1, 0, 0, 0}.HFUNC(_Shutdown)