Skip to content

Commit

Permalink
fix: time unit not match in ThreadMetricUtil.cpp (#5607)
Browse files Browse the repository at this point in the history
close #5595
  • Loading branch information
Lloyd-Pottiger authored Aug 11, 2022
1 parent 0dd2791 commit 7c99386
Showing 1 changed file with 9 additions and 9 deletions.
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);
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

0 comments on commit 7c99386

Please sign in to comment.