@@ -67,6 +67,12 @@ struct LocalPartitionWaitStats {
6767 std::vector<int64_t > wallMs;
6868};
6969
70+ struct ExchangeRunStats {
71+ int64_t wallUs = 0 ;
72+ PlanNodeStats partitionedOutputStats;
73+ PlanNodeStats exchangeStats;
74+ };
75+
7076void sortByMax (std::vector<RuntimeMetric>& metrics) {
7177 std::sort (
7278 metrics.begin (),
@@ -88,6 +94,18 @@ void sortByAndPrintMax(
8894 << " \n Min: " << metrics.back ().toString () << std::endl;
8995}
9096
97+ void printExchangeStats (
98+ const std::string& datasetName,
99+ const std::string& modeName,
100+ const ExchangeRunStats& stats) {
101+ std::cout << " -----------------------------" << datasetName << " ("
102+ << modeName << " )-----------------------------" << std::endl;
103+ std::cout << " Wall Time (ms): " << succinctMicros (stats.wallUs ) << std::endl;
104+ std::cout << " PartitionOutput: " << stats.partitionedOutputStats .toString ()
105+ << std::endl;
106+ std::cout << " Exchange: " << stats.exchangeStats .toString () << std::endl;
107+ }
108+
91109class ExchangeBenchmark : public VectorTestBase {
92110 public:
93111 std::vector<RowVectorPtr> makeRows (
@@ -120,6 +138,7 @@ class ExchangeBenchmark : public VectorTestBase {
120138 std::vector<RowVectorPtr>& vectors,
121139 int32_t width,
122140 int32_t taskWidth,
141+ bool useOptimizedPartitionedOutput,
123142 int64_t & wallUs,
124143 PlanNodeStats& partitionedOutputStats,
125144 PlanNodeStats& exchangeStats) {
@@ -373,7 +392,7 @@ int32_t ExchangeBenchmark::iteration_;
373392
374393std::unique_ptr<ExchangeBenchmark> bm;
375394
376- void runBenchmarks () {
395+ void runBenchmarks (bool optimizedPartitionedOutputEnabled = false ) {
377396 std::vector<std::string> flatNames = {" c0" };
378397 std::vector<TypePtr> flatTypes = {BIGINT ()};
379398 std::vector<TypePtr> typeSelection = {
@@ -438,75 +457,51 @@ void runBenchmarks() {
438457 std::vector<RowVectorPtr> struct1k (
439458 bm->makeRows (structType, 100 , 1000 , FLAGS_dict_pct));
440459
441- int64_t flat10KWallUs;
442- PlanNodeStats partitionedOutputStatsFlat10K;
443- PlanNodeStats exchangeStatsFlat10K;
444- folly::addBenchmark (__FILE__, " exchangeFlat10k" , [&]() {
445- bm->run (
446- flat10k,
447- FLAGS_width,
448- FLAGS_task_width,
449- flat10KWallUs,
450- partitionedOutputStatsFlat10K,
451- exchangeStatsFlat10K);
452- return 1 ;
453- });
454-
455- int64_t flat50KWallUs;
456- PlanNodeStats partitionedOutputStatsFlat50;
457- PlanNodeStats exchangeStatsFlat50;
458- folly::addBenchmark (__FILE__, " exchangeFlat50" , [&]() {
459- bm->run (
460- flat50,
461- FLAGS_width,
462- FLAGS_task_width,
463- flat50KWallUs,
464- partitionedOutputStatsFlat50,
465- exchangeStatsFlat50);
466- return 1 ;
467- });
468-
469- int64_t deep10KWallUs;
470- PlanNodeStats partitionedOutputStatsDeep10K;
471- PlanNodeStats exchangeStatsDeep10K;
472- folly::addBenchmark (__FILE__, " exchangeDeep10k" , [&]() {
473- bm->run (
474- deep10k,
475- FLAGS_width,
476- FLAGS_task_width,
477- deep10KWallUs,
478- partitionedOutputStatsDeep10K,
479- exchangeStatsDeep10K);
480- return 1 ;
481- });
482-
483- int64_t deep50KWallUs;
484- PlanNodeStats partitionedOutputStatsDeep50;
485- PlanNodeStats exchangeStatsDeep50;
486- folly::addBenchmark (__FILE__, " exchangeDeep50" , [&]() {
487- bm->run (
488- deep50,
489- FLAGS_width,
490- FLAGS_task_width,
491- deep50KWallUs,
492- partitionedOutputStatsDeep50,
493- exchangeStatsDeep50);
494- return 1 ;
495- });
496-
497- int64_t stuct1KWallUs;
498- PlanNodeStats partitionedOutputStatsStruct1K;
499- PlanNodeStats exchangeStatsStruct1K;
500- folly::addBenchmark (__FILE__, " exchangeStruct1K" , [&]() {
501- bm->run (
502- struct1k,
503- FLAGS_width,
504- FLAGS_task_width,
505- stuct1KWallUs,
506- partitionedOutputStatsStruct1K,
507- exchangeStatsStruct1K);
508- return 1 ;
509- });
460+ std::vector<std::pair<std::string, std::vector<RowVectorPtr>*>> exchangeCases{
461+ {" Flat10K" , &flat10k},
462+ {" Flat50" , &flat50},
463+ {" Deep10K" , &deep10k},
464+ {" Deep50" , &deep50},
465+ {" Struct1K" , &struct1k}};
466+
467+ std::vector<ExchangeRunStats> normalPartitionedOutputStats (
468+ exchangeCases.size ());
469+ std::vector<ExchangeRunStats> optimizedPartitionedOutputStats (
470+ exchangeCases.size ());
471+
472+ for (size_t i = 0 ; i < exchangeCases.size (); ++i) {
473+ const auto & name = exchangeCases[i].first ;
474+ folly::addBenchmark (
475+ __FILE__,
476+ fmt::format (" exchange{}_normalPartitionedOutput" , name),
477+ [&, i]() {
478+ bm->run (
479+ *exchangeCases[i].second ,
480+ FLAGS_width,
481+ FLAGS_task_width,
482+ false ,
483+ normalPartitionedOutputStats[i].wallUs ,
484+ normalPartitionedOutputStats[i].partitionedOutputStats ,
485+ normalPartitionedOutputStats[i].exchangeStats );
486+ return 1 ;
487+ });
488+ if (optimizedPartitionedOutputEnabled) {
489+ folly::addBenchmark (
490+ __FILE__,
491+ fmt::format (" exchange{}_optimizedPartitionedOutput" , name),
492+ [&, i]() {
493+ bm->run (
494+ *exchangeCases[i].second ,
495+ FLAGS_width,
496+ FLAGS_task_width,
497+ true ,
498+ optimizedPartitionedOutputStats[i].wallUs ,
499+ optimizedPartitionedOutputStats[i].partitionedOutputStats ,
500+ optimizedPartitionedOutputStats[i].exchangeStats );
501+ return 1 ;
502+ });
503+ }
504+ }
510505
511506 int64_t localPartitionWallUs;
512507 PlanNodeStats localPartitionStatsFlat10K;
@@ -524,45 +519,16 @@ void runBenchmarks() {
524519
525520 folly::runBenchmarks ();
526521
527- std::cout
528- << " ----------------------------------Flat10K----------------------------------"
529- << std::endl;
530- std::cout << " Wall Time (ms): " << succinctMicros (flat10KWallUs) << std::endl;
531- std::cout << " PartitionOutput: " << partitionedOutputStatsFlat10K.toString ()
532- << std::endl;
533- std::cout << " Exchange: " << exchangeStatsFlat10K.toString () << std::endl;
534-
535- std::cout
536- << " ----------------------------------Flat50K----------------------------------"
537- << std::endl;
538- std::cout << " Wall Time (ms): " << succinctMicros (flat50KWallUs) << std::endl;
539- std::cout << " PartitionOutput: " << partitionedOutputStatsFlat50.toString ()
540- << std::endl;
541- std::cout << " Exchange: " << exchangeStatsFlat10K.toString () << std::endl;
542-
543- std::cout
544- << " ----------------------------------Deep10K----------------------------------"
545- << std::endl;
546- std::cout << " Wall Time (ms): " << succinctMicros (deep10KWallUs) << std::endl;
547- std::cout << " PartitionOutput: " << partitionedOutputStatsDeep10K.toString ()
548- << std::endl;
549- std::cout << " Exchange: " << exchangeStatsDeep10K.toString () << std::endl;
550-
551- std::cout
552- << " ----------------------------------Deep50K----------------------------------"
553- << std::endl;
554- std::cout << " Wall Time (ms): " << succinctMicros (deep50KWallUs) << std::endl;
555- std::cout << " PartitionOutput: " << partitionedOutputStatsDeep50.toString ()
556- << std::endl;
557- std::cout << " Exchange: " << exchangeStatsDeep50.toString () << std::endl;
558-
559- std::cout
560- << " ----------------------------------Struct1K---------------------------------"
561- << std::endl;
562- std::cout << " Wall Time (ms): " << succinctMicros (stuct1KWallUs) << std::endl;
563- std::cout << " PartitionOutput: " << partitionedOutputStatsStruct1K.toString ()
564- << std::endl;
565- std::cout << " Exchange: " << exchangeStatsStruct1K.toString () << std::endl;
522+ for (size_t i = 0 ; i < exchangeCases.size (); ++i) {
523+ printExchangeStats (
524+ exchangeCases[i].first , " normal" , normalPartitionedOutputStats[i]);
525+ if (optimizedPartitionedOutputEnabled) {
526+ printExchangeStats (
527+ exchangeCases[i].first ,
528+ " optimized" ,
529+ optimizedPartitionedOutputStats[i]);
530+ }
531+ }
566532
567533 std::cout
568534 << " --------------------------------LocalFlat10K-------------------------------"
0 commit comments