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",
const Feature kMergeBlockingNonBlockingPools = {
"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
......@@ -6,6 +6,7 @@
#define BASE_TASK_TASK_FEATURES_H_
#include "base/base_export.h"
#include "base/metrics/field_trial_params.h"
namespace base {
......@@ -13,6 +14,10 @@ struct Feature;
extern const BASE_EXPORT Feature kAllTasksUserBlocking;
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
......
......@@ -20,6 +20,7 @@
#include "base/sequence_token.h"
#include "base/strings/string_util.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/task_tracker.h"
#include "base/task/task_traits.h"
......@@ -38,8 +39,6 @@
namespace base {
namespace internal {
constexpr TimeDelta SchedulerWorkerPoolImpl::kBlockedWorkersPollPeriod;
namespace {
constexpr char kPoolNameSuffix[] = "Pool";
......@@ -223,6 +222,11 @@ void SchedulerWorkerPoolImpl::Start(
WorkerEnvironment worker_environment) {
AutoSchedulerLock auto_lock(lock_);
may_block_threshold_ =
TimeDelta::FromMicroseconds(kMayBlockThresholdMicrosecondsParam.Get());
blocked_workers_poll_period_ =
TimeDelta::FromMicroseconds(kBlockedWorkersPollMicrosecondsParam.Get());
DCHECK(workers_.empty());
max_tasks_ = params.max_tasks();
......@@ -391,7 +395,7 @@ size_t SchedulerWorkerPoolImpl::NumberOfIdleWorkersForTesting() const {
}
void SchedulerWorkerPoolImpl::MaximizeMayBlockThresholdForTesting() {
maximum_blocked_threshold_for_testing_.Set();
may_block_threshold_ = TimeDelta::Max();
}
void SchedulerWorkerPoolImpl::RecordNumWorkersHistogram() const {
......@@ -964,14 +968,10 @@ void SchedulerWorkerPoolImpl::AdjustMaxTasks() {
}
TimeDelta SchedulerWorkerPoolImpl::MayBlockThreshold() const {
if (maximum_blocked_threshold_for_testing_.IsSet())
return TimeDelta::Max();
// This value was set unscientifically based on intuition and may be adjusted
// in the future. This value is smaller than |kBlockedWorkersPollPeriod|
// 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);
// This value is usually smaller than |blocked_workers_poll_period_| 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 may_block_threshold_;
}
void SchedulerWorkerPoolImpl::ScheduleAdjustMaxTasksIfNeeded() {
......@@ -986,7 +986,7 @@ void SchedulerWorkerPoolImpl::ScheduleAdjustMaxTasksIfNeeded() {
FROM_HERE,
BindOnce(&SchedulerWorkerPoolImpl::AdjustMaxTasksFunction,
Unretained(this)),
kBlockedWorkersPollPeriod);
blocked_workers_poll_period_);
}
void SchedulerWorkerPoolImpl::AdjustMaxTasksFunction() {
......@@ -1006,7 +1006,7 @@ void SchedulerWorkerPoolImpl::AdjustMaxTasksFunction() {
FROM_HERE,
BindOnce(&SchedulerWorkerPoolImpl::AdjustMaxTasksFunction,
Unretained(this)),
kBlockedWorkersPollPeriod);
blocked_workers_poll_period_);
}
bool SchedulerWorkerPoolImpl::ShouldPeriodicallyAdjustMaxTasksLockRequired() {
......
......@@ -156,12 +156,6 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
friend class TaskSchedulerWorkerPoolBlockingTest;
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:
void OnCanScheduleSequence(scoped_refptr<Sequence> sequence) override;
void OnCanScheduleSequence(
......@@ -328,9 +322,12 @@ class BASE_EXPORT SchedulerWorkerPoolImpl : public SchedulerWorkerPool {
// incremented.
std::unique_ptr<ConditionVariable> num_workers_cleaned_up_for_testing_cv_;
// Used for testing and makes MayBlockThreshold() return the maximum
// TimeDelta.
AtomicFlag maximum_blocked_threshold_for_testing_;
// Threshold after which the max tasks is increased to compensate for a
// worker that is within a MAY_BLOCK ScopedBlockingCall.
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()
// Set at the start of JoinForTesting().
......
......@@ -25,6 +25,7 @@
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.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/scheduler_task_runner_delegate.h"
#include "base/task/task_scheduler/scheduler_worker_pool_params.h"
......@@ -1064,7 +1065,8 @@ class TaskSchedulerWorkerPoolBlockingTest
// Returns how long we can expect a change to |max_tasks_| to occur
// after a task has become blocked.
TimeDelta GetMaxTasksChangeSleepTime() {
return std::max(SchedulerWorkerPoolImpl::kBlockedWorkersPollPeriod,
return std::max(TimeDelta::FromMicroseconds(
kBlockedWorkersPollMicrosecondsParam.Get()),
worker_pool_->MayBlockThreshold()) +
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