From 070fd95297d8d8eb7076ea8ba0956dee74d0e4f9 Mon Sep 17 00:00:00 2001
From: "rvargas@google.com"
 <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>
Date: Wed, 22 Apr 2009 19:19:07 +0000
Subject: Disk cache: Set up a new experiment on the dev channel.

Enable the new eviction algorithm for 10% of the current
users on the dev channel.

Review URL: http://codereview.chromium.org/79064

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14229 0039d316-1c4b-4281-b951-d872f2087c98
---
 net/disk_cache/backend_impl.cc | 62 ++++++++++++++++++++++++++++++++++++------
 net/disk_cache/eviction.cc     | 32 ++++++++++++++++++++--
 net/disk_cache/eviction.h      |  1 +
 3 files changed, 85 insertions(+), 10 deletions(-)

(limited to 'net/disk_cache')

diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc
index 64955fc..51bc948 100644
--- a/net/disk_cache/backend_impl.cc
+++ b/net/disk_cache/backend_impl.cc
@@ -140,12 +140,28 @@ bool DelayedCacheCleanup(const std::wstring& full_path) {
 // should be discarded.
 bool InitExperiment(int* stored_value) {
   if (*stored_value <= 2) {
-    *stored_value = 0;
+    // Setup the new experiment.
+    srand(static_cast<int>(Time::Now().ToInternalValue()));
+    int option = rand() % 10;
+
+    // Values used by the current experiment are 5 through 8, with 8 used for
+    // empty caches (not set here).
+    if (option > 1) {
+      // 80% will be out of the experiment.
+      *stored_value = 5;
+    } else {
+      *stored_value = option + 6;
+    }
     return true;
   }
 
-  // Discard current cache for groups 3 and 4.
-  return false;
+  if (*stored_value < 5) {
+    // Discard current cache for groups 3 and 4.
+    return false;
+  }
+
+  // Current experiment already set.
+  return true;
 }
 
 }  // namespace
@@ -247,6 +263,9 @@ bool BackendImpl::Init() {
   if (data_ && !InitExperiment(&data_->header.experiment))
     return false;
 
+  if (data_->header.experiment > 6)
+    new_eviction_ = true;
+
   if (!CheckIndex()) {
     ReportError(ERR_INIT_FAILED);
     return false;
@@ -757,6 +776,19 @@ void BackendImpl::FirstEviction() {
   int large_entries_bytes = stats_.GetLargeEntriesSize();
   int large_ratio = large_entries_bytes * 100 / data_->header.num_bytes;
   CACHE_UMA(PERCENTAGE, "FirstLargeEntriesRatio", 0, large_ratio);
+
+  if (data_->header.experiment == 8) {
+    CACHE_UMA(PERCENTAGE, "FirstResurrectRatio", 8, stats_.GetResurrectRatio());
+    CACHE_UMA(PERCENTAGE, "FirstNoUseRatio", 8,
+              data_->header.lru.sizes[0] / data_->header.num_entries);
+    CACHE_UMA(PERCENTAGE, "FirstLowUseRatio", 8,
+              data_->header.lru.sizes[1] / data_->header.num_entries);
+    CACHE_UMA(PERCENTAGE, "FirstHighUseRatio", 8,
+              data_->header.lru.sizes[2] / data_->header.num_entries);
+    CACHE_UMA(PERCENTAGE, "FirstDeletedRatio", 8,
+              data_->header.lru.sizes[4] / data_->header.num_entries);
+  }
+
   stats_.ResetRatios();
 }
 
@@ -868,9 +900,10 @@ bool BackendImpl::CreateBackingStore(disk_cache::File* file) {
   IndexHeader header;
   header.table_len = DesiredIndexTableLen(max_size_);
 
+  // New caches will go to group 8 on this experiment.
+  header.experiment = 8;
   // We need file version 2.1 for the new eviction algorithm.
-  if (new_eviction_)
-    header.version = 0x20001;
+  header.version = 0x20001;
 
   header.create_time = Time::Now().ToInternalValue();
 
@@ -1332,19 +1365,32 @@ void BackendImpl::ReportStats() {
     return;
 
   CACHE_UMA(HOURS, "UseTime", 0, static_cast<int>(use_hours));
-  CACHE_UMA(PERCENTAGE, "HitRatio", 0, stats_.GetHitRatio());
-  CACHE_UMA(PERCENTAGE, "ResurrectRatio", 0, stats_.GetResurrectRatio());
+  CACHE_UMA(PERCENTAGE, "HitRatio", data_->header.experiment,
+            stats_.GetHitRatio());
 
   int64 trim_rate = stats_.GetCounter(Stats::TRIM_ENTRY) / use_hours;
   CACHE_UMA(COUNTS, "TrimRate", 0, static_cast<int>(trim_rate));
 
   int avg_size = data_->header.num_bytes / GetEntryCount();
-  CACHE_UMA(COUNTS, "EntrySize", 0, avg_size);
+  CACHE_UMA(COUNTS, "EntrySize", data_->header.experiment, avg_size);
 
   int large_entries_bytes = stats_.GetLargeEntriesSize();
   int large_ratio = large_entries_bytes * 100 / data_->header.num_bytes;
   CACHE_UMA(PERCENTAGE, "LargeEntriesRatio", 0, large_ratio);
 
+  if (new_eviction_) {
+    CACHE_UMA(PERCENTAGE, "ResurrectRatio", data_->header.experiment,
+              stats_.GetResurrectRatio());
+    CACHE_UMA(PERCENTAGE, "NoUseRatio", data_->header.experiment,
+              data_->header.lru.sizes[0] / data_->header.num_entries);
+    CACHE_UMA(PERCENTAGE, "LowUseRatio", data_->header.experiment,
+              data_->header.lru.sizes[1] / data_->header.num_entries);
+    CACHE_UMA(PERCENTAGE, "HighUseRatio", data_->header.experiment,
+              data_->header.lru.sizes[2] / data_->header.num_entries);
+    CACHE_UMA(PERCENTAGE, "DeletedRatio", data_->header.experiment,
+              data_->header.lru.sizes[4] / data_->header.num_entries);
+  }
+
   stats_.ResetRatios();
   stats_.SetCounter(Stats::TRIM_ENTRY, 0);
 }
diff --git a/net/disk_cache/eviction.cc b/net/disk_cache/eviction.cc
index bae1e3a..b13361f 100644
--- a/net/disk_cache/eviction.cc
+++ b/net/disk_cache/eviction.cc
@@ -143,6 +143,7 @@ void Eviction::ReportTrimTimes(EntryImpl* entry) {
     first_trim_ = false;
     if (backend_->ShouldReportAgain()) {
       CACHE_UMA(AGE, "TrimAge", 0, entry->GetLastUsed());
+      ReportListStats();
     }
 
     if (header_->create_time && !header_->lru.filled) {
@@ -219,8 +220,8 @@ void Eviction::TrimCacheV2(bool empty) {
     // Make sure that frequently used items are kept for a minimum time; we know
     // that this entry is not older than its current target, but it must be at
     // least older than the target for list 0 (kTargetTime).
-    if (Rankings::HIGH_USE == list &&
-        !NodeIsOldEnough(next[Rankings::HIGH_USE].get(), 0))
+    if ((Rankings::HIGH_USE == list || Rankings::LOW_USE == list) &&
+        !NodeIsOldEnough(next[list].get(), 0))
       list = 0;
   }
 
@@ -413,4 +414,31 @@ int Eviction::SelectListByLenght() {
   return 2;
 }
 
+void Eviction::ReportListStats() {
+  if (!new_eviction_)
+    return;
+
+  Rankings::ScopedRankingsBlock last1(rankings_,
+      rankings_->GetPrev(NULL, Rankings::NO_USE));
+  Rankings::ScopedRankingsBlock last2(rankings_,
+      rankings_->GetPrev(NULL, Rankings::LOW_USE));
+  Rankings::ScopedRankingsBlock last3(rankings_,
+      rankings_->GetPrev(NULL, Rankings::HIGH_USE));
+  Rankings::ScopedRankingsBlock last4(rankings_,
+      rankings_->GetPrev(NULL, Rankings::DELETED));
+
+  if (last1.get())
+    CACHE_UMA(AGE, "NoUseAge", header_->experiment,
+              Time::FromInternalValue(last1.get()->Data()->last_used));
+  if (last2.get())
+    CACHE_UMA(AGE, "LowUseAge", header_->experiment,
+              Time::FromInternalValue(last2.get()->Data()->last_used));
+  if (last3.get())
+    CACHE_UMA(AGE, "HighUseAge", header_->experiment,
+              Time::FromInternalValue(last3.get()->Data()->last_used));
+  if (last4.get())
+    CACHE_UMA(AGE, "DeletedUseAge", header_->experiment,
+              Time::FromInternalValue(last4.get()->Data()->last_used));
+}
+
 }  // namespace disk_cache
diff --git a/net/disk_cache/eviction.h b/net/disk_cache/eviction.h
index 55fbee7..6526cff 100644
--- a/net/disk_cache/eviction.h
+++ b/net/disk_cache/eviction.h
@@ -59,6 +59,7 @@ class Eviction {
 
   bool NodeIsOldEnough(CacheRankingsBlock* node, int list);
   int SelectListByLenght();
+  void ReportListStats();
 
   BackendImpl* backend_;
   Rankings* rankings_;
-- 
cgit v1.1