Skip to content

Commit

Permalink
fix(pubsub): fewer default threads for 32-bit builds (#10793)
Browse files Browse the repository at this point in the history
When the code is compiled for 32-bit platforms using
4 * hardware-concurrency background threads can quickly
exhaust the address space. Reduce the default number of
background threads to just 4.
  • Loading branch information
coryan committed Feb 9, 2023
1 parent de6d12d commit c736252
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions google/cloud/pubsub/internal/defaults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ using ms = std::chrono::milliseconds;

std::size_t DefaultThreadCount() {
auto constexpr kDefaultThreadCount = 4;
// On 32-bit machines the address space is quickly consumed by background
// threads. Create just a few threads by default on such platforms. If the
// application needs more threads, it can override this default.
if (std::numeric_limits<std::size_t>::digits < 64) return kDefaultThreadCount;
auto const n = std::thread::hardware_concurrency();
return n == 0 ? kDefaultThreadCount : n;
}
Expand Down

0 comments on commit c736252

Please sign in to comment.