diff options
author | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-08 02:26:44 +0000 |
---|---|---|
committer | tzik@chromium.org <tzik@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-08 02:26:44 +0000 |
commit | 8eee1b6b86d1e48bb3379de74f19648d2805eb0b (patch) | |
tree | 3ccfb8b4e9735813e2786ab33e392241b268d2e5 /webkit/fileapi | |
parent | 4b7eba9874af8d2e9101bbe2aae4347e18a1cc37 (diff) | |
download | chromium_src-8eee1b6b86d1e48bb3379de74f19648d2805eb0b.zip chromium_src-8eee1b6b86d1e48bb3379de74f19648d2805eb0b.tar.gz chromium_src-8eee1b6b86d1e48bb3379de74f19648d2805eb0b.tar.bz2 |
Accumulate FileSystemUsageCache updates to improve write performance.
This change reduces the number of usage cache update on appending data to a file, and improves the write performance from 75.72 MB/s (σ = 23.255) to 229.238 MB/s (σ = 31.442) on a benchmark.
https://www.googledrive.com/host/0B0EZi1x_1MtFSnNRZy1nalVNdlk/append-write.html
BUG=166158
Review URL: https://codereview.chromium.org/11639037
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/fileapi')
-rw-r--r-- | webkit/fileapi/local_file_system_quota_unittest.cc | 1 | ||||
-rw-r--r-- | webkit/fileapi/obfuscated_file_util_unittest.cc | 2 | ||||
-rw-r--r-- | webkit/fileapi/sandbox_quota_observer.cc | 50 | ||||
-rw-r--r-- | webkit/fileapi/sandbox_quota_observer.h | 14 |
4 files changed, 61 insertions, 6 deletions
diff --git a/webkit/fileapi/local_file_system_quota_unittest.cc b/webkit/fileapi/local_file_system_quota_unittest.cc index 8ba84eb..f5f8bd8 100644 --- a/webkit/fileapi/local_file_system_quota_unittest.cc +++ b/webkit/fileapi/local_file_system_quota_unittest.cc @@ -88,6 +88,7 @@ class LocalFileSystemQuotaTest } int64 SizeByQuotaUtil() { + MessageLoop::current()->RunUntilIdle(); return test_helper_.GetCachedOriginUsage(); } diff --git a/webkit/fileapi/obfuscated_file_util_unittest.cc b/webkit/fileapi/obfuscated_file_util_unittest.cc index 349ee1c..c0d3e4e 100644 --- a/webkit/fileapi/obfuscated_file_util_unittest.cc +++ b/webkit/fileapi/obfuscated_file_util_unittest.cc @@ -229,6 +229,7 @@ class ObfuscatedFileUtilTest : public testing::Test { } int64 SizeInUsageFile() { + MessageLoop::current()->RunUntilIdle(); return FileSystemUsageCache::GetUsage(test_helper_.GetUsageCachePath()); } @@ -353,6 +354,7 @@ class ObfuscatedFileUtilTest : public testing::Test { expected_usage_(expected_usage) {} ~UsageVerifyHelper() { + MessageLoop::current()->RunUntilIdle(); Check(); } diff --git a/webkit/fileapi/sandbox_quota_observer.cc b/webkit/fileapi/sandbox_quota_observer.cc index 29e1102..ec24d37 100644 --- a/webkit/fileapi/sandbox_quota_observer.cc +++ b/webkit/fileapi/sandbox_quota_observer.cc @@ -20,7 +20,9 @@ SandboxQuotaObserver::SandboxQuotaObserver( ObfuscatedFileUtil* sandbox_file_util) : quota_manager_proxy_(quota_manager_proxy), update_notify_runner_(update_notify_runner), - sandbox_file_util_(sandbox_file_util) {} + sandbox_file_util_(sandbox_file_util), + running_delayed_cache_update_(false), + weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {} SandboxQuotaObserver::~SandboxQuotaObserver() {} @@ -37,11 +39,7 @@ void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, int64 delta) { DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); - FilePath usage_file_path = GetUsageCachePath(url); - if (usage_file_path.empty()) - return; - if (delta != 0) - FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta); + if (quota_manager_proxy_) { quota_manager_proxy_->NotifyStorageModified( quota::QuotaClient::kFileSystem, @@ -49,14 +47,35 @@ void SandboxQuotaObserver::OnUpdate(const FileSystemURL& url, FileSystemTypeToQuotaStorageType(url.type()), delta); } + + FilePath usage_file_path = GetUsageCachePath(url); + if (usage_file_path.empty()) + return; + + pending_update_notification_[usage_file_path] += delta; + if (!running_delayed_cache_update_) { + update_notify_runner_->PostTask(FROM_HERE, base::Bind( + &SandboxQuotaObserver::ApplyPendingUsageUpdate, + weak_factory_.GetWeakPtr())); + running_delayed_cache_update_ = true; + } } void SandboxQuotaObserver::OnEndUpdate(const FileSystemURL& url) { DCHECK(SandboxMountPointProvider::CanHandleType(url.type())); DCHECK(update_notify_runner_->RunsTasksOnCurrentThread()); + FilePath usage_file_path = GetUsageCachePath(url); if (usage_file_path.empty()) return; + + PendingUpdateNotificationMap::iterator found = + pending_update_notification_.find(usage_file_path); + if (found != pending_update_notification_.end()) { + UpdateUsageCacheFile(found->first, found->second); + pending_update_notification_.erase(found); + } + FileSystemUsageCache::DecrementDirty(usage_file_path); } @@ -83,4 +102,23 @@ FilePath SandboxQuotaObserver::GetUsageCachePath(const FileSystemURL& url) { return path; } +void SandboxQuotaObserver::ApplyPendingUsageUpdate() { + for (PendingUpdateNotificationMap::iterator itr = + pending_update_notification_.begin(); + itr != pending_update_notification_.end(); + ++itr) { + UpdateUsageCacheFile(itr->first, itr->second); + } + pending_update_notification_.clear(); + running_delayed_cache_update_ = false; +} + +void SandboxQuotaObserver::UpdateUsageCacheFile( + const FilePath& usage_file_path, + int64 delta) { + DCHECK(!usage_file_path.empty()); + if (!usage_file_path.empty() && delta != 0) + FileSystemUsageCache::AtomicUpdateUsageByDelta(usage_file_path, delta); +} + } // namespace fileapi diff --git a/webkit/fileapi/sandbox_quota_observer.h b/webkit/fileapi/sandbox_quota_observer.h index d2d6326..4711ec0 100644 --- a/webkit/fileapi/sandbox_quota_observer.h +++ b/webkit/fileapi/sandbox_quota_observer.h @@ -5,12 +5,16 @@ #ifndef WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ #define WEBKIT_FILEAPI_SANDBOX_QUOTA_OBSERVER_H_ +#include <map> + #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/file_path.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" #include "webkit/fileapi/file_observers.h" +#include "webkit/fileapi/file_system_url.h" namespace base { class SequencedTaskRunner; @@ -29,6 +33,8 @@ class SandboxQuotaObserver : public FileUpdateObserver, public FileAccessObserver { public: + typedef std::map<FilePath, int64> PendingUpdateNotificationMap; + SandboxQuotaObserver( quota::QuotaManagerProxy* quota_manager_proxy, base::SequencedTaskRunner* update_notify_runner, @@ -44,6 +50,9 @@ class SandboxQuotaObserver virtual void OnAccess(const FileSystemURL& url) OVERRIDE; private: + void ApplyPendingUsageUpdate(); + void UpdateUsageCacheFile(const FilePath& usage_file_path, int64 delta); + FilePath GetUsageCachePath(const FileSystemURL& url); scoped_refptr<quota::QuotaManagerProxy> quota_manager_proxy_; @@ -52,6 +61,11 @@ class SandboxQuotaObserver // Not owned; sandbox_file_util_ should have identical lifetime with this. ObfuscatedFileUtil* sandbox_file_util_; + PendingUpdateNotificationMap pending_update_notification_; + bool running_delayed_cache_update_; + + base::WeakPtrFactory<SandboxQuotaObserver> weak_factory_; + DISALLOW_COPY_AND_ASSIGN(SandboxQuotaObserver); }; |