Skip to content

Commit e2d9f19

Browse files
authored
add metrics log for join (#3988) (#630)
1 parent d559d28 commit e2d9f19

File tree

9 files changed

+46
-10
lines changed

9 files changed

+46
-10
lines changed

src/Interpreters/Streaming/ConcurrentHashJoin.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <Columns/ColumnSparse.h>
55
#include <Columns/IColumn.h>
66
#include <DataTypes/DataTypeLowCardinality.h>
7+
#include <IO/Operators.h>
8+
#include <IO/WriteBufferFromString.h>
79
#include <Common/Exception.h>
810
#include <Common/WeakHash.h>
911

@@ -389,6 +391,17 @@ std::shared_ptr<NotJoinedBlocks> ConcurrentHashJoin::getNonJoinedBlocks(
389391
ErrorCodes::LOGICAL_ERROR, "Invalid join type. join kind: {}, strictness: {}", table_join->kind(), table_join->strictness());
390392
}
391393

394+
String ConcurrentHashJoin::metricsString() const
395+
{
396+
WriteBufferFromOwnString wb;
397+
for (size_t i = 0; const auto & hash_join : hash_joins)
398+
{
399+
std::lock_guard lock(hash_join->mutex);
400+
wb << "HashJoin-" << i++ << "(" << hash_join->data->metricsString() << ")";
401+
}
402+
return wb.str();
403+
}
404+
392405
static ALWAYS_INLINE IColumn::Selector hashToSelector(const WeakHash32 & hash, size_t num_shards)
393406
{
394407
assert(num_shards > 0 && (num_shards & (num_shards - 1)) == 0);

src/Interpreters/Streaming/ConcurrentHashJoin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class ConcurrentHashJoin final : public IHashJoin
6262
bool supportParallelJoin() const override { return true; }
6363
std::shared_ptr<NotJoinedBlocks>
6464
getNonJoinedBlocks(const Block & left_sample_block, const Block & result_sample_block, UInt64 max_block_size) const override;
65+
String metricsString() const override;
6566

6667
void getKeyColumnPositions(
6768
std::vector<size_t> & left_key_column_positions_,

src/Interpreters/Streaming/HashJoin.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -866,14 +866,7 @@ HashJoin::HashJoin(
866866

867867
HashJoin::~HashJoin() noexcept
868868
{
869-
LOG_INFO(
870-
logger,
871-
"Left stream metrics: {{{}}}, right stream metrics: {{{}}}, global join metrics: {{{}}}, "
872-
"retract buffer metrics: {{{}}}",
873-
left_data.buffered_data->joinMetricsString(),
874-
right_data.buffered_data->joinMetricsString(),
875-
join_metrics.string(),
876-
join_results ? join_results->joinMetricsString(this) : "");
869+
LOG_INFO(logger, "{}", metricsString());
877870
}
878871

879872
void HashJoin::init()
@@ -1713,6 +1706,17 @@ struct AdderNonJoined
17131706
}
17141707
};
17151708

1709+
String HashJoin::metricsString() const
1710+
{
1711+
return fmt::format(
1712+
"Left stream metrics: {{{}}}, right stream metrics: {{{}}}, global join metrics: {{{}}}, "
1713+
"retract buffer metrics: {{{}}}",
1714+
left_data.buffered_data->joinMetricsString(),
1715+
right_data.buffered_data->joinMetricsString(),
1716+
join_metrics.string(),
1717+
join_results ? join_results->joinMetricsString(this) : "");
1718+
}
1719+
17161720
std::shared_ptr<NotJoinedBlocks>
17171721
HashJoin::getNonJoinedBlocks(const Block & /*left_sample_block*/, const Block & /*result_sample_block*/, UInt64 /*max_block_size*/) const
17181722
{

src/Interpreters/Streaming/HashJoin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ class HashJoin final : public IHashJoin
157157
std::shared_ptr<NotJoinedBlocks>
158158
getNonJoinedBlocks(const Block & left_sample_block, const Block & result_sample_block, UInt64 max_block_size) const override;
159159

160+
String metricsString() const final;
161+
160162
/// Number of keys in all built JOIN maps.
161163
size_t getTotalRowCount() const final;
162164
/// Sum size in bytes of all buffers, used for JOIN maps and for all memory pools.

src/Interpreters/Streaming/IHashJoin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class IHashJoin : public IJoin
3737
bool include_asof_key_column = false) const
3838
= 0;
3939

40+
virtual String metricsString() const { return ""; }
41+
4042
/// Whether hash join algorithm has buffer left/right data to align
4143
virtual bool leftStreamRequiresBufferingDataToAlign() const = 0;
4244
virtual bool rightStreamRequiresBufferingDataToAlign() const = 0;

src/Processors/Transforms/JoiningTransform.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ void JoiningTransform::transform(Chunk & chunk)
153153
{
154154
initialized = true;
155155

156+
/// proton: starts.
157+
LOG_INFO(&Poco::Logger::get("JoiningTransform"), "built hash map, total joined data {} rows, {} bytes", join->getTotalRowCount(), join->getTotalByteCount());
158+
/// proton: ends.
159+
156160
if (join->alwaysReturnsEmptySet() && !on_totals)
157161
{
158162
stop_reading = true;

src/Processors/Transforms/Streaming/JoinTransform.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ JoinTransform::JoinTransform(
3030
, output_header_chunk(outputs.front().getHeader().getColumns(), 0)
3131
, logger(&Poco::Logger::get("StreamingJoinTransform"))
3232
, input_ports_with_data{InputPortWithData{&inputs.front()}, InputPortWithData{&inputs.back()}}
33+
, last_log_ts(MonotonicSeconds::now())
3334
{
3435
assert(join);
3536

@@ -203,6 +204,12 @@ void JoinTransform::work()
203204
assert(!output_chunks.empty());
204205
output_chunks.back().setCheckpointContext(std::move(requested_ckpt));
205206
}
207+
208+
if (MonotonicSeconds::now() - last_log_ts > 60)
209+
{
210+
LOG_INFO(logger, "{}, watermark={}", join->metricsString(), watermark);
211+
last_log_ts = MonotonicSeconds::now();
212+
}
206213
}
207214

208215
inline void JoinTransform::propagateWatermark(int64_t local_watermark)

src/Processors/Transforms/Streaming/JoinTransform.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class JoinTransform final : public IProcessor
8282
NO_SERDE std::list<Chunk> output_chunks;
8383

8484
SERDE int64_t watermark = INVALID_WATERMARK;
85+
86+
NO_SERDE Int64 last_log_ts = 0;
8587
};
8688
}
8789
}

src/Processors/Transforms/Streaming/JoinTransformWithAlignment.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,12 @@ void JoinTransformWithAlignment::work()
354354

355355
need_propagate_heartbeat = false;
356356

357-
if (DB::MonotonicSeconds::now() - last_stats_log_ts >= 5)
357+
if (DB::MonotonicSeconds::now() - last_stats_log_ts >= 60)
358358
{
359359
LOG_INFO(
360360
log,
361-
"left_watermark={} right_watermark={} left_input_muted={} right_input_muted={} left_quiesce_joins={} right_quiesce_joins={}",
361+
"{}, left_watermark={} right_watermark={} left_input_muted={} right_input_muted={} left_quiesce_joins={} right_quiesce_joins={}",
362+
join->metricsString(),
362363
left_input.watermark,
363364
right_input.watermark,
364365
stats.left_input_muted,

0 commit comments

Comments
 (0)