Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: time unit not match in ThreadMetricUtil.cpp #5607

Merged
merged 2 commits into from
Aug 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions dbms/src/Common/ThreadMetricUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include <Common/Stopwatch.h>
#include <Common/ThreadMetricUtil.h>
#include <Common/TiFlashMetrics.h>
#include <common/types.h>

std::atomic<UInt64> last_max_thds_metric_reset_ts{0};
const std::chrono::duration<UInt64> max_thds_metric_reset_interval{60}; // 60s
using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point;
std::atomic<TimePoint> last_max_thds_metric_reset_ts{};
const std::chrono::seconds max_thds_metric_reset_interval{60}; // 60s

namespace DB
{
bool tryToResetMaxThreadsMetrics()
{
using nanoseconds = std::chrono::duration<UInt64, std::nano>;
UInt64 last_max_thds_metric_reset_ts_tmp = last_max_thds_metric_reset_ts.load(std::memory_order_relaxed);
UInt64 now_ts = clock_gettime_ns_adjusted(last_max_thds_metric_reset_ts_tmp, CLOCK_MONOTONIC);
if (nanoseconds(now_ts) > nanoseconds(last_max_thds_metric_reset_ts_tmp) + max_thds_metric_reset_interval)
auto last_max_thds_metric_reset_ts_tmp = last_max_thds_metric_reset_ts.load(std::memory_order_relaxed);
Comment on lines -29 to +28
Copy link
Contributor

@bestwoody bestwoody Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is overhead of new one the same as clock_monotonic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, a little bit slower……

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then I think that will be bad,why bother changing into a slower one...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class std::chrono::steady_clock represents a monotonic clock. The time points of this clock cannot decrease as physical time moves forward and the time between ticks of this clock is constant. This clock is not related to wall clock time (for example, it can be time since last reboot), and is most suitable for measuring intervals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is better to use std::chrono::steady_clock to measure intervals.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess std::chrono::steady_clock actually calls clock_gettime(MONOTONIC). you can try to confirm it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do things right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

auto now = std::max(Clock::now(), last_max_thds_metric_reset_ts_tmp);
if (now > last_max_thds_metric_reset_ts_tmp + max_thds_metric_reset_interval)
{
last_max_thds_metric_reset_ts.store(now_ts, std::memory_order_relaxed);
last_max_thds_metric_reset_ts.store(now, std::memory_order_relaxed);
GET_METRIC(tiflash_thread_count, type_max_threads_of_dispatch_mpp).Set(GET_METRIC(tiflash_thread_count, type_active_threads_of_dispatch_mpp).Value());
GET_METRIC(tiflash_thread_count, type_max_threads_of_establish_mpp).Set(GET_METRIC(tiflash_thread_count, type_active_threads_of_establish_mpp).Value());
GET_METRIC(tiflash_thread_count, type_max_threads_of_raw).Set(GET_METRIC(tiflash_thread_count, type_total_threads_of_raw).Value());
Expand All @@ -39,4 +39,4 @@ bool tryToResetMaxThreadsMetrics()
}
return false;
}
} // namespace DB
} // namespace DB