Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: content/renderer/scheduler/task_queue_manager_perftest.cc

Issue 971393002: Adds a couple of simple micro benchmarks for the TaskQueueManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Responding to feedback Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/scheduler/task_queue_manager_perftest.cc
diff --git a/content/renderer/scheduler/task_queue_manager_perftest.cc b/content/renderer/scheduler/task_queue_manager_perftest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2e3c0c9fe196a6e6d8bff65750260ba2e1d4c869
--- /dev/null
+++ b/content/renderer/scheduler/task_queue_manager_perftest.cc
@@ -0,0 +1,141 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/scheduler/task_queue_manager.h"
+
+#include "base/bind.h"
+#include "base/threading/thread.h"
+#include "content/renderer/scheduler/task_queue_selector.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/perf/perf_test.h"
+
+namespace content {
+
+namespace {
+
+class SelectorForTest : public TaskQueueSelector {
+ public:
+ SelectorForTest() {}
+
+ void RegisterWorkQueues(
+ const std::vector<const base::TaskQueue*>& work_queues) override {
+ work_queues_ = work_queues;
+ }
+
+ bool SelectWorkQueueToService(size_t* out_queue_index) override {
+ // Choose the oldest task, if any.
+ bool found_one = false;
+ for (size_t i = 0; i < work_queues_.size(); i++) {
+ if (work_queues_[i]->empty())
+ continue;
+ // Note: the < comparison is correct due to the fact that the PendingTask
+ // operator inverts its comparison operation in order to work well in a
+ // heap based priority queue.
+ if (!found_one ||
+ work_queues_[*out_queue_index]->front() < work_queues_[i]->front())
+ *out_queue_index = i;
+ found_one = true;
+ }
+ CHECK(found_one);
+ return found_one;
+ }
+
+ void AsValueInto(base::trace_event::TracedValue* state) const override {}
+
+ private:
+ std::vector<const base::TaskQueue*> work_queues_;
+
+ DISALLOW_COPY_AND_ASSIGN(SelectorForTest);
+};
+
+} // namespace
+
+class TaskQueueManagerPerfTest : public testing::Test {
+ protected:
+ void Initialize(size_t num_queues) {
+ num_queues_ = num_queues;
+ message_loop_.reset(new base::MessageLoop());
+ selector_ = make_scoped_ptr(new SelectorForTest);
+ manager_ = make_scoped_ptr(new TaskQueueManager(
+ num_queues, message_loop_->task_runner(), selector_.get()));
+ }
+
+ void TestTask() {
Sami 2015/03/04 13:00:09 nit: TestDelayedTask() since that's what this is m
alex clarke (OOO till 29th) 2015/03/04 16:34:20 Done.
+ num_tasks_in_flight_--;
+ unsigned int max_tasks_to_post = num_tasks_to_run_ % 2 ? 1 : 10;
Sami 2015/03/04 13:00:09 How deep queues do you see in DoWork() with this a
alex clarke (OOO till 29th) 2015/03/04 16:34:20 The number of delayed tasks tasks is capped to max
Sami 2015/03/04 18:33:29 I more meant how many tasks there are pending in e
alex clarke (OOO till 29th) 2015/03/05 17:44:39 There is a maximum of 200 tasks in flight. It was
+ for (unsigned int i = 0;
+ i < max_tasks_to_post && num_tasks_in_flight_ < max_tasks_in_flight_ &&
+ num_tasks_to_run_ > 0;
+ i++) {
+ // Choose a queue weighted towards queue 0.
+ unsigned int queue = num_tasks_to_run_ % (num_queues_ + 1);
+ if (queue == num_queues_) {
+ queue = 0;
+ }
+ // Simulate a mix of short and longer delays.
+ unsigned int delay =
+ num_tasks_to_run_ % 2 ? 1 : (10 + num_tasks_to_run_ % 10);
+ scoped_refptr<base::SingleThreadTaskRunner> runner =
+ manager_->TaskRunnerForQueue(queue);
+ runner->PostDelayedTask(FROM_HERE,
+ base::Bind(&TaskQueueManagerPerfTest::TestTask,
+ base::Unretained(this)),
+ base::TimeDelta::FromMicroseconds(delay));
+ num_tasks_in_flight_++;
+ num_tasks_to_run_--;
+ }
+
+ if (num_tasks_to_run_ == 0)
+ message_loop_->Quit();
+ }
+
+ void Benchmark(const std::string& trace, unsigned int num_tasks_to_run) {
Sami 2015/03/04 13:00:09 I guess you could make this a template if you don'
alex clarke (OOO till 29th) 2015/03/04 16:34:20 Good point, but I think base::Closure is more read
Sami 2015/03/04 18:33:29 Works for me.
+ base::TimeTicks start = base::TimeTicks::Now();
+ base::TimeTicks now;
+ unsigned long long num_iterations = 0;
+ do {
+ num_tasks_in_flight_ = 1;
+ num_tasks_to_run_ = num_tasks_to_run;
+ TestTask();
+ message_loop_->Run();
+ now = base::TimeTicks::Now();
+ num_iterations++;
+ } while (now - start < base::TimeDelta::FromSeconds(5));
+ perf_test::PrintResult(
+ "task", "", trace,
+ (now - start).InMicroseconds() / static_cast<double>(num_iterations),
+ "us/run", true);
+ }
+
+ size_t num_queues_;
+ unsigned int max_tasks_in_flight_;
+ unsigned int num_tasks_in_flight_;
+ unsigned int num_tasks_to_run_;
+ scoped_ptr<SelectorForTest> selector_;
+ scoped_ptr<TaskQueueManager> manager_;
+ scoped_ptr<base::MessageLoop> message_loop_;
+};
+
+TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_OneQueue) {
+ Initialize(1u);
+
+ max_tasks_in_flight_ = 200;
+ Benchmark("post 10000 delayed tasks with one queue", 10000);
+}
+
+TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_FourQueues) {
+ Initialize(4u);
+
+ max_tasks_in_flight_ = 200;
+ Benchmark("post 10000 delayed tasks with four queues", 10000);
+}
+
+TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_EightQueues) {
+ Initialize(8u);
+
+ max_tasks_in_flight_ = 200;
+ Benchmark("post 10000 delayed tasks with eight queues", 10000);
+}
+
+} // namespace content
« no previous file with comments | « content/content_tests.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698