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

feat(streaming): use tokio channels and better coop scheduling #3374

Merged
merged 6 commits into from
Jun 21, 2022

Conversation

skyzh
Copy link
Contributor

@skyzh skyzh commented Jun 21, 2022

Signed-off-by: Alex Chi iskyzh@gmail.com

What's changed and what's your intention?

  • This PR enables unstable feature of tokio, so that we can use budget APIs.
  • Replace all channels to tokio channels so that they can opt in schedule budgets.
  • SSTableIterator will account for one budget when seek.

metrics looks good:

image

Checklist

  • I have written necessary docs and comments
  • I have added necessary unit tests and integration tests
  • All checks passed in ./risedev check (or alias, ./risedev c)

Refer to a related PR or issue link (optional)

@skyzh
Copy link
Contributor Author

skyzh commented Jun 21, 2022

The bench command can now yield normally.

image

@codecov
Copy link

codecov bot commented Jun 21, 2022

Codecov Report

Merging #3374 (270d72e) into main (4b33d95) will decrease coverage by 0.00%.
The diff coverage is 79.16%.

@@            Coverage Diff             @@
##             main    #3374      +/-   ##
==========================================
- Coverage   73.63%   73.63%   -0.01%     
==========================================
  Files         760      760              
  Lines      104229   104231       +2     
==========================================
  Hits        76754    76754              
- Misses      27475    27477       +2     
Flag Coverage Δ
rust 73.63% <79.16%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/compute/src/rpc/service/exchange_service.rs 0.00% <0.00%> (ø)
src/ctl/src/cmd_impl/bench.rs 0.00% <ø> (ø)
src/risedevtool/src/bin/risedev-compose.rs 0.43% <0.00%> (-0.01%) ⬇️
src/storage/src/hummock/sstable_store.rs 83.03% <ø> (-0.71%) ⬇️
src/stream/src/task/mod.rs 43.75% <ø> (ø)
src/stream/src/task/stream_manager.rs 0.00% <0.00%> (ø)
src/common/src/cache.rs 96.73% <100.00%> (ø)
...ge/src/hummock/sstable/forward_sstable_iterator.rs 95.12% <100.00%> (+0.51%) ⬆️
src/stream/src/executor/dispatch.rs 76.94% <100.00%> (ø)
src/stream/src/executor/integration_tests.rs 98.40% <100.00%> (-0.54%) ⬇️
... and 10 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
@skyzh skyzh marked this pull request as ready for review June 21, 2022 08:08
@skyzh
Copy link
Contributor Author

skyzh commented Jun 21, 2022

Also benchmark shows that the state table layer can scan 50000 rows/s per core, which is about 500000 KV/s.

image

Which looks (maybe) reasonable?

// When all data are in block cache, it is highly possible that this iterator will stay on a
// worker thread for a full time. Therefore, we use tokio's unstable API consume_budget to
// do cooperative scheduling.
tokio::task::consume_budget().await;
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a way we can achieve something similar without tokio unstable? Maybe we could simply yield when idx % YIELD_ITERATIONS == 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but it won't share the budget with tokio channels / semaphores. I think it would be better if we have a single budget for all related events :)

