This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
add cluster balance indicator #214
Merged
Merged
Changes from 21 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
b2b4490
add cluster balance indicator
973df4a
fix code format
190d1a1
add balancer counters
372e1d6
simplify balance score to balance checker operation count
b69aeef
fix code format
1ab0319
Merge pull request #8 from XiaoMi/master
mentoswang 09104fa
Merge pull request #10 from XiaoMi/master
mentoswang deca2c8
move balance operation counters into greedy_load_balancer
1c66447
minor fix
23c3362
calculate stddev of primary and all partition count of cluster as bal…
35c0843
fix bug
3b7de8e
fix according to review
66b9e81
Merge pull request #11 from XiaoMi/master
mentoswang 3149f39
add check interface for greedy_load_balance
35129b3
fix bug
c36258e
fix bug...
10d3e28
Merge branch 'master' into balance-indicator
qinzuoyan 4817720
fix according to review
937abc4
fix code format
6174b5f
fix according to review
53e43fb
fix according to review
938ac9c
fix according to review
bc0ecd8
fix typo
bf4ae85
fix bug
27ca053
fix according to review - use fmtlib
07399c2
minor fix
6156c6f
fix according to review
6e90087
fix according to review
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. | ||
// This source code is licensed under the Apache License Version 2.0, which | ||
// can be found in the LICENSE file in the root directory of this source tree. | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
||
namespace dsn { | ||
namespace math { | ||
|
||
double mean_stddev(const std::vector<unsigned> &result_set, bool partial_sample); | ||
|
||
} // namespace math | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. | ||
// This source code is licensed under the Apache License Version 2.0, which | ||
// can be found in the LICENSE file in the root directory of this source tree. | ||
|
||
#include <numeric> | ||
#include <algorithm> | ||
#include <math.h> | ||
#include <dsn/utility/stddev.h> | ||
|
||
namespace dsn { | ||
namespace math { | ||
|
||
double mean_stddev(const std::vector<unsigned> &result_set, bool partial_sample) | ||
{ | ||
double sum = std::accumulate(result_set.begin(), result_set.end(), 0.0); | ||
double mean = sum / result_set.size(); | ||
|
||
double accum = 0.0; | ||
std::for_each(result_set.begin(), result_set.end(), [&](const double d) { | ||
accum += (d - mean) * (d - mean); | ||
}); | ||
|
||
double stddev; | ||
if (partial_sample) | ||
stddev = sqrt(accum / (result_set.size() - 1)); | ||
else | ||
stddev = sqrt(accum / (result_set.size())); | ||
|
||
stddev = ((double)((int)((stddev + 0.005) * 100))) / 100; | ||
return stddev; | ||
} | ||
|
||
} // namespace math | ||
} // namespace dsn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,5 +183,13 @@ std::string string_md5(const char *buffer, unsigned length) | |
|
||
return result; | ||
} | ||
|
||
std::string to_string_with_precision(const double double_val, const int precision) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 用 fmtlib,这个函数没必要写,http://fmtlib.net/latest/syntax.html |
||
{ | ||
std::ostringstream out; | ||
out.precision(precision); | ||
out << std::fixed << double_val; | ||
return out.str(); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
那这里还不如改为dsn::utils 名字空间,和其他工具函数保持一致。
另外文件名改为math.h/math.cpp,这样以后有其他数学相关的函数也都放在这里。