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

Create pool based schedulers: IO and Computation #301

Open
victimsnino opened this issue Dec 1, 2022 · 5 comments
Open

Create pool based schedulers: IO and Computation #301

victimsnino opened this issue Dec 1, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@victimsnino
Copy link
Owner

No description provided.

@victimsnino victimsnino added the enhancement New feature or request label Dec 1, 2022
@victimsnino victimsnino changed the title Create pool based schedulers: IO and Comptation Create pool based schedulers: IO and Computation Dec 2, 2022
@RobinQu
Copy link

RobinQu commented Apr 18, 2024

+1, right now I have to write something cumbersome like:

https://github.com/RobinQu/instinct.cpp/blob/sprint/v0.1.1/modules/instinct-retrieval/include/retrieval/MultiVectorRetriever.hpp

void Ingest(const AsyncIterator<Document>& input) override {
            static int BUFFER_SIZE = 10;
            static ThreadPool WORKER_POOL;

            Futures<void> tasks;
            input
            | rpp::operators::as_blocking()
            | rpp::operators::subscribe([&](const Document& parent_doc) {
                auto f = WORKER_POOL.submit_task([&,parent_doc]() {
                    Document copied_doc = parent_doc;
                    doc_store_->AddDocument(copied_doc);
                    auto sub_docs = std::invoke(guidance_, copied_doc);
                        LOG_DEBUG("{} guidance doc(s) generated for parent doc with id {}", sub_docs.size(), copied_doc.id());
                    UpdateResult update_result;
                    vector_store_->AddDocuments(sub_docs, update_result);
                    assert_true(update_result.failed_documents_size()==0, "all sub docs should be inserted successfully");
                });
                tasks.push_back(std::move(f));
            });

            tasks.wait();
        }
    };

PS: ThreadPool and Futures are aliases to BS::thread_pool and [BS::multi_future<T> in bshoshany/thread-pool

@victimsnino
Copy link
Owner Author

@RobinQu , added local-based thread_pool + global computational scheduler. Is it what you've exptected?

@RobinQu
Copy link

RobinQu commented Apr 22, 2024

@RobinQu , added local-based thread_pool + global computational scheduler. Is it what you've exptected?

I think it's a yes.

Thanks for you quick response. it's good enough for common IO-bound tasks.

@victimsnino
Copy link
Owner Author

@RobinQu , added local-based thread_pool + global computational scheduler. Is it what you've exptected?

I think it's a yes.

Thanks for you quick response. it's good enough for common IO-bound tasks.

You are welcome.

BTW: I've seen your another point in email notification: to have some specific background thread to schedule background job you can use thread_pool(1) as global/static variable and schedule all necessary things to it :)

@RobinQu
Copy link

RobinQu commented Apr 23, 2024

BTW: I've seen your another point in email notification: to have some specific background thread to schedule background job you can use thread_pool(1) as global/static variable and schedule all necessary things to it :)

Yes indeed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants