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

[TaskScheduler]: Create may block delay experiment.

Turn may_block_threshold and blocked_workers_poll_period into finch parameters
under the experiment kMayBlockAdjustTasksTiming.

Bug: 874080
Change-Id: I0104b68a96b08e9bf318258e75869555ab39e54b
Reviewed-on: https://chromium-review.googlesource.com/c/1337276Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarFrançois Doray <fdoray@chromium.org>
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610159}
parent fe1c04b1
...@@ -14,4 +14,13 @@ const Feature kAllTasksUserBlocking{"AllTasksUserBlocking", ...@@ -14,4 +14,13 @@ const Feature kAllTasksUserBlocking{"AllTasksUserBlocking",
const Feature kMergeBlockingNonBlockingPools = { const Feature kMergeBlockingNonBlockingPools = {
"MergeBlockingNonBlockingPools", base::FEATURE_DISABLED_BY_DEFAULT}; "MergeBlockingNonBlockingPools", base::FEATURE_DISABLED_BY_DEFAULT};
const Feature kMayBlockTimings = {"MayBlockTimings",
FEATURE_DISABLED_BY_DEFAULT};
const FeatureParam<int> kMayBlockThresholdMicrosecondsParam = {
&kMayBlockTimings, "MayBlockThresholdMicroseconds", 10000};
const FeatureParam<int> kBlockedWorkersPollMicrosecondsParam = {
&kMayBlockTimings, "BlockedWorkersPollMicroseconds", 50000};
} // namespace base } // namespace base
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define BASE_TASK_TASK_FEATURES_H_ #define BASE_TASK_TASK_FEATURES_H_
#include "base/base_export.h" #include "base/base_export.h"
#include "base/metrics/field_trial_params.h"
namespace base { namespace base {
...@@ -13,6 +14,10 @@ struct Feature; ...@@ -13,6 +14,10 @@ struct Feature;
extern const BASE_EXPORT Feature kAllTasksUserBlocking; extern const BASE_EXPORT Feature kAllTasksUserBlocking;
extern const BASE_EXPORT Feature kMergeBlockingNonBlockingPools; extern const BASE_EXPORT Feature kMergeBlockingNonBlockingPools;
extern const BASE_EXPORT Feature kMayBlockTimings;
extern const BASE_EXPORT FeatureParam<int> kMayBlockThresholdMicrosecondsParam;
extern const BASE_EXPORT FeatureParam<int> kBlockedWorkersPollMicrosecondsParam;
} // namespace base } // namespace base
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "base/sequence_token.h" #include "base/sequence_token.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/task/task_features.h"
#include "base/task/task_scheduler/scheduler_worker_pool_params.h" #include "base/task/task_scheduler/scheduler_worker_pool_params.h"
#include "base/task/task_scheduler/task_tracker.h" #include "base/task/task_scheduler/task_tracker.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
...@@ -38,8 +39,6 @@ ...@@ -38,8 +39,6 @@
namespace base { namespace base {
namespace internal { namespace internal {
constexpr TimeDelta SchedulerWorkerPoolImpl::kBlockedWorkersPollPeriod;
namespace { namespace {
constexpr char kPoolNameSuffix[] = "Pool"; constexpr char kPoolNameSuffix[] = "Pool";
...@@ -223,6 +222,11 @@ void SchedulerWorkerPoolImpl::Start( ...@@ -223,6 +222,11 @@ void SchedulerWorkerPoolImpl::Start(
WorkerEnvironment worker_environment) { WorkerEnvironment worker_environment) {
AutoSchedulerLock auto_lock(lock_); AutoSchedulerLock auto_lock(lock_);
may_block_threshold_ =
TimeDelta::FromMicroseconds(kMayBlockThresholdMicrosecondsParam.Get());
blocked_workers_poll_period_ =
TimeDelta::FromMicroseconds(kBlockedWorkersPollMicrosecondsParam.Get());
DCHECK(workers_.empty()); DCHECK(workers_.empty());
max_tasks_ = params.max_tasks(); max_tasks_ = params.max_tasks();
...@@ -391,7 +395,7 @@ size_t SchedulerWorkerPoolImpl::NumberOfIdleWorkersForTesting() const { ...@@ -391,7 +395,7 @@ size_t SchedulerWorkerPoolImpl::NumberOfIdleWorkersForTesting() const {
} }
void SchedulerWorkerPoolImpl::MaximizeMayBlockThresholdForTesting() { void SchedulerWorkerPoolImpl::MaximizeMayBlockThresholdForTesting() {
maximum_blocked_threshold_for_testing_.Set(); may_block_threshold_ = TimeDelta::Max();
} }
void SchedulerWorkerPoolImpl::RecordNumWorkersHistogram() const { void SchedulerWorkerPoolImpl::RecordNumWorkersHistogram() const {
...@@ -964,14 +968,10 @@ void SchedulerWorkerPoolImpl::AdjustMaxTasks() { ...@@ -964,14 +968,10 @@ void SchedulerWorkerPoolImpl::AdjustMaxTasks() {
} }
TimeDelta SchedulerWorkerPoolImpl::MayBlockThreshold() const { TimeDelta SchedulerWorkerPoolImpl::MayBlockThreshold() const {
if (maximum_blocked_threshold_for_testing_.IsSet()) // This value is usually smaller than |blocked_workers_poll_period_| because
return TimeDelta::Max(); // we hope than when multiple workers block around the same time, a single
// This value was set unscientifically based on intuition and may be adjusted // AdjustMaxTasks() call will perform all the necessary max tasks adjustments.
// in the future. This value is smaller than |kBlockedWorkersPollPeriod| return may_block_threshold_;
// because we hope than when multiple workers block around the same time, a
// single AdjustMaxTasks() call will perform all the necessary max tasks
// adjustments.
return TimeDelta::FromMilliseconds(10);
} }
void SchedulerWorkerPoolImpl::ScheduleAdjustMaxTasksIfNeeded() { void SchedulerWorkerPoolImpl::ScheduleAdjustMaxTasksIfNeeded() {
...@@ -986,7 +986,7 @@ void SchedulerWorkerPoolImpl::ScheduleAdjustMaxTasksIfNeeded() { ...@@ -986,7 +986,7 @@ void SchedulerWorkerPoolImpl::ScheduleAdjustMaxTasksIfNeeded() {
FROM_HERE, FROM_HERE,
BindOnce(&SchedulerWorkerPoolImpl::AdjustMaxTasksFunction, BindOnce(&SchedulerWorkerPoolImpl::AdjustMaxTasksFunction,
Unretained(this)), Unretained(this)),
kBlockedWorkersPollPeriod); blocked_workers_poll_period_);
} }
void SchedulerWorkerPoolImpl::AdjustMaxTasksFunction() { void SchedulerWorkerPoolImpl::AdjustMaxTasksFunction() {
...@@ -1006,7 +1006,7 @@ void SchedulerWorkerPoolImpl::AdjustMaxTasksFunction() { ...@@ -1006,7 +1006,7 @@ void SchedulerWorkerPoolImpl::AdjustMaxTasksFunction() {
FROM_HERE, FROM_HERE,
BindOnce(&SchedulerWorkerPoolImpl::AdjustMaxTasksFunction, BindOnce(&SchedulerWorkerPoolImpl::AdjustMaxTasksFunction,
Unretained(this)), Unretained(this)),
kBlockedWorkersPollPeriod); blocked_workers_poll_period_);
} }
bool SchedulerWorkerPoolImpl::ShouldPeriodicallyAdjustMaxTasksLockRequired() { bool SchedulerWorkerPoolImpl::ShouldPeriodicallyAdjustMaxTasksLockRequired() {
......
...@@ -156,12 +156,6 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { ...@@ -156,12 +156,6 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
friend class TaskSchedulerWorkerPoolBlockingTest; friend class TaskSchedulerWorkerPoolBlockingTest;
friend class TaskSchedulerWorkerPoolMayBlockTest; friend class TaskSchedulerWorkerPoolMayBlockTest;
// The period between calls to AdjustMaxTasks() when the pool is at capacity.
// This value was set unscientifically based on intuition and may be adjusted
// in the future.
static constexpr TimeDelta kBlockedWorkersPollPeriod =
TimeDelta::FromMilliseconds(50);
// SchedulerWorkerPool: // SchedulerWorkerPool:
void OnCanScheduleSequence(scoped_refptr<Sequence> sequence) override; void OnCanScheduleSequence(scoped_refptr<Sequence> sequence) override;
void OnCanScheduleSequence( void OnCanScheduleSequence(
...@@ -328,9 +322,12 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool { ...@@ -328,9 +322,12 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// incremented. // incremented.
std::unique_ptr<ConditionVariable> num_workers_cleaned_up_for_testing_cv_; std::unique_ptr<ConditionVariable> num_workers_cleaned_up_for_testing_cv_;
// Used for testing and makes MayBlockThreshold() return the maximum // Threshold after which the max tasks is increased to compensate for a
// TimeDelta. // worker that is within a MAY_BLOCK ScopedBlockingCall.
AtomicFlag maximum_blocked_threshold_for_testing_; TimeDelta may_block_threshold_;
// The period between calls to AdjustMaxTasks() when the pool is at capacity.
TimeDelta blocked_workers_poll_period_;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
// Set at the start of JoinForTesting(). // Set at the start of JoinForTesting().
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "base/synchronization/condition_variable.h" #include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/task/task_features.h"
#include "base/task/task_scheduler/delayed_task_manager.h" #include "base/task/task_scheduler/delayed_task_manager.h"
#include "base/task/task_scheduler/scheduler_task_runner_delegate.h" #include "base/task/task_scheduler/scheduler_task_runner_delegate.h"
#include "base/task/task_scheduler/scheduler_worker_pool_params.h" #include "base/task/task_scheduler/scheduler_worker_pool_params.h"
...@@ -1064,7 +1065,8 @@ class TaskSchedulerWorkerPoolBlockingTest ...@@ -1064,7 +1065,8 @@ class TaskSchedulerWorkerPoolBlockingTest
// Returns how long we can expect a change to |max_tasks_| to occur // Returns how long we can expect a change to |max_tasks_| to occur
// after a task has become blocked. // after a task has become blocked.
TimeDelta GetMaxTasksChangeSleepTime() { TimeDelta GetMaxTasksChangeSleepTime() {
return std::max(SchedulerWorkerPoolImpl::kBlockedWorkersPollPeriod, return std::max(TimeDelta::FromMicroseconds(
kBlockedWorkersPollMicrosecondsParam.Get()),
worker_pool_->MayBlockThreshold()) + worker_pool_->MayBlockThreshold()) +
TestTimeouts::tiny_timeout(); TestTimeouts::tiny_timeout();
} }
......
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