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

Side by Side Diff: net/disk_cache/disk_cache_perftest.cc

Issue 1978483004: Disk cache perf test: guard linux only flushes, add fd limit control. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@open-speeder-3
Patch Set: more windows guards Created 4 years, 7 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits>
5 #include <string> 6 #include <string>
6 7
7 #include "base/bind.h" 8 #include "base/bind.h"
8 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
9 #include "base/files/file_enumerator.h" 10 #include "base/files/file_enumerator.h"
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/hash.h" 12 #include "base/hash.h"
13 #include "base/process/process_metrics.h"
12 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
13 #include "base/test/perf_time_logger.h" 15 #include "base/test/perf_time_logger.h"
14 #include "base/test/test_file_util.h" 16 #include "base/test/test_file_util.h"
15 #include "base/threading/thread.h" 17 #include "base/threading/thread.h"
16 #include "net/base/cache_type.h" 18 #include "net/base/cache_type.h"
17 #include "net/base/io_buffer.h" 19 #include "net/base/io_buffer.h"
18 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
19 #include "net/base/test_completion_callback.h" 21 #include "net/base/test_completion_callback.h"
20 #include "net/disk_cache/blockfile/backend_impl.h" 22 #include "net/disk_cache/blockfile/backend_impl.h"
21 #include "net/disk_cache/blockfile/block_files.h" 23 #include "net/disk_cache/blockfile/block_files.h"
22 #include "net/disk_cache/disk_cache.h" 24 #include "net/disk_cache/disk_cache.h"
23 #include "net/disk_cache/disk_cache_test_base.h" 25 #include "net/disk_cache/disk_cache_test_base.h"
24 #include "net/disk_cache/disk_cache_test_util.h" 26 #include "net/disk_cache/disk_cache_test_util.h"
25 #include "testing/gtest/include/gtest/gtest.h" 27 #include "testing/gtest/include/gtest/gtest.h"
26 #include "testing/platform_test.h" 28 #include "testing/platform_test.h"
27 29
28 using base::Time; 30 using base::Time;
29 31
30 namespace { 32 namespace {
31 33
34 size_t MaybeGetMaxFds() {
35 #if defined(OS_POSIX)
36 return base::GetMaxFds();
37 #else
38 return std::numeric_limits<size_t>::max();
39 #endif
40 }
41
42 void MaybeSetFdLimit(unsigned int max_descriptors) {
43 #if defined(OS_POSIX)
44 base::SetFdLimit(max_descriptors);
45 #endif
46 }
47
32 struct TestEntry { 48 struct TestEntry {
33 std::string key; 49 std::string key;
34 int data_len; 50 int data_len;
35 }; 51 };
36 52
37 class DiskCachePerfTest : public DiskCacheTestWithCache { 53 class DiskCachePerfTest : public DiskCacheTestWithCache {
54 public:
55 DiskCachePerfTest() : saved_fd_limit_(MaybeGetMaxFds()) {
56 if (saved_fd_limit_ < kFdLimitForCacheTests)
57 MaybeSetFdLimit(kFdLimitForCacheTests);
58 }
59
60 ~DiskCachePerfTest() override {
61 if (saved_fd_limit_ < kFdLimitForCacheTests)
62 MaybeSetFdLimit(kFdLimitForCacheTests);
63 }
64
38 protected: 65 protected:
39 enum class WhatToRead { 66 enum class WhatToRead {
40 HEADERS_ONLY, 67 HEADERS_ONLY,
41 HEADERS_AND_BODY, 68 HEADERS_AND_BODY,
42 }; 69 };
43 70
44 // Helper methods for constructing tests. 71 // Helper methods for constructing tests.
45 bool TimeWrite(); 72 bool TimeWrite();
46 bool TimeRead(WhatToRead what_to_read, const char* timer_message); 73 bool TimeRead(WhatToRead what_to_read, const char* timer_message);
47 void ResetAndEvictSystemDiskCache(); 74 void ResetAndEvictSystemDiskCache();
48 75
49 // Complete perf tests. 76 // Complete perf tests.
50 void CacheBackendPerformance(); 77 void CacheBackendPerformance();
51 78
79 const size_t kFdLimitForCacheTests = 8192;
80
52 const int kNumEntries = 1000; 81 const int kNumEntries = 1000;
53 const int kHeadersSize = 200; 82 const int kHeadersSize = 200;
54 const int kBodySize = 16 * 1024 - 1; 83 const int kBodySize = 16 * 1024 - 1;
55 84
56 std::vector<TestEntry> entries_; 85 std::vector<TestEntry> entries_;
86
87 private:
88 const size_t saved_fd_limit_;
57 }; 89 };
58 90
59 // Creates num_entries on the cache, and writes 200 bytes of metadata and up 91 // Creates num_entries on the cache, and writes 200 bytes of metadata and up
60 // to kBodySize of data to each entry. 92 // to kBodySize of data to each entry.
61 bool DiskCachePerfTest::TimeWrite() { 93 bool DiskCachePerfTest::TimeWrite() {
62 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kHeadersSize)); 94 scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kHeadersSize));
63 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kBodySize)); 95 scoped_refptr<net::IOBuffer> buffer2(new net::IOBuffer(kBodySize));
64 96
65 CacheTestFillBuffer(buffer1->data(), kHeadersSize, false); 97 CacheTestFillBuffer(buffer1->data(), kHeadersSize, false);
66 CacheTestFillBuffer(buffer2->data(), kBodySize, false); 98 CacheTestFillBuffer(buffer2->data(), kBodySize, false);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 cache_.reset(); 205 cache_.reset();
174 206
175 // Flush all files in the cache out of system memory. 207 // Flush all files in the cache out of system memory.
176 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*"); 208 const base::FilePath::StringType file_pattern = FILE_PATH_LITERAL("*");
177 base::FileEnumerator enumerator(cache_path_, true /* recursive */, 209 base::FileEnumerator enumerator(cache_path_, true /* recursive */,
178 base::FileEnumerator::FILES, file_pattern); 210 base::FileEnumerator::FILES, file_pattern);
179 for (base::FilePath file_path = enumerator.Next(); !file_path.empty(); 211 for (base::FilePath file_path = enumerator.Next(); !file_path.empty();
180 file_path = enumerator.Next()) { 212 file_path = enumerator.Next()) {
181 ASSERT_TRUE(base::EvictFileFromSystemCache(file_path)); 213 ASSERT_TRUE(base::EvictFileFromSystemCache(file_path));
182 } 214 }
183 // And, cache directories. 215 #if defined(OS_LINUX)
216 // And, cache directories, on platforms where the eviction utility supports
217 // this (currently Linux only).
184 if (simple_cache_mode_) { 218 if (simple_cache_mode_) {
185 ASSERT_TRUE( 219 ASSERT_TRUE(
186 base::EvictFileFromSystemCache(cache_path_.AppendASCII("index-dir"))); 220 base::EvictFileFromSystemCache(cache_path_.AppendASCII("index-dir")));
187 } 221 }
188 ASSERT_TRUE(base::EvictFileFromSystemCache(cache_path_)); 222 ASSERT_TRUE(base::EvictFileFromSystemCache(cache_path_));
223 #endif
189 224
190 DisableFirstCleanup(); 225 DisableFirstCleanup();
191 InitCache(); 226 InitCache();
192 } 227 }
193 228
194 void DiskCachePerfTest::CacheBackendPerformance() { 229 void DiskCachePerfTest::CacheBackendPerformance() {
195 InitCache(); 230 InitCache();
196 EXPECT_TRUE(TimeWrite()); 231 EXPECT_TRUE(TimeWrite());
197 232
198 ResetAndEvictSystemDiskCache(); 233 ResetAndEvictSystemDiskCache();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 files.DeleteBlock(address[entry], false); 295 files.DeleteBlock(address[entry], false);
261 EXPECT_TRUE( 296 EXPECT_TRUE(
262 files.CreateBlock(disk_cache::RANKINGS, BlockSize(), &address[entry])); 297 files.CreateBlock(disk_cache::RANKINGS, BlockSize(), &address[entry]));
263 } 298 }
264 299
265 timer2.Done(); 300 timer2.Done();
266 base::MessageLoop::current()->RunUntilIdle(); 301 base::MessageLoop::current()->RunUntilIdle();
267 } 302 }
268 303
269 } // namespace 304 } // namespace
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698