Commit 3f40244c authored by Etienne Pierre-Doray's avatar Etienne Pierre-Doray Committed by Commit Bot

[TaskScheduler]: Create no detach below initial capacity feature

Under this experiment, scheduler workers are only detached if the pool is
above its initial capacity (threads that are created to replace blocked threads).

2 options were considered:
Option A: Detach only when over initial capacity.

Option B: Detach only when over current capacity (includes currently blocked threads in capacity).
This might better handle the following case: At any given time, there is at least 1 blocked thread.
On top of that, some periodic work uses all worker every 30s or so. The current capacity will
encompass for the blocked thread and avoid detaching it periodically.

Option A was picked because it is more conservative. Initial capacity is smaller or
equal to current capacity, so detaching is closer to current behavior. We want to avoid having
too many threads that aren't used.

Bug: 847501
Change-Id: I0b116db54095767768b158d92f5f146249720b45
Reviewed-on: https://chromium-review.googlesource.com/c/1348863
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612698}
parent 87b782c9
......@@ -14,6 +14,9 @@ const Feature kAllTasksUserBlocking{"AllTasksUserBlocking",
const Feature kMergeBlockingNonBlockingPools = {
"MergeBlockingNonBlockingPools", base::FEATURE_DISABLED_BY_DEFAULT};
const Feature kNoDetachBelowInitialCapacity = {"NoDetachBelowInitialCapacity",
base::FEATURE_DISABLED_BY_DEFAULT};
const Feature kMayBlockTimings = {"MayBlockTimings",
FEATURE_DISABLED_BY_DEFAULT};
......
......@@ -16,6 +16,10 @@ extern const BASE_EXPORT Feature kAllTasksUserBlocking;
extern const BASE_EXPORT Feature kMergeBlockingNonBlockingPools;
extern const BASE_EXPORT Feature kMayBlockTimings;
// Under this feature, unused threads in SchedulerWorkerPool are only detached
// if the total number of threads in the pool is above the initial capacity.
extern const BASE_EXPORT Feature kNoDetachBelowInitialCapacity;
extern const BASE_EXPORT FeatureParam<int> kMayBlockThresholdMicrosecondsParam;
extern const BASE_EXPORT FeatureParam<int> kBlockedWorkersPollMicrosecondsParam;
......
......@@ -14,6 +14,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/compiler_specific.h"
#include "base/feature_list.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram.h"
......@@ -630,6 +631,8 @@ bool SchedulerWorkerPoolImpl::SchedulerWorkerDelegateImpl::
const TimeTicks last_used_time = worker->GetLastUsedTime();
return !last_used_time.is_null() &&
TimeTicks::Now() - last_used_time >= outer_->suggested_reclaim_time_ &&
(outer_->workers_.size() > outer_->initial_max_tasks_ ||
!FeatureList::IsEnabled(kNoDetachBelowInitialCapacity)) &&
LIKELY(!outer_->worker_cleanup_disallowed_for_testing_);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment