Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 | |
|
Sami
2015/03/03 18:09:18
Nit: extra blank line.
alex clarke (OOO till 29th)
2015/03/04 11:38:06
Done.
| |
| 2 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 3 // Use of this source code is governed by a BSD-style license that can be | |
| 4 // found in the LICENSE file. | |
| 5 | |
| 6 #include "content/renderer/scheduler/task_queue_manager.h" | |
| 7 | |
| 8 #include <functional> | |
|
Sami
2015/03/03 18:09:18
I'm not sure we can use this yet. Lambdas by thems
alex clarke (OOO till 29th)
2015/03/04 11:38:06
Done.
| |
| 9 #include "base/bind.h" | |
| 10 #include "base/threading/thread.h" | |
| 11 #include "content/renderer/scheduler/task_queue_selector.h" | |
| 12 #include "testing/gmock/include/gmock/gmock.h" | |
| 13 #include "testing/perf/perf_test.h" | |
| 14 | |
| 15 namespace content { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 class SelectorForTest : public TaskQueueSelector { | |
| 20 public: | |
| 21 SelectorForTest() {} | |
| 22 | |
| 23 void RegisterWorkQueues( | |
| 24 const std::vector<const base::TaskQueue*>& work_queues) override { | |
| 25 work_queues_ = work_queues; | |
| 26 } | |
| 27 | |
| 28 bool SelectWorkQueueToService(size_t* out_queue_index) override { | |
| 29 // Choose the oldest task, if any. | |
| 30 bool found_one = false; | |
| 31 for (size_t i = 0; i < work_queues_.size(); i++) { | |
| 32 if (work_queues_[i]->empty()) | |
| 33 continue; | |
| 34 // Note: the < comparison is correct due to the fact that the PendingTask | |
| 35 // operator inverts its comparison operation in order to work well in a | |
| 36 // heap based priority queue. | |
| 37 if (!found_one || | |
| 38 work_queues_[*out_queue_index]->front() < work_queues_[i]->front()) | |
| 39 *out_queue_index = i; | |
| 40 found_one = true; | |
| 41 } | |
| 42 return found_one; | |
|
Sami
2015/03/03 18:09:18
nit: This is guaranteed to be true because the sel
alex clarke (OOO till 29th)
2015/03/04 11:38:06
Sure. I put a CHECK in there to hopefully make th
| |
| 43 } | |
| 44 | |
| 45 void AsValueInto(base::trace_event::TracedValue* state) const override {} | |
| 46 | |
| 47 private: | |
| 48 std::vector<const base::TaskQueue*> work_queues_; | |
| 49 | |
| 50 DISALLOW_COPY_AND_ASSIGN(SelectorForTest); | |
| 51 }; | |
| 52 | |
| 53 } // namespace | |
| 54 | |
| 55 class TaskQueueManagerPerfTest : public testing::Test { | |
| 56 protected: | |
| 57 void Initialize(size_t num_queues) { | |
| 58 num_queues_ = num_queues; | |
| 59 message_loop_.reset(new base::MessageLoop()); | |
| 60 selector_ = make_scoped_ptr(new SelectorForTest); | |
| 61 manager_ = make_scoped_ptr(new TaskQueueManager( | |
| 62 num_queues, message_loop_->task_runner(), selector_.get())); | |
| 63 } | |
| 64 | |
| 65 void Benchmark(const std::string& trace, std::function<void()> fn) { | |
| 66 base::TimeTicks start = base::TimeTicks::Now(); | |
| 67 base::TimeTicks now; | |
| 68 unsigned long long num_iterations = 0; | |
| 69 do { | |
| 70 fn(); | |
| 71 now = base::TimeTicks::Now(); | |
| 72 num_iterations++; | |
| 73 } while (now - start < base::TimeDelta::FromSeconds(5)); | |
| 74 perf_test::PrintResult( | |
| 75 "task", "", trace, | |
| 76 (now - start).InMicroseconds() / static_cast<double>(num_iterations), | |
| 77 "us/run", true); | |
| 78 } | |
| 79 | |
| 80 void TestTask() { | |
| 81 // Post a variable number of tasks. | |
| 82 unsigned int num_posts = 1 + sequence_number_ % 8; | |
| 83 for (unsigned int i = 0; i < num_posts; i++) { | |
| 84 if (++sequence_number_ < 10000) { | |
| 85 // Choose a queue weighted towards queue 0. | |
| 86 unsigned int queue = sequence_number_ % (num_queues_ + 1); | |
| 87 if (queue == num_queues_) { | |
| 88 queue = 0; | |
| 89 } | |
| 90 base::TimeDelta delay( | |
| 91 base::TimeDelta::FromMilliseconds(sequence_number_ % 10)); | |
|
Sami
2015/03/03 18:09:18
I think you said this takes less than a millisecon
alex clarke (OOO till 29th)
2015/03/04 11:38:06
No it takes much longer to complete than that. Pu
Sami
2015/03/04 13:00:08
We're counting tasks posted and not tasks run thou
alex clarke (OOO till 29th)
2015/03/04 16:34:20
I changed it so that it runs all. I don't see muc
| |
| 92 scoped_refptr<base::SingleThreadTaskRunner> runner = | |
| 93 manager_->TaskRunnerForQueue(queue); | |
| 94 runner->PostDelayedTask(FROM_HERE, | |
|
Sami
2015/03/03 18:09:18
I'm worried this is a little too atypical workload
alex clarke (OOO till 29th)
2015/03/04 11:38:06
50 - 200 delayed tasks are common on heavy pages l
| |
| 95 base::Bind(&TaskQueueManagerPerfTest::TestTask, | |
| 96 base::Unretained(this)), | |
| 97 delay); | |
| 98 } else { | |
| 99 message_loop_->Quit(); | |
| 100 return; | |
| 101 } | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 size_t num_queues_; | |
| 106 unsigned int sequence_number_; | |
| 107 scoped_ptr<SelectorForTest> selector_; | |
| 108 scoped_ptr<TaskQueueManager> manager_; | |
| 109 scoped_ptr<base::MessageLoop> message_loop_; | |
| 110 }; | |
| 111 | |
| 112 TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_OneQueue) { | |
| 113 Initialize(1u); | |
| 114 | |
| 115 Benchmark("post 10000 delayed tasks", [this]() { | |
|
Sami
2015/03/03 18:09:18
Could you pass in the number of task queues as a m
alex clarke (OOO till 29th)
2015/03/04 11:38:06
Done.
| |
| 116 sequence_number_ = 0; | |
| 117 TestTask(); | |
| 118 message_loop_->Run(); | |
| 119 }); | |
| 120 } | |
| 121 | |
| 122 TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_FourQueues) { | |
| 123 Initialize(4u); | |
| 124 | |
| 125 Benchmark("post 10000 delayed tasks", [this]() { | |
| 126 sequence_number_ = 0; | |
| 127 TestTask(); | |
| 128 message_loop_->Run(); | |
| 129 }); | |
| 130 } | |
| 131 | |
| 132 TEST_F(TaskQueueManagerPerfTest, RunTenThousandDelayedTasks_EightQueues) { | |
| 133 Initialize(8u); | |
| 134 | |
| 135 Benchmark("post 10000 delayed tasks", [this]() { | |
| 136 sequence_number_ = 0; | |
| 137 TestTask(); | |
| 138 message_loop_->Run(); | |
| 139 }); | |
| 140 } | |
| 141 | |
| 142 } // namespace content | |
| OLD | NEW |