malloc opt
This commit is contained in:
@ -87,9 +87,10 @@ struct ObMallocSamplePairCmp
|
||||
}
|
||||
};
|
||||
|
||||
inline uint64_t ob_malloc_sample_hash(const char* data)
|
||||
inline uint64_t ob_malloc_sample_hash(uint64_t v1, uint64_t v2)
|
||||
{
|
||||
return (uint64_t)data * 0xdeece66d + 0xb;
|
||||
uint64_t data = (v1<<32) | ((v2<<32)>>32);
|
||||
return data * 0xdeece66d + 0xb;
|
||||
}
|
||||
|
||||
inline ObMallocSampleLimiter::ObMallocSampleLimiter()
|
||||
@ -124,7 +125,8 @@ inline bool ObMallocSampleLimiter::malloc_sample_allowed(const int64_t size, con
|
||||
// Full sample when size is bigger than 16M.
|
||||
ret = true;
|
||||
} else {
|
||||
uint64_t hash_val = ob_malloc_sample_hash(attr.label_.str_);
|
||||
int64_t tid = ob_gettid();
|
||||
uint64_t hash_val = ob_malloc_sample_hash((uint64_t)attr.label_.str_, tid);
|
||||
if (rate_limiters[hash_val & MAX_MALLOC_SAMPLER_NUM].try_acquire(size)) {
|
||||
ret = true;
|
||||
}
|
||||
|
||||
@ -15,8 +15,6 @@
|
||||
#include "lib/utility/ob_print_utils.h"
|
||||
using namespace oceanbase::lib;
|
||||
using namespace oceanbase::common;
|
||||
|
||||
volatile int64_t ObMallocTimeMonitor::WARN_THRESHOLD = 100000;
|
||||
void ObMallocTimeMonitor::print()
|
||||
{
|
||||
char buf[1024] = {'\0'};
|
||||
@ -29,8 +27,8 @@ void ObMallocTimeMonitor::print()
|
||||
int64_t avg_cost_time = (0 == delta_count ? 0 : delta_total_cost_time / delta_count);
|
||||
last_total_cost_times_[i] = total_cost_time;
|
||||
last_counts_[i] = count;
|
||||
int64_t left = (0 == i ? 0 : TIME_SLOT[i-1]);
|
||||
int64_t right = TIME_SLOT[i];
|
||||
int64_t left = TIME_SLOT[i];
|
||||
int64_t right = TIME_SLOT[i + 1];
|
||||
databuff_printf(buf, sizeof(buf), pos, "[MALLOC_TIME_MONITOR] [%8ld,%20ld): delta_total_cost_time=%15ld, delta_count=%15ld, avg_cost_time=%8ld\n",
|
||||
left, right, delta_total_cost_time, delta_count, avg_cost_time);
|
||||
|
||||
|
||||
@ -22,9 +22,10 @@ namespace lib
|
||||
class ObMallocTimeMonitor
|
||||
{
|
||||
public:
|
||||
static volatile int64_t WARN_THRESHOLD;
|
||||
static constexpr const int64_t TIME_SLOT[] = {10, 100, 1000, 10000, 100000, 1000000, INT64_MAX};
|
||||
static const int64_t TIME_SLOT_NUM = ARRAYSIZEOF(TIME_SLOT);
|
||||
static const int64_t WARN_THRESHOLD = 100000;
|
||||
static const int64_t RECORD_THRESHOLD = 1000;
|
||||
static constexpr const int64_t TIME_SLOT[] = {1000, 10000, 100000, 1000000, INT64_MAX};
|
||||
static const int64_t TIME_SLOT_NUM = ARRAYSIZEOF(TIME_SLOT) - 1;
|
||||
ObMallocTimeMonitor()
|
||||
{
|
||||
MEMSET(this, 0, sizeof(*this));
|
||||
@ -35,28 +36,32 @@ public:
|
||||
static ObMallocTimeMonitor instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void inc(int64_t cost_time)
|
||||
{
|
||||
for (int i = 0; i < TIME_SLOT_NUM; ++i) {
|
||||
if (cost_time < TIME_SLOT[i]) {
|
||||
if (cost_time < TIME_SLOT[i + 1]) {
|
||||
total_cost_times_[i].inc(cost_time);
|
||||
counts_[i].inc(1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void record_malloc_time(ObBasicTimeGuard& time_guard, const int64_t size, const ObMemAttr& attr)
|
||||
{
|
||||
const int64_t cost_time = time_guard.get_diff();
|
||||
inc(cost_time);
|
||||
if (OB_UNLIKELY(cost_time > WARN_THRESHOLD)) {
|
||||
const int64_t buf_len = 1024;
|
||||
char buf[buf_len] = {'\0'};
|
||||
int64_t pos = attr.to_string(buf, buf_len);
|
||||
(void)logdata_printf(buf, buf_len, pos, ", size=%ld, ", size);
|
||||
pos += time_guard.to_string(buf + pos, buf_len - pos);
|
||||
int64_t tid = GETTID();
|
||||
fprintf(stderr, "[%ld]OB_MALLOC COST TOO MUCH TIME, cost_time=%ld, %.*s\n", tid, cost_time, static_cast<int>(pos), buf);
|
||||
if (OB_UNLIKELY(cost_time >= RECORD_THRESHOLD)) {
|
||||
inc(cost_time);
|
||||
if (OB_UNLIKELY(cost_time > WARN_THRESHOLD)) {
|
||||
const int64_t buf_len = 1024;
|
||||
char buf[buf_len] = {'\0'};
|
||||
int64_t pos = attr.to_string(buf, buf_len);
|
||||
(void)logdata_printf(buf, buf_len, pos, ", size=%ld, ", size);
|
||||
pos += time_guard.to_string(buf + pos, buf_len - pos);
|
||||
int64_t tid = GETTID();
|
||||
fprintf(stderr, "[%ld]OB_MALLOC COST TOO MUCH TIME, cost_time=%ld, %.*s\n", tid, cost_time, static_cast<int>(pos), buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
void print();
|
||||
|
||||
2
deps/oblib/src/lib/stat/ob_latch_define.h
vendored
2
deps/oblib/src/lib/stat/ob_latch_define.h
vendored
@ -80,7 +80,7 @@ LATCH_DEF(SERVER_STATUS_LOCK, 53, "server status lock", LATCH_READ_PREFER, 2000,
|
||||
LATCH_DEF(SERVER_MAINTAINCE_LOCK, 54, "server maintaince lock", LATCH_READ_PREFER, 2000, 0, true)
|
||||
LATCH_DEF(UNIT_MANAGER_LOCK, 55, "unit manager lock", LATCH_READ_PREFER, 2000, 0, true)
|
||||
LATCH_DEF(ZONE_MANAGER_LOCK, 56, "zone manager maintaince lock", LATCH_READ_PREFER, 2000, 0, true)
|
||||
LATCH_DEF(ALLOC_OBJECT_LOCK, 57, "object set lock", LATCH_READ_PREFER, 2000, 0, true)
|
||||
LATCH_DEF(ALLOC_OBJECT_LOCK, 57, "object set lock", LATCH_READ_PREFER, 1, 0, true)
|
||||
LATCH_DEF(ALLOC_BLOCK_LOCK, 58, "block set lock", LATCH_READ_PREFER, 2000, 0, true)
|
||||
LATCH_DEF(TRACE_RECORDER_LOCK, 59, "normal trace recorder lock", LATCH_FIFO, 2000, 0, true)
|
||||
LATCH_DEF(SESSION_TRACE_RECORDER_LOCK, 60, "session trace recorder lock", LATCH_FIFO, 2000, 0, true)
|
||||
|
||||
Reference in New Issue
Block a user