@@ -136,7 +137,7 @@ pub async fn cooperative_scheduling<T>(stream: impl Stream<Item = T>) {
#[for_await]
for item in stream {
yield item;
tokio::task::yield_now().await;
// tokio::task::consume_budget().await;
Copy link
Contributor

Choose a reason for hiding this comment

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

similar comment here

@jon-chuang
Copy link
Contributor

Quite curious if this has been benchmarked on the hash join?

@skyzh
Copy link
Contributor Author

skyzh commented Jun 21, 2022

Yes, still no significant improvement.

@skyzh skyzh requested a review from BugenZhao June 21, 2022 10:53
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
@skyzh skyzh added the mergify/can-merge Indicates that the PR can be added to the merge queue label Jun 21, 2022
@mergify mergify bot merged commit bc74ff4 into main Jun 21, 2022
@mergify mergify bot deleted the skyzh/use-tokio-channel branch June 21, 2022 14:59
cnissnzg added a commit that referenced this pull request Jun 22, 2022
commit aac69d2
Author: William Wen <44139337+wenym1@users.noreply.github.com>
Date:   Wed Jun 22 17:23:31 2022 +0800

    fix(storage): fix ignoring delete record when getting from sst (#3405)

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit ebfbd0c
Author: Alex Chi <iskyzh@gmail.com>
Date:   Wed Jun 22 17:01:53 2022 +0800

    chore(storage): move read lock acquire out of lock (#3400)

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit c5b4fe2
Author: lmatz <lmatz823@gmail.com>
Date:   Wed Jun 22 01:49:23 2022 -0700

    fix(expr): trim (#3402)

commit 28cf5ff
Author: Wallace <bupt2013211450@gmail.com>
Date:   Wed Jun 22 16:29:03 2022 +0800

    feat(compaction): compress data with dynamic level (#3388)

    * do not compress data in high level

    Signed-off-by: Little-Wallace <bupt2013211450@gmail.com>

commit 7602285
Author: Lee Zong Yu <65748142+marvenlee2486@users.noreply.github.com>
Date:   Wed Jun 22 15:58:31 2022 +0800

    fix(grafana): Edit update.sh (#3399)

    * Edit update.sh

    * Edit format error

    * Add payload to gitignore

    * Revert risedev.yml modification

    * Fix wrong gitignore

    * Fix wrong gitignore

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 4e66ca3
Author: congyi <58715567+wcy-fdu@users.noreply.github.com>
Date:   Wed Jun 22 13:16:48 2022 +0800

    feat(docs): add docs for the relational table layer (#3313)

    * add doc for relational layer

commit 7c44a15
Author: Bugen Zhao <i@bugenzhao.com>
Date:   Wed Jun 22 12:51:59 2022 +0800

    fix: build failure of cell based table with release profile (#3395)

commit 93c62a3
Author: Li0k <yuli@singularity-data.com>
Date:   Wed Jun 22 11:50:18 2022 +0800

    chore(frontend): fix handle_with_properties ctx of explain (#3394)

commit 233ee5d
Author: Li0k <yuli@singularity-data.com>
Date:   Wed Jun 22 11:32:05 2022 +0800

    feat(frontend): catalog add properties for ttl (#3382)

    * feat(frontend): catlog add properties for materialized_view and materialized_source to support ttl

    * fix(frontend): fix test_runner

    * chore(frontend): unify handle_with_properties logic for handler

    * chore(frontend): explain introduce handle_with_properties to replace WithProperties

    * chore(sqlparser): remove unused logic of WithProperties

commit 78861e3
Author: Bugen Zhao <i@bugenzhao.com>
Date:   Wed Jun 22 02:19:37 2022 +0800

    feat(storage): store all column descs in cell based table (#3344)

    * add pk indices

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * extract mapping

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * distinguish parital table

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * refactor proto

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * fix clippy

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * fix output schema

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * store column ids in serializer

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * refine docs

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * fix plan test

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * refine docs

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * write check

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * Apply suggestions from code review

    Co-authored-by: Yuanxin Cao <60498509+xx01cyx@users.noreply.github.com>

    * trigger ci

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    Co-authored-by: Yuanxin Cao <60498509+xx01cyx@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit bc74ff4
Author: Alex Chi <iskyzh@gmail.com>
Date:   Tue Jun 21 22:59:22 2022 +0800

    feat(streaming): use tokio channels and better coop scheduling (#3374)

    * feat(streaming): use tokio channels and better coop scheduling

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * more info when deploy

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * remove manual coop scheduling

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

commit 4b33d95
Author: Huangjw <1223644280@qq.com>
Date:   Tue Jun 21 18:32:36 2022 +0800

    chore(ci): update ci image vesion and remove changelog.json (#3384)

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit ed1de15
Author: Alex Chi <iskyzh@gmail.com>
Date:   Tue Jun 21 18:19:02 2022 +0800

    feat(risedev): fix meta args and support healthcheck in docker (#3378)

    * feat(risedev): support healthcheck in docker

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * pin version

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 5a7e115
Author: Alex Chi <iskyzh@gmail.com>
Date:   Tue Jun 21 18:05:56 2022 +0800

    chore(ci): manual CLA check (#3386)

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

commit 2688491
Author: ZENOTME <43447882+ZENOTME@users.noreply.github.com>
Date:   Tue Jun 21 18:03:02 2022 +0800

    feat(pgwire): support row limit in extended query mode (#3354)

    * * add row_end flag in PgResponse
    * add values interface in PgResponse

    * * add result_cache
    * add execute interface

    * fix complile error of row_end

    * * split process_query_msg into process_query_msg_simple and process_query_response

    execute flow:

    simple mode:                        extended query mode:
    process_query_msg_simple              portal.execute()
        |   (response)             (response)  |
    process_query_response ---------------------
        |
    process_query_with_results

    * fix clippy

    * add process at Execute

    * add PortalSuspended msg

    * add row_limit process at process_query_with_results

    * fix small problem and add some comment

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit dc8631e
Author: Tao Wu <wutao@singularity-data.com>
Date:   Tue Jun 21 17:35:36 2022 +0800

    test: sqlsmith supports generating unary func (#3370)

commit cb0d7c1
Author: Bowen <36908971+BowenXiao1999@users.noreply.github.com>
Date:   Tue Jun 21 17:16:10 2022 +0800

    refactor: deparallel hash agg apply batch + remove Arc Mutex (#3377)

    * refactor: deparallel hash agg apply batch

    * remove Arc Mutex

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
mergify bot pushed a commit that referenced this pull request Jun 27, 2022
…3363)

* implement cascade && restrict by add relation map

* fmt

* implement cascade && restrict by add relation map

* fmt

* correct pre unit test error

* correct misc test error

* fix

* update proto && fix

* change grantor to granted by

* implement recursive privilege relations && fix

* Squashed commit of the following:

commit aac69d2
Author: William Wen <44139337+wenym1@users.noreply.github.com>
Date:   Wed Jun 22 17:23:31 2022 +0800

    fix(storage): fix ignoring delete record when getting from sst (#3405)

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit ebfbd0c
Author: Alex Chi <iskyzh@gmail.com>
Date:   Wed Jun 22 17:01:53 2022 +0800

    chore(storage): move read lock acquire out of lock (#3400)

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit c5b4fe2
Author: lmatz <lmatz823@gmail.com>
Date:   Wed Jun 22 01:49:23 2022 -0700

    fix(expr): trim (#3402)

commit 28cf5ff
Author: Wallace <bupt2013211450@gmail.com>
Date:   Wed Jun 22 16:29:03 2022 +0800

    feat(compaction): compress data with dynamic level (#3388)

    * do not compress data in high level

    Signed-off-by: Little-Wallace <bupt2013211450@gmail.com>

commit 7602285
Author: Lee Zong Yu <65748142+marvenlee2486@users.noreply.github.com>
Date:   Wed Jun 22 15:58:31 2022 +0800

    fix(grafana): Edit update.sh (#3399)

    * Edit update.sh

    * Edit format error

    * Add payload to gitignore

    * Revert risedev.yml modification

    * Fix wrong gitignore

    * Fix wrong gitignore

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 4e66ca3
Author: congyi <58715567+wcy-fdu@users.noreply.github.com>
Date:   Wed Jun 22 13:16:48 2022 +0800

    feat(docs): add docs for the relational table layer (#3313)

    * add doc for relational layer

commit 7c44a15
Author: Bugen Zhao <i@bugenzhao.com>
Date:   Wed Jun 22 12:51:59 2022 +0800

    fix: build failure of cell based table with release profile (#3395)

commit 93c62a3
Author: Li0k <yuli@singularity-data.com>
Date:   Wed Jun 22 11:50:18 2022 +0800

    chore(frontend): fix handle_with_properties ctx of explain (#3394)

commit 233ee5d
Author: Li0k <yuli@singularity-data.com>
Date:   Wed Jun 22 11:32:05 2022 +0800

    feat(frontend): catalog add properties for ttl (#3382)

    * feat(frontend): catlog add properties for materialized_view and materialized_source to support ttl

    * fix(frontend): fix test_runner

    * chore(frontend): unify handle_with_properties logic for handler

    * chore(frontend): explain introduce handle_with_properties to replace WithProperties

    * chore(sqlparser): remove unused logic of WithProperties

commit 78861e3
Author: Bugen Zhao <i@bugenzhao.com>
Date:   Wed Jun 22 02:19:37 2022 +0800

    feat(storage): store all column descs in cell based table (#3344)

    * add pk indices

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * extract mapping

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * distinguish parital table

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * refactor proto

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * fix clippy

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * fix output schema

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * store column ids in serializer

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * refine docs

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * fix plan test

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * refine docs

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * write check

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    * Apply suggestions from code review

    Co-authored-by: Yuanxin Cao <60498509+xx01cyx@users.noreply.github.com>

    * trigger ci

    Signed-off-by: Bugen Zhao <i@bugenzhao.com>

    Co-authored-by: Yuanxin Cao <60498509+xx01cyx@users.noreply.github.com>
    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit bc74ff4
Author: Alex Chi <iskyzh@gmail.com>
Date:   Tue Jun 21 22:59:22 2022 +0800

    feat(streaming): use tokio channels and better coop scheduling (#3374)

    * feat(streaming): use tokio channels and better coop scheduling

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * more info when deploy

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * remove manual coop scheduling

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

commit 4b33d95
Author: Huangjw <1223644280@qq.com>
Date:   Tue Jun 21 18:32:36 2022 +0800

    chore(ci): update ci image vesion and remove changelog.json (#3384)

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit ed1de15
Author: Alex Chi <iskyzh@gmail.com>
Date:   Tue Jun 21 18:19:02 2022 +0800

    feat(risedev): fix meta args and support healthcheck in docker (#3378)

    * feat(risedev): support healthcheck in docker

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * fix

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    * pin version

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit 5a7e115
Author: Alex Chi <iskyzh@gmail.com>
Date:   Tue Jun 21 18:05:56 2022 +0800

    chore(ci): manual CLA check (#3386)

    Signed-off-by: Alex Chi <iskyzh@gmail.com>

commit 2688491
Author: ZENOTME <43447882+ZENOTME@users.noreply.github.com>
Date:   Tue Jun 21 18:03:02 2022 +0800

    feat(pgwire): support row limit in extended query mode (#3354)

    * * add row_end flag in PgResponse
    * add values interface in PgResponse

    * * add result_cache
    * add execute interface

    * fix complile error of row_end

    * * split process_query_msg into process_query_msg_simple and process_query_response

    execute flow:

    simple mode:                        extended query mode:
    process_query_msg_simple              portal.execute()
        |   (response)             (response)  |
    process_query_response ---------------------
        |
    process_query_with_results

    * fix clippy

    * add process at Execute

    * add PortalSuspended msg

    * add row_limit process at process_query_with_results

    * fix small problem and add some comment

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

commit dc8631e
Author: Tao Wu <wutao@singularity-data.com>
Date:   Tue Jun 21 17:35:36 2022 +0800

    test: sqlsmith supports generating unary func (#3370)

commit cb0d7c1
Author: Bowen <36908971+BowenXiao1999@users.noreply.github.com>
Date:   Tue Jun 21 17:16:10 2022 +0800

    refactor: deparallel hash agg apply batch + remove Arc Mutex (#3377)

    * refactor: deparallel hash agg apply batch

    * remove Arc Mutex

    Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>

* add unit test

* fmt

* correct pre test

* some fix

Co-authored-by: August <pin@singularity-data.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergify/can-merge Indicates that the PR can be added to the merge queue type/feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants