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

parallelization of simple query #132

Merged
merged 1 commit into from
Nov 27, 2024
Merged

Conversation

YoshiakiNishimura
Copy link
Contributor

https://github.com/project-tsurugi/tsurugi-issues/issues/991

scan_default_parallelの値でscanのrangeを分割する

@YoshiakiNishimura YoshiakiNishimura force-pushed the parallel_simple_query branch 3 times, most recently from e2a85cd to f987122 Compare November 25, 2024 10:28
@YoshiakiNishimura YoshiakiNishimura marked this pull request as ready for review November 25, 2024 10:45
begin.key(), begin.endpointkind(), end.key(), end.endpointkind());
auto pivot_count = scan_parallel_count - 1;
auto pivots = distribution.compute_pivots(pivot_count, range);
bounds.emplace_back(std::move(begin));
Copy link
Contributor

Choose a reason for hiding this comment

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

boundsに対するemplace_backを行う前にstd::vector::reserveを呼んであらかじめ必要な領域を確保してください。

}
} else {
bounds.emplace_back(std::move(begin));
}
bounds.emplace_back(std::move(end));
for (size_t i = 0; i + 1 < bounds.size(); i += 2) {
scan_ranges.emplace_back(std::make_shared<impl::scan_range>(
Copy link
Contributor

Choose a reason for hiding this comment

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

for文の前にstd::vector::reserveしてください。

size_t scan_parallel_count = global::config_pool()->scan_default_parallel();
auto option = request_context_->transaction()->option();
bool is_rtx = option && option->type() == kvs::transaction_option::transaction_type::read_only;
if (scan_parallel_count > 1 && is_rtx) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is_empty=trueの場合はそもそも分割が必要ないのでこのif文に入らないようにした方がいいですね。

Copy link
Contributor

Choose a reason for hiding this comment

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

configuration::rtx_parallel_scan=trueかどうかの確認も必要ではないでしょうか。

auto pivot_count = scan_parallel_count - 1;
auto pivots = distribution.compute_pivots(pivot_count, range);
bounds.emplace_back(std::move(begin));
for (const auto& pivot : pivots) {
Copy link
Contributor

Choose a reason for hiding this comment

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

L.420のfor文でboundsを作成し、その内容を L.430で2個ずつ取り出して最終的なscan_rangesを作っています。
好みの問題に近いですが、 L.420のfor文で直接scan_rangesまで作ってしまった方がシンプルではないでしょうか。

Copy link
Contributor

@kuron99 kuron99 left a comment

Choose a reason for hiding this comment

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

レビューしました。指摘部分対応後にマージしてOKです。

@YoshiakiNishimura
Copy link
Contributor Author

YoshiakiNishimura commented Nov 26, 2024

@kuron99 テスト中に問題見つけました。

pivotとして81 ffが選択されても

bound(kvs::end_point_kind::exclusive, pivots.front().size(),
                    std::make_unique<data::aligned_buffer>(pivots.front())),
                is_empty));

boundに入れると 20 00になってます。結果不正が起きているので調査します

  bound:
    endpointkind_: exclusive
    len_: 2
    key_:  size: 2 capacity: 2 alignment: 1 data: 20-00
    aligned_buffer:
      capacity_: 2
      alignment_: 1
      size_: 2
      data_: 20 00

@kuron99
Copy link
Contributor

kuron99 commented Nov 26, 2024

@YoshiakiNishimura simple_key_distribution::compute_pivotsが戻しているstd::string_viewってローカルに確保されたstd::string (L.41)のものなので作成後に書きかわってしまうとかでしょうか?

pivots.emplace_back(pivot);

@YoshiakiNishimura
Copy link
Contributor Author

YoshiakiNishimura commented Nov 26, 2024

@kuron99 std::vector<simple_key_distribution::pivot_type> ->std::vectorstd::stringで試してみます。(この場合コピーが発生して問題なく動作すると思います)

@YoshiakiNishimura
Copy link
Contributor Author

@kuron99

問題対応 & 指摘反映しましたのでmergeします

@YoshiakiNishimura YoshiakiNishimura merged commit 873a72a into master Nov 27, 2024
10 checks passed
@YoshiakiNishimura YoshiakiNishimura deleted the parallel_simple_query branch November 27, 2024 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants