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

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

Issue 15203004: Disk cache: Reference CL for the implementation of file format version 3. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: IndexTable review Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « net/disk_cache/cache_creator.cc ('k') | net/disk_cache/disk_cache_test_base.h » ('j') | 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 <string> 5 #include <string>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/hash.h" 10 #include "base/hash.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 entry.key = GenerateKey(true); 60 entry.key = GenerateKey(true);
61 entry.data_len = rand() % kMaxSize; 61 entry.data_len = rand() % kMaxSize;
62 entries->push_back(entry); 62 entries->push_back(entry);
63 63
64 disk_cache::Entry* cache_entry; 64 disk_cache::Entry* cache_entry;
65 net::TestCompletionCallback cb; 65 net::TestCompletionCallback cb;
66 int rv = cache->CreateEntry(entry.key, &cache_entry, cb.callback()); 66 int rv = cache->CreateEntry(entry.key, &cache_entry, cb.callback());
67 if (net::OK != cb.GetResult(rv)) 67 if (net::OK != cb.GetResult(rv))
68 break; 68 break;
69 int ret = cache_entry->WriteData( 69 int ret = cache_entry->WriteData(
70 0, 0, buffer1, kSize1, 70 0, 0, buffer1.get(), kSize1,
71 base::Bind(&CallbackTest::Run, base::Unretained(&callback)), false); 71 base::Bind(&CallbackTest::Run, base::Unretained(&callback)), false);
72 if (net::ERR_IO_PENDING == ret) 72 if (net::ERR_IO_PENDING == ret)
73 expected++; 73 expected++;
74 else if (kSize1 != ret) 74 else if (kSize1 != ret)
75 break; 75 break;
76 76
77 ret = cache_entry->WriteData( 77 ret = cache_entry->WriteData(
78 1, 0, buffer2, entry.data_len, 78 1, 0, buffer2.get(), entry.data_len,
79 base::Bind(&CallbackTest::Run, base::Unretained(&callback)), false); 79 base::Bind(&CallbackTest::Run, base::Unretained(&callback)), false);
80 if (net::ERR_IO_PENDING == ret) 80 if (net::ERR_IO_PENDING == ret)
81 expected++; 81 expected++;
82 else if (entry.data_len != ret) 82 else if (entry.data_len != ret)
83 break; 83 break;
84 cache_entry->Close(); 84 cache_entry->Close();
85 } 85 }
86 86
87 helper.WaitUntilCacheIoFinished(expected); 87 helper.WaitUntilCacheIoFinished(expected);
88 timer.Done(); 88 timer.Done();
(...skipping 20 matching lines...) Expand all
109 "Read disk cache entries (warm)"; 109 "Read disk cache entries (warm)";
110 PerfTimeLogger timer(message); 110 PerfTimeLogger timer(message);
111 111
112 for (int i = 0; i < num_entries; i++) { 112 for (int i = 0; i < num_entries; i++) {
113 disk_cache::Entry* cache_entry; 113 disk_cache::Entry* cache_entry;
114 net::TestCompletionCallback cb; 114 net::TestCompletionCallback cb;
115 int rv = cache->OpenEntry(entries[i].key, &cache_entry, cb.callback()); 115 int rv = cache->OpenEntry(entries[i].key, &cache_entry, cb.callback());
116 if (net::OK != cb.GetResult(rv)) 116 if (net::OK != cb.GetResult(rv))
117 break; 117 break;
118 int ret = cache_entry->ReadData( 118 int ret = cache_entry->ReadData(
119 0, 0, buffer1, kSize1, 119 0, 0, buffer1.get(), kSize1,
120 base::Bind(&CallbackTest::Run, base::Unretained(&callback))); 120 base::Bind(&CallbackTest::Run, base::Unretained(&callback)));
121 if (net::ERR_IO_PENDING == ret) 121 if (net::ERR_IO_PENDING == ret)
122 expected++; 122 expected++;
123 else if (kSize1 != ret) 123 else if (kSize1 != ret)
124 break; 124 break;
125 125
126 ret = cache_entry->ReadData( 126 ret = cache_entry->ReadData(
127 1, 0, buffer2, entries[i].data_len, 127 1, 0, buffer2.get(), entries[i].data_len,
128 base::Bind(&CallbackTest::Run, base::Unretained(&callback))); 128 base::Bind(&CallbackTest::Run, base::Unretained(&callback)));
129 if (net::ERR_IO_PENDING == ret) 129 if (net::ERR_IO_PENDING == ret)
130 expected++; 130 expected++;
131 else if (entries[i].data_len != ret) 131 else if (entries[i].data_len != ret)
132 break; 132 break;
133 cache_entry->Close(); 133 cache_entry->Close();
134 } 134 }
135 135
136 helper.WaitUntilCacheIoFinished(expected); 136 helper.WaitUntilCacheIoFinished(expected);
137 timer.Done(); 137 timer.Done();
(...skipping 16 matching lines...) Expand all
154 for (int i = 0; i < 300000; i++) { 154 for (int i = 0; i < 300000; i++) {
155 std::string key = GenerateKey(true); 155 std::string key = GenerateKey(true);
156 base::Hash(key); 156 base::Hash(key);
157 } 157 }
158 timer.Done(); 158 timer.Done();
159 } 159 }
160 160
161 TEST_F(DiskCacheTest, CacheBackendPerformance) { 161 TEST_F(DiskCacheTest, CacheBackendPerformance) {
162 base::Thread cache_thread("CacheThread"); 162 base::Thread cache_thread("CacheThread");
163 ASSERT_TRUE(cache_thread.StartWithOptions( 163 ASSERT_TRUE(cache_thread.StartWithOptions(
164 base::Thread::Options(MessageLoop::TYPE_IO, 0))); 164 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)));
165 165
166 ASSERT_TRUE(CleanupCacheDir()); 166 ASSERT_TRUE(CleanupCacheDir());
167 net::TestCompletionCallback cb; 167 net::TestCompletionCallback cb;
168 disk_cache::Backend* cache; 168 disk_cache::Backend* cache;
169 int rv = disk_cache::CreateCacheBackend( 169 int rv = disk_cache::CreateCacheBackend(
170 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false, 170 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false,
171 cache_thread.message_loop_proxy(), NULL, &cache, cb.callback()); 171 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback());
172 172
173 ASSERT_EQ(net::OK, cb.GetResult(rv)); 173 ASSERT_EQ(net::OK, cb.GetResult(rv));
174 174
175 int seed = static_cast<int>(Time::Now().ToInternalValue()); 175 int seed = static_cast<int>(Time::Now().ToInternalValue());
176 srand(seed); 176 srand(seed);
177 177
178 TestEntries entries; 178 TestEntries entries;
179 int num_entries = 1000; 179 int num_entries = 1000;
180 180
181 EXPECT_TRUE(TimeWrite(num_entries, cache, &entries)); 181 EXPECT_TRUE(TimeWrite(num_entries, cache, &entries));
182 182
183 MessageLoop::current()->RunUntilIdle(); 183 base::MessageLoop::current()->RunUntilIdle();
184 delete cache; 184 delete cache;
185 185
186 ASSERT_TRUE(file_util::EvictFileFromSystemCache( 186 ASSERT_TRUE(file_util::EvictFileFromSystemCache(
187 cache_path_.AppendASCII("index"))); 187 cache_path_.AppendASCII("index")));
188 ASSERT_TRUE(file_util::EvictFileFromSystemCache( 188 ASSERT_TRUE(file_util::EvictFileFromSystemCache(
189 cache_path_.AppendASCII("data_0"))); 189 cache_path_.AppendASCII("data_0")));
190 ASSERT_TRUE(file_util::EvictFileFromSystemCache( 190 ASSERT_TRUE(file_util::EvictFileFromSystemCache(
191 cache_path_.AppendASCII("data_1"))); 191 cache_path_.AppendASCII("data_1")));
192 ASSERT_TRUE(file_util::EvictFileFromSystemCache( 192 ASSERT_TRUE(file_util::EvictFileFromSystemCache(
193 cache_path_.AppendASCII("data_2"))); 193 cache_path_.AppendASCII("data_2")));
194 ASSERT_TRUE(file_util::EvictFileFromSystemCache( 194 ASSERT_TRUE(file_util::EvictFileFromSystemCache(
195 cache_path_.AppendASCII("data_3"))); 195 cache_path_.AppendASCII("data_3")));
196 196
197 rv = disk_cache::CreateCacheBackend( 197 rv = disk_cache::CreateCacheBackend(
198 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false, 198 net::DISK_CACHE, net::CACHE_BACKEND_BLOCKFILE, cache_path_, 0, false,
199 cache_thread.message_loop_proxy(), 199 cache_thread.message_loop_proxy().get(), NULL, &cache, cb.callback());
200 NULL, &cache, cb.callback());
201 ASSERT_EQ(net::OK, cb.GetResult(rv)); 200 ASSERT_EQ(net::OK, cb.GetResult(rv));
202 201
203 EXPECT_TRUE(TimeRead(num_entries, cache, entries, true)); 202 EXPECT_TRUE(TimeRead(num_entries, cache, entries, true));
204 203
205 EXPECT_TRUE(TimeRead(num_entries, cache, entries, false)); 204 EXPECT_TRUE(TimeRead(num_entries, cache, entries, false));
206 205
207 MessageLoop::current()->RunUntilIdle(); 206 base::MessageLoop::current()->RunUntilIdle();
208 delete cache; 207 delete cache;
209 } 208 }
210 209
211 // Creating and deleting "entries" on a block-file is something quite frequent 210 // Creating and deleting "entries" on a block-file is something quite frequent
212 // (after all, almost everything is stored on block files). The operation is 211 // (after all, almost everything is stored on block files). The operation is
213 // almost free when the file is empty, but can be expensive if the file gets 212 // almost free when the file is empty, but can be expensive if the file gets
214 // fragmented, or if we have multiple files. This test measures that scenario, 213 // fragmented, or if we have multiple files. This test measures that scenario,
215 // by using multiple, highly fragmented files. 214 // by using multiple, highly fragmented files.
216 TEST_F(DiskCacheTest, BlockFilesPerformance) { 215 TEST_F(DiskCacheTest, BlockFilesPerformance) {
217 ASSERT_TRUE(CleanupCacheDir()); 216 ASSERT_TRUE(CleanupCacheDir());
218 217
219 disk_cache::BlockFiles files(cache_path_); 218 disk_cache::BlockFiles files(cache_path_);
220 ASSERT_TRUE(files.Init(true)); 219 ASSERT_TRUE(files.Init(true, disk_cache::kFirstAdditionalBlockFile));
221 220
222 int seed = static_cast<int>(Time::Now().ToInternalValue()); 221 int seed = static_cast<int>(Time::Now().ToInternalValue());
223 srand(seed); 222 srand(seed);
224 223
225 const int kNumEntries = 60000; 224 const int kNumEntries = 60000;
226 disk_cache::Addr* address = new disk_cache::Addr[kNumEntries]; 225 disk_cache::Addr* address = new disk_cache::Addr[kNumEntries];
227 226
228 PerfTimeLogger timer1("Fill three block-files"); 227 PerfTimeLogger timer1("Fill three block-files");
229 228
230 // Fill up the 32-byte block file (use three files). 229 // Fill up the 32-byte block file (use three files).
231 for (int i = 0; i < kNumEntries; i++) { 230 for (int i = 0; i < kNumEntries; i++) {
232 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), 231 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(),
233 &address[i])); 232 &address[i]));
234 } 233 }
235 234
236 timer1.Done(); 235 timer1.Done();
237 PerfTimeLogger timer2("Create and delete blocks"); 236 PerfTimeLogger timer2("Create and delete blocks");
238 237
239 for (int i = 0; i < 200000; i++) { 238 for (int i = 0; i < 200000; i++) {
240 int entry = rand() * (kNumEntries / RAND_MAX + 1); 239 int entry = rand() * (kNumEntries / RAND_MAX + 1);
241 if (entry >= kNumEntries) 240 if (entry >= kNumEntries)
242 entry = 0; 241 entry = 0;
243 242
244 files.DeleteBlock(address[entry], false); 243 files.DeleteBlock(address[entry], false);
245 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(), 244 EXPECT_TRUE(files.CreateBlock(disk_cache::RANKINGS, BlockSize(),
246 &address[entry])); 245 &address[entry]));
247 } 246 }
248 247
249 timer2.Done(); 248 timer2.Done();
250 MessageLoop::current()->RunUntilIdle(); 249 base::MessageLoop::current()->RunUntilIdle();
251 delete[] address; 250 delete[] address;
252 } 251 }
OLDNEW
« no previous file with comments | « net/disk_cache/cache_creator.cc ('k') | net/disk_cache/disk_cache_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698