You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "joemarshall (via GitHub)" <gi...@apache.org> on 2023/05/18 14:44:42 UTC
[GitHub] [arrow] joemarshall opened a new pull request, #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
joemarshall opened a new pull request, #35672:
URL: https://github.com/apache/arrow/pull/35672
<!--
Thanks for opening a pull request!
If this is your first pull request you can find detailed information on how
to contribute here:
* [New Contributor's Guide](https://arrow.apache.org/docs/dev/developers/guide/step_by_step/pr_lifecycle.html#reviews-and-merge-of-the-pull-request)
* [Contributing Overview](https://arrow.apache.org/docs/dev/developers/overview.html)
If this is not a [minor PR](https://github.com/apache/arrow/blob/main/CONTRIBUTING.md#Minor-Fixes). Could you open an issue for this pull request on GitHub? https://github.com/apache/arrow/issues/new/choose
Opening GitHub issues ahead of time contributes to the [Openness](http://theapacheway.com/open/#:~:text=Openness%20allows%20new%20users%20the,must%20happen%20in%20the%20open.) of the Apache Arrow project.
Then could you also rename the pull request title in the following format?
GH-${GITHUB_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
or
MINOR: [${COMPONENT}] ${SUMMARY}
In the case of PARQUET issues on JIRA the title also supports:
PARQUET-${JIRA_ISSUE_ID}: [${COMPONENT}] ${SUMMARY}
-->
### Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
### What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
### Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
### Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please uncomment the line below and explain which changes are breaking.
-->
<!-- **This PR includes breaking changes to public APIs.** -->
<!--
Please uncomment the line below (and provide explanation) if the changes fix either (a) a security vulnerability, (b) a bug that caused incorrect or invalid data to be produced, or (c) a bug that causes a crash (even when the API contract is upheld). We use this to highlight fixes to issues that may affect users without their knowledge. For this reason, fixing bugs that cause errors don't count, since those are usually obvious.
-->
<!-- **This PR contains a "Critical Fix".** -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1662218137
@kou - I've done those tidying up fixes (use of auto, extraneous return statements etc.)
Those two test cases that you flagged, I checked through them again, and I think I was wrong - they probably don't really make sense in single-threaded mode as they're testing essentially multithreaded behaviour. I've just skipped those tests in single threaded mode.
The description at the top of the PR is up to date now (and has a brief changelog of what changed from initial PR), so hopefully good to go.
thanks
Joe
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1580983435
@kou - I did a couple of things on this - firstly I fixed most of those comments you had (and added comments where I think things might not need fixing). Secondly, I ran a build in arm64 on oracle cloud, and the test that failed in CI works just fine on there, so maybe that is just a fluke.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1570308482
@kou - I think I've squashed everything now, hopefully ready to merge and then I can put in the emscripten/webassembly cmake settings as another PR
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1203860528
##########
cpp/cmake_modules/ThirdpartyToolchain.cmake:
##########
@@ -5190,4 +5190,4 @@ message(STATUS "All bundled static libraries: ${ARROW_BUNDLED_STATIC_LIBS}")
configure_file("src/arrow/util/config.h.cmake" "src/arrow/util/config.h" ESCAPE_QUOTES)
install(FILES "${ARROW_BINARY_DIR}/src/arrow/util/config.h"
- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/arrow/util")
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/arrow/util")
Review Comment:
oops done now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1652272915
@kou any concerns?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1263784736
##########
cpp/src/arrow/util/future.cc:
##########
@@ -149,17 +150,39 @@ class ConcreteFutureImpl : public FutureImpl {
}
void DoWait() {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return IsFutureFinished(state_); });
+#else
+ while (true) {
+ if (IsFutureFinished(state_)) {
+ return;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
Review Comment:
I've put a warning in if it waits in here too long
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1239677898
##########
cpp/src/arrow/util/thread_pool.h:
##########
@@ -194,6 +196,11 @@ class ARROW_EXPORT Executor {
// Executor. Returns false if this Executor does not support this property.
virtual bool OwnsThisThread() { return false; }
+ // Return true if this is the current executor being called
+ // n.b. this defaults to just calling OwnsThisThread
+ // unless the threadpool is disabled
+ virtual bool IsCurrentExecutor() { return OwnsThisThread(); }
Review Comment:
It's because in threading disabled mode, there can be multiple nested executors running, with one executor waiting on another. OwnsThisThread assumes that each executor has a thread, and uses the thread id to check if the code is running under one particular executor, which doesn't work without threads.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1275675227
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1051,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
+ arrow::internal::Executor* executor, Future<> future) {
+ if (unlocked_) {
+ num_finished_++;
+ future.MarkFinished(Status::OK());
+ return;
Review Comment:
```suggestion
```
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1051,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
+ arrow::internal::Executor* executor, Future<> future) {
+ if (unlocked_) {
+ num_finished_++;
+ future.MarkFinished(Status::OK());
+ return;
+ } else {
+ if (std::chrono::steady_clock::now() > end_time) {
+ num_finished_++;
+ future.MarkFinished(
+ Status::Invalid("Task unlock never happened - if threads are disabled you "
+ "can't wait on gatedtask"));
+ return;
+ } else {
+ SleepABit();
+ auto spawn_status = executor->Spawn([this, end_time, executor, future]() {
+ WaitForEndOrUnlocked(end_time, executor, future);
+ });
+ if (!spawn_status.ok()) {
+ status_ &= Status::Invalid("Couldn't spawn gating task unlock waiter");
+ }
+ }
+ }
+ }
+
+ Future<> RunTaskFuture() {
+ num_running_++;
+ // post the unlock check as a separate task
+ // otherwise we'll never let anything else run
+ // so nothing can unlock us
+ using Clock = std::chrono::steady_clock;
+ using DurationDouble = std::chrono::duration<double>;
+ using DurationClock = std::chrono::steady_clock::duration;
+
+ auto start_time = Clock::now();
+ std::chrono::duration<double> secs_left =
+ std::chrono::duration<double>(timeout_seconds_);
+ std::chrono::time_point<Clock> end_time =
Review Comment:
Can we use `auto` here?
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1051,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
+ arrow::internal::Executor* executor, Future<> future) {
+ if (unlocked_) {
+ num_finished_++;
+ future.MarkFinished(Status::OK());
+ return;
+ } else {
+ if (std::chrono::steady_clock::now() > end_time) {
+ num_finished_++;
+ future.MarkFinished(
+ Status::Invalid("Task unlock never happened - if threads are disabled you "
+ "can't wait on gatedtask"));
+ return;
Review Comment:
```suggestion
```
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1051,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
+ arrow::internal::Executor* executor, Future<> future) {
+ if (unlocked_) {
+ num_finished_++;
+ future.MarkFinished(Status::OK());
+ return;
+ } else {
+ if (std::chrono::steady_clock::now() > end_time) {
+ num_finished_++;
+ future.MarkFinished(
+ Status::Invalid("Task unlock never happened - if threads are disabled you "
+ "can't wait on gatedtask"));
+ return;
+ } else {
+ SleepABit();
+ auto spawn_status = executor->Spawn([this, end_time, executor, future]() {
+ WaitForEndOrUnlocked(end_time, executor, future);
+ });
+ if (!spawn_status.ok()) {
+ status_ &= Status::Invalid("Couldn't spawn gating task unlock waiter");
+ }
+ }
+ }
+ }
+
+ Future<> RunTaskFuture() {
+ num_running_++;
+ // post the unlock check as a separate task
+ // otherwise we'll never let anything else run
+ // so nothing can unlock us
+ using Clock = std::chrono::steady_clock;
+ using DurationDouble = std::chrono::duration<double>;
+ using DurationClock = std::chrono::steady_clock::duration;
+
+ auto start_time = Clock::now();
+ std::chrono::duration<double> secs_left =
Review Comment:
```suggestion
auto secs_left =
```
##########
cpp/src/arrow/util/future.cc:
##########
@@ -149,17 +150,47 @@ class ConcreteFutureImpl : public FutureImpl {
}
void DoWait() {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return IsFutureFinished(state_); });
+#else
+ auto last_processed_time = std::chrono::steady_clock::now();
+ while (true) {
+ if (IsFutureFinished(state_)) {
+ return;
+ }
+ if (arrow::internal::SerialExecutor::RunTasksOnAllExecutors() == false) {
+ auto this_time = std::chrono::steady_clock::now();
+ if (this_time - last_processed_time < std::chrono::seconds(10)) {
+ ARROW_LOG(WARNING) << "Waiting for future, but no executors have had any tasks "
+ "pending for last 10 seconds";
+ last_processed_time = std::chrono::steady_clock::now();
+ }
+ }
+ }
+#endif
}
bool DoWait(double seconds) {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait_for(lock, std::chrono::duration<double>(seconds),
[this] { return IsFutureFinished(state_); });
return IsFutureFinished(state_);
+#else
+ auto start = std::chrono::steady_clock::now();
+ std::chrono::duration<double> fsec = std::chrono::duration<double>(seconds);
Review Comment:
```suggestion
auto fsec = std::chrono::duration<double>(seconds);
```
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +267,110 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors() {
+ auto globalState = GetSerialExecutorGlobalState();
+ // if the previously called executor was deleted, ignore last_called_executor
+ if (globalState->last_called_executor != NULL &&
+ globalState->all_executors.count(globalState->last_called_executor) == 0) {
+ globalState->last_called_executor = NULL;
+ }
+ bool run_task = true;
+ bool keep_going = true;
+ while (keep_going) {
+ run_task = false;
+ keep_going = false;
+ for (auto it = globalState->all_executors.begin();
+ it != globalState->all_executors.end(); ++it) {
+ if (globalState->last_called_executor != NULL) {
+ // always rerun loop if we have a last_called_executor, otherwise
+ // we may drop out before every executor has been checked
+ keep_going = true;
+ if (globalState->all_executors.count(globalState->last_called_executor) == 0 ||
+ globalState->last_called_executor == *it) {
+ // found the last one (or it doesn't exist ih the set any more)
+ // now we can start running things
+ globalState->last_called_executor = NULL;
+ }
+ // skip until after we have seen the last executor we called
+ // so that we do things nicely in turn
+ continue;
+ }
+ SerialExecutor* exe = *it;
Review Comment:
```suggestion
auto exe = *it;
```
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1530,6 +1547,16 @@ TEST(TestAsyncUtil, ReadaheadFailedWaitForInFlight) {
// These are our in-flight tasks
return TestInt(0);
}));
+#else
+ // if threading is disabled, we can't call Task() as we do below because it will
+ // never return and will block everything
Review Comment:
@joemarshall Could you check this?
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1486,13 +1490,24 @@ TEST(TestAsyncUtil, ReadaheadFailed) {
// should all pass
auto source = [&]() -> Future<TestInt> {
auto count = counter++;
+#ifdef ARROW_ENABLE_THREADING
return DeferNotOk(thread_pool->Submit([&, count]() -> Result<TestInt> {
gating_task->Task()();
if (count == 0) {
return Status::Invalid("X");
}
return TestInt(count);
}));
+#else
+ // if threading is disabled, we can't call Task() as we do below because it will
+ // never return and will block everything
Review Comment:
@joemarshall Could you check this?
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1051,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
+ arrow::internal::Executor* executor, Future<> future) {
+ if (unlocked_) {
+ num_finished_++;
+ future.MarkFinished(Status::OK());
+ return;
Review Comment:
Or:
```cpp
if (unlocked_) {
...
return;
}
if (std::chrono::steady_clock::now() > end_time) {
...
return;
}
SleepABit();
...
```
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1051,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
+ arrow::internal::Executor* executor, Future<> future) {
+ if (unlocked_) {
+ num_finished_++;
+ future.MarkFinished(Status::OK());
+ return;
+ } else {
+ if (std::chrono::steady_clock::now() > end_time) {
+ num_finished_++;
+ future.MarkFinished(
+ Status::Invalid("Task unlock never happened - if threads are disabled you "
+ "can't wait on gatedtask"));
+ return;
+ } else {
+ SleepABit();
+ auto spawn_status = executor->Spawn([this, end_time, executor, future]() {
+ WaitForEndOrUnlocked(end_time, executor, future);
+ });
+ if (!spawn_status.ok()) {
+ status_ &= Status::Invalid("Couldn't spawn gating task unlock waiter");
+ }
+ }
+ }
+ }
+
+ Future<> RunTaskFuture() {
+ num_running_++;
+ // post the unlock check as a separate task
+ // otherwise we'll never let anything else run
+ // so nothing can unlock us
+ using Clock = std::chrono::steady_clock;
+ using DurationDouble = std::chrono::duration<double>;
+ using DurationClock = std::chrono::steady_clock::duration;
+
+ auto start_time = Clock::now();
+ std::chrono::duration<double> secs_left =
+ std::chrono::duration<double>(timeout_seconds_);
+ std::chrono::time_point<Clock> end_time =
+ std::chrono::time_point_cast<DurationClock, Clock, DurationDouble>(start_time +
+ secs_left);
+ arrow::internal::Executor* executor = arrow::internal::GetCpuThreadPool();
Review Comment:
```suggestion
auto executor = arrow::internal::GetCpuThreadPool();
```
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1051,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
+ arrow::internal::Executor* executor, Future<> future) {
+ if (unlocked_) {
+ num_finished_++;
+ future.MarkFinished(Status::OK());
+ return;
+ } else {
+ if (std::chrono::steady_clock::now() > end_time) {
+ num_finished_++;
+ future.MarkFinished(
+ Status::Invalid("Task unlock never happened - if threads are disabled you "
+ "can't wait on gatedtask"));
+ return;
+ } else {
+ SleepABit();
+ auto spawn_status = executor->Spawn([this, end_time, executor, future]() {
+ WaitForEndOrUnlocked(end_time, executor, future);
+ });
+ if (!spawn_status.ok()) {
+ status_ &= Status::Invalid("Couldn't spawn gating task unlock waiter");
+ }
+ }
+ }
+ }
+
+ Future<> RunTaskFuture() {
+ num_running_++;
+ // post the unlock check as a separate task
+ // otherwise we'll never let anything else run
+ // so nothing can unlock us
+ using Clock = std::chrono::steady_clock;
+ using DurationDouble = std::chrono::duration<double>;
+ using DurationClock = std::chrono::steady_clock::duration;
+
+ auto start_time = Clock::now();
+ std::chrono::duration<double> secs_left =
+ std::chrono::duration<double>(timeout_seconds_);
+ std::chrono::time_point<Clock> end_time =
+ std::chrono::time_point_cast<DurationClock, Clock, DurationDouble>(start_time +
+ secs_left);
+ arrow::internal::Executor* executor = arrow::internal::GetCpuThreadPool();
+ Future<> future = Future<>::Make();
Review Comment:
```suggestion
auto future = Future<>::Make();
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1287834111
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1521,6 +1532,7 @@ TEST(TestAsyncUtil, ReadaheadFailedWaitForInFlight) {
auto in_flight_gating_task = GatingTask::Make();
auto source = [&]() -> Future<TestInt> {
auto count = counter++;
+
Review Comment:
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1663858005
> > The description at the top of the PR is up to date now (and has a brief changelog of what changed from initial PR)
>
> Could you replace the initial description directly instead of adding a new "Updated since initial PR:" section? The latest decision is the most important thing for us. If we want to see the history, we can use GitHub's history view UI. (See the "edited" pull down in the top of the description area.)
Okay, it's up to date.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1204884326
##########
cpp/CMakeLists.txt:
##########
@@ -370,6 +370,7 @@ if(ARROW_ENABLE_TIMING_TESTS)
add_definitions(-DARROW_WITH_TIMING_TESTS)
endif()
+
Review Comment:
Could you revert needless changes like this?
It seems that there are more needless changes. Could you check again?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1220899262
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +247,105 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
Review Comment:
I think pretty much anything that does I/O assumes that the i/o calls and serialexecutor calls run in parallel. Without this stuff, serialexecutors can't run at the same time as I/O things which breaks quite a lot of things including loading parquet files. Executors need to be able to assume that other things will happen if they don't have any tasks ready to run or else bad things happen.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1218911341
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -725,8 +726,24 @@ void TestInitialized(const ArrayData& array) {
}
void SleepFor(double seconds) {
+#ifdef ARROW_ENABLE_THREADING
std::this_thread::sleep_for(
std::chrono::nanoseconds(static_cast<int64_t>(seconds * 1e9)));
+#else
+ std::chrono::duration<double> secs_left = std::chrono::duration<double>(seconds);
Review Comment:
```suggestion
auto secs_left = std::chrono::duration<double>(seconds);
```
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1048,16 +1118,32 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
" seconds) waiting for the gating task to be unlocked");
}
num_finished_++;
+#else
+ // can't wait here for anything, so make a future to do the waiting
+ num_running_++;
+ auto future = RunTaskFuture();
+ future.Wait();
+ return;
Review Comment:
```suggestion
```
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -725,8 +726,24 @@ void TestInitialized(const ArrayData& array) {
}
void SleepFor(double seconds) {
+#ifdef ARROW_ENABLE_THREADING
std::this_thread::sleep_for(
std::chrono::nanoseconds(static_cast<int64_t>(seconds * 1e9)));
+#else
+ std::chrono::duration<double> secs_left = std::chrono::duration<double>(seconds);
+ auto start_time = std::chrono::steady_clock::now();
+ auto end_time = start_time + secs_left;
+ auto now = start_time;
+ while (now < end_time) {
Review Comment:
```suggestion
while (std::chrono::steady_clock::now() < end_time) {
```
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1048,16 +1118,32 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
" seconds) waiting for the gating task to be unlocked");
}
num_finished_++;
+#else
+ // can't wait here for anything, so make a future to do the waiting
+ num_running_++;
+ auto future = RunTaskFuture();
+ future.Wait();
Review Comment:
Can we just use `BusyWait()` here?
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1486,13 +1490,24 @@ TEST(TestAsyncUtil, ReadaheadFailed) {
// should all pass
auto source = [&]() -> Future<TestInt> {
auto count = counter++;
+#ifdef ARROW_ENABLE_THREADING
return DeferNotOk(thread_pool->Submit([&, count]() -> Result<TestInt> {
gating_task->Task()();
if (count == 0) {
return Status::Invalid("X");
}
return TestInt(count);
}));
+#else
+ // if threading is disabled, we can't call Task() as we do below because it will
+ // never return and will block everything
Review Comment:
Should we skip this test instead of adding codes here?
##########
cpp/src/arrow/util/thread_pool_test.cc:
##########
@@ -845,8 +877,11 @@ TEST_F(TestThreadPoolForkSafety, Basics) {
}
TEST_F(TestThreadPoolForkSafety, MultipleChildThreads) {
- // ARROW-15593: race condition in after-fork ThreadPool reinitialization
- // when SpawnReal() was called from multiple threads in a forked child.
+// ARROW-15593: race condition in after-fork ThreadPool reinitialization
+// when SpawnReal() was called from multiple threads in a forked child.
Review Comment:
Could you move this after `GTEST_SKIP()`?
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -725,8 +726,24 @@ void TestInitialized(const ArrayData& array) {
}
void SleepFor(double seconds) {
+#ifdef ARROW_ENABLE_THREADING
std::this_thread::sleep_for(
std::chrono::nanoseconds(static_cast<int64_t>(seconds * 1e9)));
+#else
+ std::chrono::duration<double> secs_left = std::chrono::duration<double>(seconds);
+ auto start_time = std::chrono::steady_clock::now();
+ auto end_time = start_time + secs_left;
+ auto now = start_time;
+ while (now < end_time) {
+ bool run_task = arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
+ now = std::chrono::steady_clock::now();
+ if (!run_task) {
+ // all executors are empty, just sleep for the rest of the time
+ std::this_thread::sleep_for(end_time - now);
Review Comment:
```suggestion
std::this_thread::sleep_for(end_time - std::chrono::steady_clock::now());
```
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1530,6 +1547,16 @@ TEST(TestAsyncUtil, ReadaheadFailedWaitForInFlight) {
// These are our in-flight tasks
return TestInt(0);
}));
+#else
+ // if threading is disabled, we can't call Task() as we do below because it will
+ // never return and will block everything
Review Comment:
Should we skip this test instead of adding codes here?
##########
cpp/src/arrow/util/future.cc:
##########
@@ -89,7 +90,7 @@ class ConcreteFutureImpl : public FutureImpl {
case ShouldSchedule::IfUnfinished:
return !in_add_callback;
case ShouldSchedule::IfDifferentExecutor:
- return !callback_record.options.executor->OwnsThisThread();
+ return !(callback_record.options.executor->IsCurrentExecutor());
Review Comment:
Why do we need this change?
Can we just disable (or error) this feature without threading?
##########
cpp/src/arrow/util/thread_pool_test.cc:
##########
@@ -341,6 +342,7 @@ TEST(SerialExecutor, AsyncGeneratorWithCleanup) {
// must run before the terminal item is delivered from the iterator.
bool follow_up_ran = false;
Iterator<TestInt> iter =
+
Review Comment:
```suggestion
```
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +247,105 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
Review Comment:
Why do we need this?
Can we disable (or error) features that need this method?
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -532,6 +695,65 @@ int ThreadPool::DefaultCapacity() {
return capacity;
}
+#else // ARROW_ENABLE_THREADING
+ThreadPool::ThreadPool() {
Review Comment:
Can we return `Status::NotImplemented` from all `ThreadPool` methods instead of implementing `ThreadPool` without threading?
##########
cpp/src/arrow/util/thread_pool_test.cc:
##########
@@ -598,8 +603,11 @@ TEST_F(TestThreadPool, OwnsCurrentThread) {
ASSERT_FALSE(pool->OwnsThisThread());
ASSERT_FALSE(one_failed);
}
-
Review Comment:
Could you revert all needless changes?
##########
cpp/src/arrow/util/future.cc:
##########
@@ -149,17 +150,38 @@ class ConcreteFutureImpl : public FutureImpl {
}
void DoWait() {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
-
Review Comment:
Could you revert needless change?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1203838566
##########
ci/scripts/cpp_test.sh:
##########
@@ -80,6 +80,12 @@ pushd ${build_dir}
if [ -z "${PYTHON}" ] && ! which python > /dev/null 2>&1; then
export PYTHON="${PYTHON:-python3}"
fi
+if [[ "${ARROW_ENABLE_THREADING}" == "OFF" ]]; then
+# if threading is disabled, some tests take longer to run
+# but we can get away with running more tests in parallel because we know they wont make loads of threads
+ ARROW_CTEST_TIMEOUT=${ARROW_CTEST_TIMEOUT:-900}
+ n_jobs=$((n_jobs*4))
Review Comment:
Reverted this stuff - I think a bug was causing the slow tests in my build.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1572249563
@kou I don't know why that last version of this PR had a fail on arm64-ubuntu. I've merged latest changes into my branch to see if it fails there also. It may just be a freak github actions fail though.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1669009155
@kou think we're good to merge now?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] jorisvandenbossche commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "jorisvandenbossche (via GitHub)" <gi...@apache.org>.
jorisvandenbossche commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1614637264
@github-actions crossbow submit test-ubuntu-22.04-cpp-no-threading
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1228352814
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1052,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void _WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
Review Comment:
Why the leading underscore?
##########
cpp/src/arrow/util/thread_pool.h:
##########
@@ -194,6 +196,11 @@ class ARROW_EXPORT Executor {
// Executor. Returns false if this Executor does not support this property.
virtual bool OwnsThisThread() { return false; }
+ // Return true if this is the current executor being called
+ // n.b. this defaults to just calling OwnsThisThread
+ // unless the threadpool is disabled
+ virtual bool IsCurrentExecutor() { return OwnsThisThread(); }
Review Comment:
I'm having a hard time understanding the difference between these two. When would I prefer `IsCurrentExecutor` over `OwnsThisThread` (or vice versa)?
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -60,11 +61,33 @@ struct SerialExecutor::State {
std::thread::id current_thread;
bool paused{false};
bool finished{false};
+#ifndef ARROW_ENABLE_THREADING
+ int max_tasks_running{1};
+ int tasks_running{0};
+#endif
};
-SerialExecutor::SerialExecutor() : state_(std::make_shared<State>()) {}
+#ifndef ARROW_ENABLE_THREADING
+// list of all SerialExecutor objects - as we need to run tasks from all pools at once in
+// Run()
+std::unordered_set<SerialExecutor*> SerialExecutor::all_executors;
+SerialExecutor* SerialExecutor::current_executor = NULL;
+SerialExecutor* SerialExecutor::GetCurrentExecutor() { return current_executor; }
+SerialExecutor* SerialExecutor::last_called_executor = NULL;
Review Comment:
We should prefer static local variables. E.g. something like...
```
struct SerialExecutors {
std::unordered_set<SerialExecutor*> SerialExecutor::all_executors;
SerialExecutor* SerialExecutor::current_executor = NULL;
SerialExecutor* SerialExecutor::last_called_executor = NULL;
}
SerialExecutors& GetSerialExecutors() {
static SerialExecutors serial_executors;
return serial_executors;
}
```
Also, we could use a bit more explanation here. What is the difference between `current_executor` and `last_called_executors`?
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -60,11 +61,33 @@ struct SerialExecutor::State {
std::thread::id current_thread;
bool paused{false};
bool finished{false};
+#ifndef ARROW_ENABLE_THREADING
+ int max_tasks_running{1};
+ int tasks_running{0};
+#endif
};
-SerialExecutor::SerialExecutor() : state_(std::make_shared<State>()) {}
+#ifndef ARROW_ENABLE_THREADING
+// list of all SerialExecutor objects - as we need to run tasks from all pools at once in
+// Run()
+std::unordered_set<SerialExecutor*> SerialExecutor::all_executors;
+SerialExecutor* SerialExecutor::current_executor = NULL;
+SerialExecutor* SerialExecutor::GetCurrentExecutor() { return current_executor; }
+SerialExecutor* SerialExecutor::last_called_executor = NULL;
+
+#endif
+
+SerialExecutor::SerialExecutor() : state_(std::make_shared<State>()) {
+#ifndef ARROW_ENABLE_THREADING
+ all_executors.insert(this);
Review Comment:
This doesn't seem thread safe. If `ARROW_ENABLE_THREADING` is false does this mean that we are assuming the user doesn't have any threads of their own?
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -77,6 +100,12 @@ SerialExecutor::~SerialExecutor() {
}
}
+int SerialExecutor::GetNumTasks() {
+ auto state = state_;
+ return (int)(state_->task_queue.size());
Review Comment:
Prefer C++ style casts
```suggestion
return static_cast<int>(state_->task_queue.size());
```
##########
cpp/src/arrow/util/future.cc:
##########
@@ -149,17 +150,39 @@ class ConcreteFutureImpl : public FutureImpl {
}
void DoWait() {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return IsFutureFinished(state_); });
+#else
+ while (true) {
+ if (IsFutureFinished(state_)) {
+ return;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
+ }
+#endif
}
bool DoWait(double seconds) {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait_for(lock, std::chrono::duration<double>(seconds),
[this] { return IsFutureFinished(state_); });
return IsFutureFinished(state_);
+#else
+ auto start = std::chrono::steady_clock::now();
+ std::chrono::duration<double> fsec = std::chrono::duration<double>(seconds);
+ while (std::chrono::steady_clock::now() - start < fsec) {
+ // run one task then check time
+ if (IsFutureFinished(state_)) {
+ return true;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
+ }
+ return IsFutureFinished(state_);
Review Comment:
This pattern seems to have repeated itself a few times. I wonder if we can add a utility method somewhere like `SafeWait(Func condition, double max_wait_seconds)`
##########
cpp/src/arrow/util/thread_pool.h:
##########
@@ -393,8 +420,23 @@ class ARROW_EXPORT SerialExecutor : public Executor {
RunLoop();
return final_fut;
}
+
+#ifndef ARROW_ENABLE_THREADING
+ // we have to run tasks from all live executors
+ // during RunLoop if we don't have threading
+ static std::unordered_set<SerialExecutor*> all_executors;
Review Comment:
If threading is disabled then how is there more than one serial executor?
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1486,13 +1490,24 @@ TEST(TestAsyncUtil, ReadaheadFailed) {
// should all pass
auto source = [&]() -> Future<TestInt> {
auto count = counter++;
+#ifdef ARROW_ENABLE_THREADING
return DeferNotOk(thread_pool->Submit([&, count]() -> Result<TestInt> {
gating_task->Task()();
if (count == 0) {
return Status::Invalid("X");
}
return TestInt(count);
}));
+#else
+ // if threading is disabled, we can't call Task() as we do below because it will
+ // never return and will block everything
Review Comment:
Or possibly we could use a serial executor instead of the thread pool if threading is disabled.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1663143528
> The description at the top of the PR is up to date now (and has a brief changelog of what changed from initial PR)
Could you replace the initial description directly instead of adding a new "Updated since initial PR:" section?
The latest decision is the most important thing for us.
If we want to see the history, we can use GitHub's history view UI. (See the "edited" pull down in the top of the description area.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1591883165
> Thank you for working on this. This will be a great feature. I haven't fully understood everything but I think I am getting the picture. Could you just give a general description of how you might have multiple serial executors? Is this from multiple user threads? Or is this becuase the CPU executor and the I/O executor need to be two distinct executors for some reason?
So there's two ways to end up with multiple executors - firstly there's lots of code that assumes that while an executor is running a cpu based task, it can fire and wait for i/o calls. In order to support this kind of waiting in CPU processing code, we still have to keep track of things in multiple executors.
There's also I think some stuff in other things which use multiple executors to run things in parallel whilst keeping each set of executions neatly serialised. And I think things that use nested executors. I found it easier to keep the multiple executors in existence logically, even if in reality there is only ever one thing happening at any time. I did try putting everything in a single executor and a lot of tests failed, so I figured it made more sense to keep the logical structure.
The only other difference is that instead of waiting on a condition when a serial executor is held up by I/o or whatever, it instead loops through all other executors to see if they have any tasks that need running.
Because of that, the concept of a current executor, i.e. the innermost executor being called is used instead of the thread id to detect if a particular executor is running the currently executing task.
The other potential advantage of keeping the logical structure of things like this is that in future, there is potential for support for asynchronous i/o even in systems without threading - e.g. in webassembly there is an extension (currently experimental only, but standards track ) which enables creating and waiting on JavaScript futures. With that, whilst you still often don't have threads, you can do i/o in parallel with computation. That could integrate with this code with minimal modifications I think.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1220906930
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1048,16 +1118,32 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
" seconds) waiting for the gating task to be unlocked");
}
num_finished_++;
+#else
+ // can't wait here for anything, so make a future to do the waiting
+ num_running_++;
+ auto future = RunTaskFuture();
+ future.Wait();
Review Comment:
I don't think so, but I can't remember why
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1561163275
Right - that's fixed, I think ready for review
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] conbench-apache-arrow[bot] commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "conbench-apache-arrow[bot] (via GitHub)" <gi...@apache.org>.
conbench-apache-arrow[bot] commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1675841977
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit b668595dda38beb7bfd5b5528c3200402590c1eb.
There were 2 benchmark results indicating a performance regression:
- Commit Run on `ursa-i9-9960x` at [2023-08-12 07:55:52Z](http://conbench.ursa.dev/compare/runs/304418d8c8c445c1bd667d90b38e9ee3...94412b2949b94d2995d4ca2c1b50fa7f/)
- [`file-read` (R) with compression=uncompressed, dataset=fanniemae_2016Q4, file_type=feather, language=R, output_type=dataframe](http://conbench.ursa.dev/compare/benchmarks/064d72179c177da180000443c5bb3145...064d74ccbc0d7c758000c41a24def95f)
- [`file-read` (R) with compression=lz4, dataset=fanniemae_2016Q4, file_type=feather, language=R, output_type=table](http://conbench.ursa.dev/compare/benchmarks/064d721861217b4380000b3319bfae38...064d74ce04517baf8000da50d8257cee)
The [full Conbench report](https://github.com/apache/arrow/runs/15840517894) has more details. It also includes information about possible false positives for unstable benchmarks that are known to sometimes produce them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1645401845
@westonpace Fixed merge conflicts with recent changes (just to bloom filter testing) and merged up to date. hopefully we're ready to merge now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1635930491
@westonpace sorry, I went off sick for a few days, and only just caught up with this. I've think I've fixed all the broken things / missing comments now.
I left those tests in, just because I felt they were useful as examples of what does and doesn't work in single threaded mode, Feel free to remove if you think that's a bad idea.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1553173900
@github-actions crossbow submit test-ubuntu-22.04-cpp-no-threading
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1220903702
##########
cpp/src/arrow/util/future.cc:
##########
@@ -89,7 +90,7 @@ class ConcreteFutureImpl : public FutureImpl {
case ShouldSchedule::IfUnfinished:
return !in_add_callback;
case ShouldSchedule::IfDifferentExecutor:
- return !callback_record.options.executor->OwnsThisThread();
+ return !(callback_record.options.executor->IsCurrentExecutor());
Review Comment:
I'm not sure - I didn't really know what this feature was used for and who uses it, so I made sure I didn't break it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1553657705
@github-actions crossbow submit test-ubuntu-22.04-cpp-no-threading
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1262547286
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +267,110 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
+ auto globalState = GetSerialExecutorGlobalState();
+ // if the previously called executor was deleted, ignore last_called_executor
+ if (globalState->last_called_executor != NULL &&
+ globalState->all_executors.count(globalState->last_called_executor) == 0) {
+ globalState->last_called_executor = NULL;
+ }
+ bool run_task = true;
+ bool keep_going = true;
+ while (keep_going) {
+ run_task = false;
+ keep_going = false;
+ for (auto it = globalState->all_executors.begin();
+ it != globalState->all_executors.end(); ++it) {
+ if (globalState->last_called_executor != NULL) {
+ // always rerun loop if we have a last_called_executor, otherwise
+ // we drop out before everything is
+ keep_going = true;
+ if (globalState->all_executors.count(globalState->last_called_executor) == 0 ||
+ globalState->last_called_executor == *it) {
+ // found the last one (or it doesn't exist ih the set any more)
+ // now we can start running things
+ globalState->last_called_executor = NULL;
+ }
+ // skip until after we have seen the last executor we called
+ // so that we do things nicely in turn
+ continue;
+ }
+ SerialExecutor* exe = *it;
+ // don't make reentrant calls inside a serialexecutor
+ // or more than the number of concurrent tasks set on a threadpool
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] westonpace commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "westonpace (via GitHub)" <gi...@apache.org>.
westonpace commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1254020989
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +267,110 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
Review Comment:
I believe that every time you call this method `once_only` is set to `true`. Does this parameter need to be here?
##########
cpp/src/arrow/util/future.cc:
##########
@@ -149,17 +150,39 @@ class ConcreteFutureImpl : public FutureImpl {
}
void DoWait() {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return IsFutureFinished(state_); });
+#else
+ while (true) {
+ if (IsFutureFinished(state_)) {
+ return;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
Review Comment:
If all the executors were idle then this could turn into a busy loop. However, for that to happen, it would mean there is a future that is getting fulfilled by something that isn't a task. I don't think we do that very often. The only example I can think of is S3 (since S3 uses its own threads) and I expect S3 support is disabled on emscripten? It's probably not something we need to worry too much about now but maybe log a warning if `RunTasksOnAllExecutors` returns false here?
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +267,110 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
+ auto globalState = GetSerialExecutorGlobalState();
+ // if the previously called executor was deleted, ignore last_called_executor
+ if (globalState->last_called_executor != NULL &&
+ globalState->all_executors.count(globalState->last_called_executor) == 0) {
+ globalState->last_called_executor = NULL;
+ }
+ bool run_task = true;
+ bool keep_going = true;
+ while (keep_going) {
+ run_task = false;
+ keep_going = false;
+ for (auto it = globalState->all_executors.begin();
+ it != globalState->all_executors.end(); ++it) {
+ if (globalState->last_called_executor != NULL) {
+ // always rerun loop if we have a last_called_executor, otherwise
+ // we drop out before everything is
Review Comment:
everything is what?
##########
cpp/src/arrow/util/future.cc:
##########
@@ -149,17 +150,39 @@ class ConcreteFutureImpl : public FutureImpl {
}
void DoWait() {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return IsFutureFinished(state_); });
+#else
+ while (true) {
+ if (IsFutureFinished(state_)) {
+ return;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
+ }
+#endif
}
bool DoWait(double seconds) {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait_for(lock, std::chrono::duration<double>(seconds),
[this] { return IsFutureFinished(state_); });
return IsFutureFinished(state_);
+#else
+ auto start = std::chrono::steady_clock::now();
+ std::chrono::duration<double> fsec = std::chrono::duration<double>(seconds);
+ while (std::chrono::steady_clock::now() - start < fsec) {
+ // run one task then check time
+ if (IsFutureFinished(state_)) {
+ return true;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
+ }
+ return IsFutureFinished(state_);
Review Comment:
No, I agree we shouldn't worry about it.
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +267,110 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
+ auto globalState = GetSerialExecutorGlobalState();
+ // if the previously called executor was deleted, ignore last_called_executor
+ if (globalState->last_called_executor != NULL &&
+ globalState->all_executors.count(globalState->last_called_executor) == 0) {
+ globalState->last_called_executor = NULL;
+ }
+ bool run_task = true;
+ bool keep_going = true;
+ while (keep_going) {
+ run_task = false;
+ keep_going = false;
+ for (auto it = globalState->all_executors.begin();
+ it != globalState->all_executors.end(); ++it) {
+ if (globalState->last_called_executor != NULL) {
+ // always rerun loop if we have a last_called_executor, otherwise
+ // we drop out before everything is
+ keep_going = true;
+ if (globalState->all_executors.count(globalState->last_called_executor) == 0 ||
+ globalState->last_called_executor == *it) {
+ // found the last one (or it doesn't exist ih the set any more)
+ // now we can start running things
+ globalState->last_called_executor = NULL;
+ }
+ // skip until after we have seen the last executor we called
+ // so that we do things nicely in turn
+ continue;
+ }
+ SerialExecutor* exe = *it;
+ // don't make reentrant calls inside a serialexecutor
+ // or more than the number of concurrent tasks set on a threadpool
Review Comment:
```suggestion
// don't make more reentrant calls inside a serialexecutor
// than the number of concurrent tasks set on a threadpool
```
Though maybe I am misunderstanding this comment
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1530,6 +1547,16 @@ TEST(TestAsyncUtil, ReadaheadFailedWaitForInFlight) {
// These are our in-flight tasks
return TestInt(0);
}));
+#else
+ // if threading is disabled, we can't call Task() as we do below because it will
+ // never return and will block everything
Review Comment:
Agreed
##########
cpp/src/arrow/util/async_generator_test.cc:
##########
@@ -1486,13 +1490,24 @@ TEST(TestAsyncUtil, ReadaheadFailed) {
// should all pass
auto source = [&]() -> Future<TestInt> {
auto count = counter++;
+#ifdef ARROW_ENABLE_THREADING
return DeferNotOk(thread_pool->Submit([&, count]() -> Result<TestInt> {
gating_task->Task()();
if (count == 0) {
return Status::Invalid("X");
}
return TestInt(count);
}));
+#else
+ // if threading is disabled, we can't call Task() as we do below because it will
+ // never return and will block everything
Review Comment:
However, I'm also content to just skip this test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1607662529
@westonpace I finally got round to looking at those changes - I've put comments on anything that I didn't just resolve now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1239675684
##########
cpp/src/arrow/util/thread_pool.h:
##########
@@ -393,8 +420,23 @@ class ARROW_EXPORT SerialExecutor : public Executor {
RunLoop();
return final_fut;
}
+
+#ifndef ARROW_ENABLE_THREADING
+ // we have to run tasks from all live executors
+ // during RunLoop if we don't have threading
+ static std::unordered_set<SerialExecutor*> all_executors;
Review Comment:
Because CPU processing can wait for i/o. And in theory (not sure but I think in practice in acero) people can create multiple executors with dependencies across each other, which should still work in this case, just with things in other executors being run when one executor waits for the other.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1614640359
Revision: 798b7cb115d09486ed3f7d5b876e07485f0fbb35
Submitted crossbow builds: [ursacomputing/crossbow @ actions-70f1a7afb9](https://github.com/ursacomputing/crossbow/branches/all?query=actions-70f1a7afb9)
|Task|Status|
|----|------|
|test-ubuntu-22.04-cpp-no-threading|[](https://github.com/ursacomputing/crossbow/actions/runs/5423335068/jobs/9861125889)|
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1553177771
@kou Could you try and run the github actions bot on here. If it works then I'll copy all the description across and remove the previous PR
thanks,
Joe
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1553173473
* Closes: #35176
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] raulcd commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "raulcd (via GitHub)" <gi...@apache.org>.
raulcd commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1572263253
> @kou I don't know why that last version of this PR had a fail on arm64-ubuntu. I've merged latest changes into my branch to see if it fails there also. It may just be a freak github actions fail though.
We use self-hosted runners for ARM64. I am not sure why the test fails either:
```
[ RUN ] TestSelfPipe.ForkSafety
/arrow/cpp/src/arrow/testing/gtest_util.cc:603: Failure
Failed
Child terminated by signal 11
[ FAILED ] TestSelfPipe.ForkSafety (17 ms)
```
I've kicked CI.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1583800151
Sorry. I can't review this immediately because I don't have enough time for now. It seems that I need to run tests with `-DARROW_ENABLE_THREADING=OFF` on GDB , write some codes and so on to consider what approach is reasonable. I hope that I can do it in the next month.
(@westonpace or @pitrou may be able to review this.)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1230072096
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -60,11 +61,33 @@ struct SerialExecutor::State {
std::thread::id current_thread;
bool paused{false};
bool finished{false};
+#ifndef ARROW_ENABLE_THREADING
+ int max_tasks_running{1};
+ int tasks_running{0};
+#endif
};
-SerialExecutor::SerialExecutor() : state_(std::make_shared<State>()) {}
+#ifndef ARROW_ENABLE_THREADING
+// list of all SerialExecutor objects - as we need to run tasks from all pools at once in
+// Run()
+std::unordered_set<SerialExecutor*> SerialExecutor::all_executors;
+SerialExecutor* SerialExecutor::current_executor = NULL;
+SerialExecutor* SerialExecutor::GetCurrentExecutor() { return current_executor; }
+SerialExecutor* SerialExecutor::last_called_executor = NULL;
+
+#endif
+
+SerialExecutor::SerialExecutor() : state_(std::make_shared<State>()) {
+#ifndef ARROW_ENABLE_THREADING
+ all_executors.insert(this);
Review Comment:
Yep, I'm assuming that the main use case for disabling threading is use of arrow in emscripten or similarly constrained environments where threading doesn't work (and synchronisation primitives may also not work for that matter - in emscripten they are no ops)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1242330383
##########
cpp/src/arrow/testing/gtest_util.cc:
##########
@@ -1036,7 +1052,60 @@ class GatingTask::Impl : public std::enable_shared_from_this<GatingTask::Impl> {
return unlocked_future_;
}
+ void _WaitForEndOrUnlocked(std::chrono::time_point<std::chrono::steady_clock> end_time,
Review Comment:
because my brain was in python mode, sorry. fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1205206136
##########
cpp/CMakeLists.txt:
##########
@@ -370,6 +370,7 @@ if(ARROW_ENABLE_TIMING_TESTS)
add_definitions(-DARROW_WITH_TIMING_TESTS)
endif()
+
Review Comment:
Darn, I ran auto-lint on everything, sorry, will remove them.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1262489479
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +267,110 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
+ auto globalState = GetSerialExecutorGlobalState();
+ // if the previously called executor was deleted, ignore last_called_executor
+ if (globalState->last_called_executor != NULL &&
+ globalState->all_executors.count(globalState->last_called_executor) == 0) {
+ globalState->last_called_executor = NULL;
+ }
+ bool run_task = true;
+ bool keep_going = true;
+ while (keep_going) {
+ run_task = false;
+ keep_going = false;
+ for (auto it = globalState->all_executors.begin();
+ it != globalState->all_executors.end(); ++it) {
+ if (globalState->last_called_executor != NULL) {
+ // always rerun loop if we have a last_called_executor, otherwise
+ // we drop out before everything is
Review Comment:
oops
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1561020931
I'm just tidying this up now - there's one test in flight which fails on multi-threaded build - probably because something somewhere doesn't include `util/config.h` so ARROW_ENABLE_THREADING isn't defined when it should be. I'm fixing that and then I think it is nearly ready.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1242334293
##########
cpp/src/arrow/util/future.cc:
##########
@@ -149,17 +150,39 @@ class ConcreteFutureImpl : public FutureImpl {
}
void DoWait() {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait(lock, [this] { return IsFutureFinished(state_); });
+#else
+ while (true) {
+ if (IsFutureFinished(state_)) {
+ return;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
+ }
+#endif
}
bool DoWait(double seconds) {
+#ifdef ARROW_ENABLE_THREADING
std::unique_lock<std::mutex> lock(mutex_);
cv_.wait_for(lock, std::chrono::duration<double>(seconds),
[this] { return IsFutureFinished(state_); });
return IsFutureFinished(state_);
+#else
+ auto start = std::chrono::steady_clock::now();
+ std::chrono::duration<double> fsec = std::chrono::duration<double>(seconds);
+ while (std::chrono::steady_clock::now() - start < fsec) {
+ // run one task then check time
+ if (IsFutureFinished(state_)) {
+ return true;
+ }
+ arrow::internal::SerialExecutor::RunTasksOnAllExecutors(true);
+ }
+ return IsFutureFinished(state_);
Review Comment:
I think this is the only time it turns up outside test specific code though. I could pull it the equivalent (busywait) from gtest_util into threadpool or somewhere instead, but I don't know if it is worth it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou merged pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou merged PR #35672:
URL: https://github.com/apache/arrow/pull/35672
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1670522381
@github-actions crossbow submit test-ubuntu-22.04-cpp-no-threading
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1670523944
Revision: a4bfd804a49765a45887a05451787d54673565c5
Submitted crossbow builds: [ursacomputing/crossbow @ actions-0e4eae872c](https://github.com/ursacomputing/crossbow/branches/all?query=actions-0e4eae872c)
|Task|Status|
|----|------|
|test-ubuntu-22.04-cpp-no-threading|[](https://github.com/ursacomputing/crossbow/actions/runs/5803783903/job/15732388782)|
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1553660418
Revision: 84a8485c5b3a7241037f95055d75874b86706b43
Submitted crossbow builds: [ursacomputing/crossbow @ actions-055c8d776c](https://github.com/ursacomputing/crossbow/branches/all?query=actions-055c8d776c)
|Task|Status|
|----|------|
|test-ubuntu-22.04-cpp-no-threading|[](https://github.com/ursacomputing/crossbow/actions/runs/5018372445/jobs/8997694994)|
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] github-actions[bot] commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1553175374
```
Only contributors can submit requests to this bot. Please ask someone from the community for help with getting the first commit in.
The Archery job run can be found at: https://github.com/apache/arrow/actions/runs/5015158504
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1203200360
##########
ci/scripts/cpp_build.sh:
##########
@@ -129,6 +129,7 @@ cmake \
-DARROW_WITH_UTF8PROC=${ARROW_WITH_UTF8PROC:-ON} \
-DARROW_WITH_ZLIB=${ARROW_WITH_ZLIB:-OFF} \
-DARROW_WITH_ZSTD=${ARROW_WITH_ZSTD:-OFF} \
+ -DARROW_ENABLE_THREADING=${ARROW_ENABLE_THREADING:-ON} \
Review Comment:
Could you keep this list in alphabetical order?
##########
cpp/cmake_modules/ThirdpartyToolchain.cmake:
##########
@@ -5190,4 +5190,4 @@ message(STATUS "All bundled static libraries: ${ARROW_BUNDLED_STATIC_LIBS}")
configure_file("src/arrow/util/config.h.cmake" "src/arrow/util/config.h" ESCAPE_QUOTES)
install(FILES "${ARROW_BINARY_DIR}/src/arrow/util/config.h"
- DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/arrow/util")
+ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/arrow/util")
Review Comment:
Could you revert this needless change?
##########
ci/scripts/cpp_test.sh:
##########
@@ -80,6 +80,12 @@ pushd ${build_dir}
if [ -z "${PYTHON}" ] && ! which python > /dev/null 2>&1; then
export PYTHON="${PYTHON:-python3}"
fi
+if [[ "${ARROW_ENABLE_THREADING}" == "OFF" ]]; then
+# if threading is disabled, some tests take longer to run
+# but we can get away with running more tests in parallel because we know they wont make loads of threads
+ ARROW_CTEST_TIMEOUT=${ARROW_CTEST_TIMEOUT:-900}
+ n_jobs=$((n_jobs*4))
Review Comment:
I don't think that this is a good idea...
If we use more test processes than the number of cores, each test process competes CPU resource with others...
##########
ci/scripts/cpp_test.sh:
##########
@@ -80,6 +80,12 @@ pushd ${build_dir}
if [ -z "${PYTHON}" ] && ! which python > /dev/null 2>&1; then
export PYTHON="${PYTHON:-python3}"
fi
+if [[ "${ARROW_ENABLE_THREADING}" == "OFF" ]]; then
+# if threading is disabled, some tests take longer to run
+# but we can get away with running more tests in parallel because we know they wont make loads of threads
Review Comment:
```suggestion
# if threading is disabled, some tests take longer to run
# but we can get away with running more tests in parallel because we know they won't make loads of threads
```
##########
cpp/src/arrow/acero/asof_join_node.cc:
##########
@@ -1514,14 +1514,19 @@ class AsofJoinNode : public ExecNode {
}
Status StartProducing() override {
- ARROW_ASSIGN_OR_RAISE(process_task_, plan_->query_context()->BeginExternalTask(
- "AsofJoinNode::ProcessThread"));
- if (!process_task_.is_valid()) {
- // Plan has already aborted. Do not start process thread
+ #ifndef ARROW_ENABLE_THREADING
+ return Status::NotImplemented("ASOF join requires threading enabled");
+ #else
Review Comment:
Can we use the following approach?
```cpp
Status StartProducing() override {
#ifndef ARROW_ENABLE_THREADING
return Status::NotImplemented("ASOF join requires threading enabled");
#endif
ARROW_ASSIGN_OR_RAISE(process_task_, plan_->query_context()->BeginExternalTask(
// use existing code as-is.
```
Putting existing code to `#else ... #endif` reduces readability.
##########
cpp/src/arrow/acero/bloom_filter_test.cc:
##########
@@ -507,7 +507,11 @@ TEST(BloomFilter, Scaling) {
num_build.push_back(4000000);
std::vector<BloomFilterBuildStrategy> strategy;
+#ifndef ARROW_ENABLE_THREADING
+ strategy.push_back(BloomFilterBuildStrategy::SINGLE_THREADED);
+#else
strategy.push_back(BloomFilterBuildStrategy::PARALLEL);
+#endif
Review Comment:
Could you use `#ifdef ... #else ... #endif` not `#ifndef ... #else ... #endif` as much as possible? A `#ifndef` (invert) and `#else` (invert) pair reduces readability.
```cpp
#ifdef ARROW_ENABLE_THREADING
strategy.push_back(BloomFilterBuildStrategy::PARALLEL);
#else
strategy.push_back(BloomFilterBuildStrategy::SINGLE_THREADED);
#endif
```
##########
ci/scripts/cpp_test.sh:
##########
@@ -80,6 +80,12 @@ pushd ${build_dir}
if [ -z "${PYTHON}" ] && ! which python > /dev/null 2>&1; then
export PYTHON="${PYTHON:-python3}"
fi
+if [[ "${ARROW_ENABLE_THREADING}" == "OFF" ]]; then
+# if threading is disabled, some tests take longer to run
+# but we can get away with running more tests in parallel because we know they wont make loads of threads
+ ARROW_CTEST_TIMEOUT=${ARROW_CTEST_TIMEOUT:-900}
Review Comment:
It seems that max test time is "239.99 sec" in our CI:
https://github.com/ursacomputing/crossbow/actions/runs/5018372445/jobs/8997694994#step:6:3234
> ```text
> 89/103 Test #21: arrow-compute-scalar-if-else-test ......... Passed 239.99 sec
> ```
Why is this needed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten (from sub-branch)
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on PR #35672:
URL: https://github.com/apache/arrow/pull/35672#issuecomment-1562541946
@kou I think I've killed those last whitespace changes now.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] kou commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "kou (via GitHub)" <gi...@apache.org>.
kou commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1212338912
##########
cpp/src/arrow/io/memory_test.cc:
##########
@@ -869,6 +870,7 @@ TEST(CacheOptions, Basics) {
check(CacheOptions::MakeFromNetworkMetrics(5, 500, .75, 5), 2.5, 5);
}
+#ifdef ARROW_ENABLE_THREADING
Review Comment:
Can we use `GTEST_SKIP` here like others?
##########
cpp/src/arrow/dataset/dataset_writer_test.cc:
##########
@@ -380,8 +381,11 @@ TEST_F(DatasetWriterTestFixture, MinRowGroupBackpressure) {
}
TEST_F(DatasetWriterTestFixture, ConcurrentWritesSameFile) {
- // Use a gated filesystem to queue up many writes behind a file open to make sure the
- // file isn't opened multiple times.
+// Use a gated filesystem to queue up many writes behind a file open to make sure the
+// file isn't opened multiple times.
+#ifndef ARROW_ENABLE_THREADING
+ GTEST_SKIP() << "Concurrent writes tests need threads";
+#endif
Review Comment:
```suggestion
#ifndef ARROW_ENABLE_THREADING
GTEST_SKIP() << "Concurrent writes tests need threads";
#endif
// Use a gated filesystem to queue up many writes behind a file open to make sure the
// file isn't opened multiple times.
```
##########
cpp/cmake_modules/DefineOptions.cmake:
##########
@@ -210,6 +210,8 @@ takes precedence over ccache if a storage backend is configured" ON)
define_option(ARROW_WITH_MUSL "Whether the system libc is musl or not" OFF)
+ define_option(ARROW_ENABLE_THREADING "Enable threading in Arrow core." ON)
Review Comment:
```suggestion
define_option(ARROW_ENABLE_THREADING "Enable threading in Arrow core" ON)
```
##########
cpp/src/arrow/dataset/dataset_writer_test.cc:
##########
@@ -394,7 +398,10 @@ TEST_F(DatasetWriterTestFixture, ConcurrentWritesSameFile) {
}
TEST_F(DatasetWriterTestFixture, ConcurrentWritesDifferentFiles) {
- // NBATCHES must be less than I/O executor concurrency to avoid deadlock / test failure
+// NBATCHES must be less than I/O executor concurrency to avoid deadlock / test failure
+#ifndef ARROW_ENABLE_THREADING
+ GTEST_SKIP() << "Concurrent writes tests need threads";
+#endif
Review Comment:
```suggestion
#ifndef ARROW_ENABLE_THREADING
GTEST_SKIP() << "Concurrent writes tests need threads";
#endif
// NBATCHES must be less than I/O executor concurrency to avoid deadlock / test failure
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1242327026
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -60,11 +61,33 @@ struct SerialExecutor::State {
std::thread::id current_thread;
bool paused{false};
bool finished{false};
+#ifndef ARROW_ENABLE_THREADING
+ int max_tasks_running{1};
+ int tasks_running{0};
+#endif
};
-SerialExecutor::SerialExecutor() : state_(std::make_shared<State>()) {}
+#ifndef ARROW_ENABLE_THREADING
+// list of all SerialExecutor objects - as we need to run tasks from all pools at once in
+// Run()
+std::unordered_set<SerialExecutor*> SerialExecutor::all_executors;
+SerialExecutor* SerialExecutor::current_executor = NULL;
+SerialExecutor* SerialExecutor::GetCurrentExecutor() { return current_executor; }
+SerialExecutor* SerialExecutor::last_called_executor = NULL;
Review Comment:
Done (and commented on what the variables mean)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1262487062
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -183,6 +267,110 @@ void SerialExecutor::RunLoop() {
}
state_->current_thread = {};
}
+#else // ARROW_ENABLE_THREADING
+bool SerialExecutor::RunTasksOnAllExecutors(bool once_only) {
Review Comment:
nope, good spot
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [arrow] joemarshall commented on a diff in pull request #35672: GH-35176: [C++] Add support for disabling threading for emscripten
Posted by "joemarshall (via GitHub)" <gi...@apache.org>.
joemarshall commented on code in PR #35672:
URL: https://github.com/apache/arrow/pull/35672#discussion_r1220894872
##########
cpp/src/arrow/util/thread_pool.cc:
##########
@@ -532,6 +695,65 @@ int ThreadPool::DefaultCapacity() {
return capacity;
}
+#else // ARROW_ENABLE_THREADING
+ThreadPool::ThreadPool() {
Review Comment:
@kou I was going to do that initially, but the problem is that there is so much code that assumes that there is an IO pool and a cpu threadpool and that they are different things that it was easier just to keep track of them. And even code that uses serialexecutors assumes that other things will run concurrently because of the i/o pools. I found that rather than refactoring all code that uses thread pools, it was easier to make the threadpool & serialexecutors do some basic cooperative multitasking instead. This way also has an advantage in that it should be possible to incrementally patch in asynchronous features where the non-threading OS supports them, e.g. in emscripten it might use async calls to javascript for some types of i/o.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org