Skip to content

Conversation

@Xiaoccer
Copy link
Contributor

Proposed changes

Issue Number: close #xxx

Problem summary

Add bthread to separate the logic of IO and computation when executing the OlapScanner, which can speed up to access those sql that are already cached.

  • In OlapScanner's execution chain, change std::mutex/std::condition_variable to bthread::Mutex/bthread::ConditionVariable
  • Add class of AsyncIO to separate task from bthread to pthread
  • Change the usage of reader's/filesytem's interface when using bthread

Performance test

  • 1be+1fe
  • base: commit_id-bd2280b4ce702e24cc31ca1d379aeaf6f00ce69c

ssbf100 benchmark

sql base(s) bthread(s)
q1.1 0.92 0.904
q1.2 1.122 1.126
q1.3 0.052 0.052
q2.1 12.041 12.072
q2.2 0.741 0.705
q2.3 0.635 0.671
q3.1 3.492 3.422
q3.2 0.46 0.47
q3.3 0.649 0.679
q3.4 0.089 0.087
q4.1 4.358 4.685
q4.2 0.519 0.572
q4.3 0.457 0.463

The performance of using bthread and using pthread is almost the same.

cached read

Description: First execute q1.1.sql to cache data, and then execute q1.1.sql、q2.1.sql and q4.1.sql concurrently.

sql base(s) bthread(s)
first time q1.1 2.673 2.721
second time (cached) q1.1 13.441 0.206
first time q2.1 53.846 53.793
first time q4.1 53.864 53.903

When using bthread, If the data of sql has been cached, the result of sql can be returned fast without waiting the free thread of thread pool.

Checklist(Required)

  1. Does it affect the original behavior:
    • Yes
    • No
    • I don't know
  2. Has unit tests been added:
    • Yes
    • No
    • No Need
  3. Has document been added or modified:
    • Yes
    • No
    • No Need
  4. Does it need to update dependencies:
    • Yes
    • No
  5. Are there any changes that cannot be rolled back:
    • Yes (If Yes, please explain WHY)
    • No

Further comments

If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...

@github-actions
Copy link
Contributor

sh-checker report

To get the full details, please check in the job output.

shellcheck errors

'shellcheck ' returned error 1 finding the following syntactical issues:

----------

In build.sh line 428:
	-DUSE_BTHREAD_SCANNER=${USE_BTHREAD_SCANNER} \
                              ^--------------------^ SC2248 (style): Prefer double quoting even when variables don't contain special characters.

Did you mean: 
	-DUSE_BTHREAD_SCANNER="${USE_BTHREAD_SCANNER}" \

For more information:
  https://www.shellcheck.net/wiki/SC2248 -- Prefer double quoting even when v...
----------

You can address the above issues in one of three ways:
1. Manually correct the issue in the offending shell script;
2. Disable specific issues by adding the comment:
  # shellcheck disable=NNNN
above the line that contains the issue, where NNNN is the error code;
3. Add '-e NNNN' to the SHELLCHECK_OPTS setting in your .yml action file.



shfmt errors

'shfmt ' returned error 1 finding the following formatting issues:

----------
--- build.sh.orig
+++ build.sh
@@ -425,7 +425,7 @@
         -DUSE_DWARF="${USE_DWARF}" \
         -DUSE_MEM_TRACKER="${USE_MEM_TRACKER}" \
         -DUSE_JEMALLOC="${USE_JEMALLOC}" \
-	-DUSE_BTHREAD_SCANNER=${USE_BTHREAD_SCANNER} \
+        -DUSE_BTHREAD_SCANNER=${USE_BTHREAD_SCANNER} \
         -DSTRICT_MEMORY_USE="${STRICT_MEMORY_USE}" \
         -DENABLE_STACKTRACE="${ENABLE_STACKTRACE}" \
         -DUSE_AVX2="${USE_AVX2}" \
----------

You can reformat the above files to meet shfmt's requirements by typing:

  shfmt  -w filename


Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

PriorityThreadPool* _io_thread_pool = nullptr;
PriorityThreadPool* _remote_thread_pool = nullptr;

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]

Suggested change
private:

be/src/util/async_io.h:79: previously declared here

private:
^

if (!_has_called.load(std::memory_order_acquire)) {
do {
std::lock_guard l(_mutex);
if (_has_called.load(std::memory_order_acquire)) break;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: statement should be inside braces [readability-braces-around-statements]

Suggested change
if (_has_called.load(std::memory_order_acquire)) break;
if (_has_called.load(std::memory_order_acquire)) { break;
}

// Blocks until the work queue is empty, and then calls shutdown to stop the worker
// threads and Join to wait until they are finished.
// Any work Offer()'ed during DrainAndshutdown may or may not be processed.
void drain_and_shutdown() override {
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: only virtual member functions can be marked 'override' [clang-diagnostic-error]

Suggested change
void drain_and_shutdown() override {
void drain_and_shutdown() {

void drain_and_shutdown() override {
{
std::unique_lock<std::mutex> l(_lock);
std::unique_lock l(_lock);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier '_lock'; did you mean 'clock'? [clang-diagnostic-error]

Suggested change
std::unique_lock l(_lock);
std::unique_lock l(clock);

/usr/include/time.h:71: 'clock' declared here

extern clock_t clock (void) __THROW;
               ^

std::unique_lock<std::mutex> l(_lock);
std::unique_lock l(_lock);
while (get_queue_size() != 0) {
_empty_cv.wait(l);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier '_empty_cv' [clang-diagnostic-error]

                _empty_cv.wait(l);
                ^

@hello-stephen
Copy link
Contributor

hello-stephen commented Jan 17, 2023

TeamCity pipeline, clickbench performance test result:
the sum of best hot time: 34.89 seconds
load time: 469 seconds
storage size: 17171040497 Bytes
https://doris-community-test-1308700295.cos.ap-hongkong.myqcloud.com/tmp/20230208044414_clickbench_pr_91881.html

@adonis0147 adonis0147 closed this Jan 18, 2023
@adonis0147 adonis0147 reopened this Jan 18, 2023
@github-actions
Copy link
Contributor

sh-checker report

To get the full details, please check in the job output.

shellcheck errors

'shellcheck ' returned error 1 finding the following syntactical issues:

----------

In build.sh line 428:
	-DUSE_BTHREAD_SCANNER=${USE_BTHREAD_SCANNER} \
                              ^--------------------^ SC2248 (style): Prefer double quoting even when variables don't contain special characters.

Did you mean: 
	-DUSE_BTHREAD_SCANNER="${USE_BTHREAD_SCANNER}" \

For more information:
  https://www.shellcheck.net/wiki/SC2248 -- Prefer double quoting even when v...
----------

You can address the above issues in one of three ways:
1. Manually correct the issue in the offending shell script;
2. Disable specific issues by adding the comment:
  # shellcheck disable=NNNN
above the line that contains the issue, where NNNN is the error code;
3. Add '-e NNNN' to the SHELLCHECK_OPTS setting in your .yml action file.



shfmt errors

'shfmt ' returned error 1 finding the following formatting issues:

----------
--- build.sh.orig
+++ build.sh
@@ -425,7 +425,7 @@
         -DUSE_DWARF="${USE_DWARF}" \
         -DUSE_MEM_TRACKER="${USE_MEM_TRACKER}" \
         -DUSE_JEMALLOC="${USE_JEMALLOC}" \
-	-DUSE_BTHREAD_SCANNER=${USE_BTHREAD_SCANNER} \
+        -DUSE_BTHREAD_SCANNER=${USE_BTHREAD_SCANNER} \
         -DSTRICT_MEMORY_USE="${STRICT_MEMORY_USE}" \
         -DENABLE_STACKTRACE="${ENABLE_STACKTRACE}" \
         -DUSE_AVX2="${USE_AVX2}" \
----------

You can reformat the above files to meet shfmt's requirements by typing:

  shfmt  -w filename


@gavinchou
Copy link
Contributor

LGTM

Copy link
Contributor

@gavinchou gavinchou left a comment

Choose a reason for hiding this comment

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

LGTM

gavinchou
gavinchou previously approved these changes Feb 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2023

sh-checker report

To get the full details, please check in the job output.

shellcheck errors
'shellcheck ' found no issues.

shfmt errors

'shfmt ' returned error 1 finding the following formatting issues:

----------
--- build.sh.orig
+++ build.sh
@@ -426,7 +426,7 @@
         -DUSE_DWARF="${USE_DWARF}" \
         -DUSE_MEM_TRACKER="${USE_MEM_TRACKER}" \
         -DUSE_JEMALLOC="${USE_JEMALLOC}" \
-	-DUSE_BTHREAD_SCANNER="${USE_BTHREAD_SCANNER}" \
+        -DUSE_BTHREAD_SCANNER="${USE_BTHREAD_SCANNER}" \
         -DSTRICT_MEMORY_USE="${STRICT_MEMORY_USE}" \
         -DENABLE_STACKTRACE="${ENABLE_STACKTRACE}" \
         -DUSE_AVX2="${USE_AVX2}" \
----------

You can reformat the above files to meet shfmt's requirements by typing:

  shfmt  -w filename


Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

static FileSystemMap* instance();
~FileSystemMap() = default;

void insert(ResourceId id, FileSystemSPtr fs);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unknown type name 'ResourceId' [clang-diagnostic-error]

    void insert(ResourceId id, FileSystemSPtr fs);
                ^

void insert(ResourceId id, FileSystemSPtr fs);

// If `id` is not in `_map`, return nullptr.
FileSystemSPtr get(const ResourceId& id);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: unknown type name 'ResourceId' [clang-diagnostic-error]

    FileSystemSPtr get(const ResourceId& id);
                             ^

private:
FileSystemMap() = default;

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]

Suggested change
private:

be/src/io/fs/file_system_map.h:39: previously declared here

private:
^


private:
doris::SharedMutex _mu;
std::unordered_map<ResourceId, FileSystemSPtr> _map; // GUARED_BY(_mu)
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: use of undeclared identifier 'ResourceId' [clang-diagnostic-error]

    std::unordered_map<ResourceId, FileSystemSPtr> _map; // GUARED_BY(_mu)
                       ^

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

PriorityThreadPool* _io_thread_pool = nullptr;
PriorityThreadPool* _remote_thread_pool = nullptr;

private:
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: redundant access specifier has the same accessibility as the previous access specifier [readability-redundant-access-specifiers]

Suggested change
private:

be/src/util/async_io.h:96: previously declared here

private:
^

@github-actions
Copy link
Contributor

github-actions bot commented Feb 8, 2023

PR approved by anyone and no changes requested.

Copy link
Contributor

@dataroaring dataroaring left a comment

Choose a reason for hiding this comment

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

LGTM

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Feb 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2023

PR approved by at least one committer and no changes requested.

@dataroaring dataroaring merged commit 0142ef8 into apache:master Feb 9, 2023
YangShaw pushed a commit to YangShaw/doris that referenced this pull request Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. area/vectorization dev/1.2.2 reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants