Commit 8eee1b6b authored by tzik@chromium.org's avatar tzik@chromium.org

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
parent 4b7eba98
......@@ -88,6 +88,7 @@ class LocalFileSystemQuotaTest
}
int64 SizeByQuotaUtil() {
MessageLoop::current()->RunUntilIdle();
return test_helper_.GetCachedOriginUsage();
}
......
......@@ -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();
}
......
......@@ -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
......@@ -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);
};
......
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