提交 e020cc1e 编写于 作者: M Marbin Tan 提交者: Management and Monitoring Team

Revert "gpperfmon: refactor to make 'skew' calculation more readable"

This code is not correctly recording the data. There seems to be a bug
with how we're modifying the values. Most likely, that we're trying to
change the address instead of the actual value it's pointing to.

We will need to fully run the test this part of the code again and create a new PR.

This reverts commit 411d3c82.
上级 43492c38
......@@ -1097,77 +1097,41 @@ static apr_int64_t get_rowsout(qdnode_t* qdnode)
return rowsout;
}
static void _get_sum_seg_info(apr_hash_t* segtab, apr_int64_t *total_data_out, int* segcount_out)
static double get_cpu_skew(qdnode_t* qdnode)
{
apr_hash_index_t *hi;
void* valptr;
apr_int64_t* seg_data_sum = NULL;
apr_pool_t* tmp_pool;
apr_hash_t* segtab;
apr_hash_index_t *hi;
for (hi = apr_hash_first(NULL, segtab); hi; hi = apr_hash_next(hi))
{
apr_hash_this(hi, 0, 0, &valptr);
seg_data_sum = (apr_int64_t*) valptr;
total_data_out += *seg_data_sum;
TR2(("(SKEW) Segment resource usage: %d\n", *seg_data_sum));
segcount_out++;
}
}
// qenode_t* pqe = NULL;
static void _get_sum_deviation_squared(apr_hash_t* segtab, const apr_int64_t data_avg, apr_int64_t *total_deviation_squared_out)
{
apr_hash_index_t *hi;
void* valptr;
apr_int64_t* seg_data_sum = NULL;
apr_int64_t cpu_avg = 0;
apr_int64_t* seg_cpu_sum = NULL;
void* valptr;
for (hi = apr_hash_first(NULL, segtab); hi; hi = apr_hash_next(hi))
{
apr_int64_t dev = 0;
apr_hash_this(hi, NULL, NULL, &valptr);
seg_data_sum = (apr_int64_t*) valptr;
dev = *seg_data_sum - data_avg;
TR2(("(SKEW) Deviation: %d\n", dev));
total_deviation_squared_out += dev * dev;
}
}
static double get_cpu_skew(qdnode_t* qdnode)
{
apr_pool_t* tmp_pool;
apr_hash_t* segtab;
apr_hash_index_t *hi;
double var = 0.0f;
apr_int64_t cpu_avg = 0;
apr_int64_t total_cpu = 0;
apr_int64_t total_deviation_squared = 0;
double variance = 0;
double standard_deviation = 0;
double coefficient_of_variation = 0;
apr_int64_t* seg_cpu_sum = NULL;
void* valptr;
int segcnt = 0;
int e;
int segcnt = 0;
int e;
if (!qdnode)
return 0.0f;
if (!qdnode)
return 0.0f;
if (0 != (e = apr_pool_create_alloc(&tmp_pool, 0)))
if (0 != (e = apr_pool_create_alloc(&tmp_pool, 0)))
{
gpmon_warningx(FLINE, e, "apr_pool_create_alloc failed");
return 0.0f;
gpmon_warningx(FLINE, e, "apr_pool_create_alloc failed");
return 0.0f;
}
segtab = apr_hash_make(tmp_pool);
if (!segtab)
segtab = apr_hash_make(tmp_pool);
if (!segtab)
{
gpmon_warning(FLINE, "Out of memory");
return 0.0f;
gpmon_warning(FLINE, "Out of memory");
return 0.0f;
}
TR2(("Calc mean per segment\n"));
/* Calc mean per segment */
TR2( ("Calc mean per segment\n"));
for (hi = apr_hash_first(NULL, qdnode->query_seginfo_hash); hi; hi = apr_hash_next(hi))
{
mmon_query_seginfo_t *rec;
......@@ -1187,69 +1151,82 @@ static double get_cpu_skew(qdnode_t* qdnode)
apr_hash_set(segtab, &rec->key.segid, sizeof(rec->key.segid), seg_cpu_sum);
}
_get_sum_seg_info(segtab, &total_cpu, &segcnt);
if (!segcnt) {
TR2(("No segments for CPU skew calculation\n"));
apr_pool_destroy(tmp_pool);
return 0.0f;
}
/* Calc mean across all segments */
for (hi = apr_hash_first(NULL, segtab); hi; hi = apr_hash_next(hi))
{
apr_hash_this(hi, 0, 0, &valptr);
seg_cpu_sum = (apr_int64_t*) valptr;
cpu_avg += *seg_cpu_sum;
TR2(("(SKEW) Segment rusage: %d\n", *seg_cpu_sum));
segcnt++;
}
cpu_avg = total_cpu / segcnt;
TR2(("(SKEW) Avg resource usage: %" FMT64 "\n", cpu_avg));
if (!segcnt) {
TR2(("No segments for CPU skew calculation\n"));
apr_pool_destroy(tmp_pool);
return 0.0f;
}
_get_sum_deviation_squared(segtab, cpu_avg, &total_deviation_squared);
cpu_avg = cpu_avg / segcnt;
TR2(("(SKEW) Avg rusage: %" FMT64 "\n", cpu_avg));
variance = total_deviation_squared / (double)segcnt;
/* Calc sqrt of dev squared mean */
for (hi = apr_hash_first(NULL, segtab); hi; hi = apr_hash_next(hi))
{
apr_int64_t dev = 0;
standard_deviation = sqrt(variance);
apr_hash_this(hi, NULL, NULL, &valptr);
seg_cpu_sum = (apr_int64_t*) valptr;
dev = *seg_cpu_sum - cpu_avg;
TR2(("(SKEW) Deviation: %d\n", dev));
var += dev * dev;
}
TR2(("(SKEW) CPU standard deviation: %f\n", standard_deviation));
var = sqrt(var / (double)segcnt);
coefficient_of_variation = cpu_avg ? standard_deviation/(double)cpu_avg : 0.0f;
TR2(("(SKEW) CPU variance: %f\n", var));
apr_pool_destroy(tmp_pool);
TR2(("(SKEW) CPU Skew: %f\n", coefficient_of_variation));
/* Skew calc */
apr_pool_destroy(tmp_pool);
TR2(("(SKEW) CPU Skew: %f\n", cpu_avg ? var/(double)cpu_avg : 0.0f));
return coefficient_of_variation;
return (cpu_avg ? (var/(double)cpu_avg) * 100.0f : 0.0f);
}
static double get_row_skew(qdnode_t* qdnode)
{
apr_pool_t* tmp_pool;
apr_hash_t* segtab;
apr_hash_index_t *hi;
apr_int64_t total_row_out = 0;
apr_int64_t total_deviation_squared = 0;
double variance = 0.0f;
double standard_deviation = 0;
double coefficient_of_variation = 0;
apr_int64_t row_out_avg = 0;
apr_int64_t* seg_row_out_sum = NULL;
void* valptr;
apr_pool_t* tmp_pool;
apr_hash_t* segtab;
apr_hash_index_t *hi;
int segcnt = 0;
int e;
apr_int64_t row_out_avg = 0;
apr_int64_t* seg_row_out_sum = NULL;
void* valptr;
double var = 0.0f;
if (!qdnode)
return 0.0f;
int segcnt = 0;
int e;
if (0 != (e = apr_pool_create_alloc(&tmp_pool, 0)))
if (!qdnode)
return 0.0f;
if (0 != (e = apr_pool_create_alloc(&tmp_pool, 0)))
{
gpmon_warningx(FLINE, e, "apr_pool_create_alloc failed");
return 0.0f;
gpmon_warningx(FLINE, e, "apr_pool_create_alloc failed");
return 0.0f;
}
segtab = apr_hash_make(tmp_pool);
if (!segtab)
segtab = apr_hash_make(tmp_pool);
if (!segtab)
{
gpmon_warning(FLINE, "Out of memory");
return 0.0f;
gpmon_warning(FLINE, "Out of memory");
return 0.0f;
}
/* Calc rows in sum per segment */
TR2(("Calc rows in sum per segment\n"));
TR2( ("Calc rows in sum per segment\n"));
for (hi = apr_hash_first(NULL, qdnode->query_seginfo_hash); hi; hi = apr_hash_next(hi))
{
mmon_query_seginfo_t *rec;
......@@ -1269,31 +1246,46 @@ static double get_row_skew(qdnode_t* qdnode)
apr_hash_set(segtab, &rec->key.segid, sizeof(rec->key.segid), seg_row_out_sum);
}
_get_sum_seg_info(segtab, &total_row_out, &segcnt);
/* Calc rows in mean across all segments */
for (hi = apr_hash_first(NULL, segtab); hi; hi = apr_hash_next(hi))
{
apr_hash_this(hi, 0, 0, &valptr);
seg_row_out_sum = (apr_int64_t*) valptr;
row_out_avg += *seg_row_out_sum;
segcnt++;
}
if (!segcnt) {
TR2(("No segments for Rows skew calculation\n"));
apr_pool_destroy(tmp_pool);
return 0.0f;
}
if (!segcnt) {
TR2(("No segments for CPU skew calculation\n"));
apr_pool_destroy(tmp_pool);
return 0.0f;
}
row_out_avg = row_out_avg / segcnt;
row_out_avg = row_out_avg / segcnt;
TR2(("(SKEW) Avg rows out: %" FMT64 "\n", row_out_avg));
TR2(("(SKEW) Avg rows out: %" FMT64 "\n", row_out_avg));
_get_sum_deviation_squared(segtab, row_out_avg, &total_deviation_squared);
/* Calc sqrt of dev squared mean */
for (hi = apr_hash_first(NULL, segtab); hi; hi = apr_hash_next(hi))
{
apr_int64_t dev = 0;
variance = total_deviation_squared / (double)segcnt;
standard_deviation = sqrt(variance);
apr_hash_this(hi, NULL, NULL, &valptr);
seg_row_out_sum = (apr_int64_t*) valptr;
dev = *seg_row_out_sum - row_out_avg;
TR2(("(SKEW) Deviation: %d\n", dev));
var += dev * dev;
}
TR2(("(SKEW) Rows in standard deviaton: %f\n", standard_deviation));
var = sqrt(var / (double)segcnt);
coefficient_of_variation = row_out_avg ? standard_deviation/(double)row_out_avg : 0.0f;
TR2(("(SKEW) Rows in variance: %f\n", var));
apr_pool_destroy(tmp_pool);
TR2(("(SKEW) Rows out skew: %f\n", coefficient_of_variation));
/* Skew calc */
apr_pool_destroy(tmp_pool);
TR2(("(SKEW) Rows out skew: %f\n", row_out_avg ? var/(double)row_out_avg : 0.0f));
return coefficient_of_variation;
return (row_out_avg ? (var/(double)row_out_avg) * 100.0f : 0.0f);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册