Commit 6c14fefa authored by rvargas@google.com's avatar rvargas@google.com

Http cache: fix a bug that prevented the infinite cache simulation from saving

large data sets.

Also, go back to a limit of 200k entries, to monitor things, and increase the
version number to have clean stats after this change.

BUG=147383
TEST=none
Review URL: https://codereview.chromium.org/11415222

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170548 0039d316-1c4b-4281-b951-d872f2087c98
parent 5baa7d38
......@@ -82,10 +82,10 @@ const size_t kRecordSize = sizeof(Key) + sizeof(Details);
// Some constants related to the database file.
uint32 kMagicSignature = 0x1f00cace;
uint32 kCurrentVersion = 0x10001;
uint32 kCurrentVersion = 0x10002;
// Basic limits for the experiment.
int kMaxNumEntries = 500 * 1000;
int kMaxNumEntries = 200 * 1000;
int kMaxTrackingSize = 40 * 1024 * 1024;
// Settings that control how we generate histograms.
......@@ -604,7 +604,7 @@ void InfiniteCache::Worker::LoadData() {
base::ClosePlatformFile(file);
if (header_->disabled) {
UMA_HISTOGRAM_BOOLEAN("InfiniteCache.Full", true);
map_.clear();
InitializeData();
}
}
......@@ -639,6 +639,7 @@ void InfiniteCache::Worker::InitializeData() {
header_->magic = kMagicSignature;
header_->version = kCurrentVersion;
header_->creation_time = Time::Now().ToInternalValue();
map_.clear();
UMA_HISTOGRAM_BOOLEAN("InfiniteCache.Initialize", true);
init_ = true;
......@@ -653,7 +654,7 @@ bool InfiniteCache::Worker::ReadData(PlatformFile file) {
uint32 hash = adler32(0, Z_NULL, 0);
for (int remaining_records = header_->num_entries; remaining_records;) {
int num_records = std::min(header_->num_entries,
int num_records = std::min(remaining_records,
static_cast<int>(kMaxRecordsToRead));
size_t num_bytes = num_records * kRecordSize;
remaining_records -= num_records;
......@@ -703,7 +704,7 @@ bool InfiniteCache::Worker::WriteData(PlatformFile file) {
DCHECK_EQ(header_->num_entries, static_cast<int32>(map_.size()));
KeyMap::iterator iterator = map_.begin();
for (int remaining_records = header_->num_entries; remaining_records;) {
int num_records = std::min(header_->num_entries,
int num_records = std::min(remaining_records,
static_cast<int>(kMaxRecordsToRead));
size_t num_bytes = num_records * kRecordSize;
remaining_records -= num_records;
......@@ -804,6 +805,7 @@ void InfiniteCache::Worker::Add(const Details& details) {
int entry_size = static_cast<int>(header_->total_size / kMaxNumEntries);
UMA_HISTOGRAM_COUNTS("InfiniteCache.FinalAvgEntrySize", entry_size);
header_->disabled = 1;
header_->num_entries = 0;
map_.clear();
}
}
......
......@@ -6,6 +6,7 @@
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/stringprintf.h"
#include "base/threading/platform_thread.h"
#include "base/time.h"
#include "net/base/net_errors.h"
......@@ -245,3 +246,31 @@ TEST(InfiniteCache, DeleteBetween) {
EXPECT_EQ(1, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
#endif // OS_ANDROID
}
#if 0
// This test is too slow for the bots.
TEST(InfiniteCache, FillUp) {
base::ScopedTempDir dir;
ASSERT_TRUE(dir.CreateUniqueTempDir());
FilePath path = dir.path().Append(FILE_PATH_LITERAL("infinite"));
scoped_ptr<InfiniteCache> cache(new InfiniteCache);
cache->Init(path);
net::TestCompletionCallback cb;
const int kNumEntries = 25000;
for (int i = 0; i < kNumEntries; i++) {
std::string url = StringPrintf("http://foo.com/%d/foo.html", i);
MockTransaction transaction = kTypicalGET_Transaction;
transaction.url = url.c_str();
ProcessRequest(transaction, cache.get());
}
EXPECT_EQ(kNumEntries, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
EXPECT_EQ(net::OK, cb.GetResult(cache->FlushDataForTest(cb.callback())));
cache.reset(new InfiniteCache);
cache->Init(path);
EXPECT_EQ(kNumEntries, cb.GetResult(cache->QueryItemsForTest(cb.callback())));
}
#endif
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