Changeset 219220 in webkit


Ignore:
Timestamp:
Jul 6, 2017 2:59:33 PM (7 years ago)
Author:
Brent Fulgham
Message:

[WK2] ResourceLoadStatistics should batch its writes
https://bugs.webkit.org/show_bug.cgi?id=174111
<rdar://problem/33115894>

Reviewed by Chris Dumez.

Revise the data writing operation to only write on a specific interval (currently
set to 5 minutes).

Also make 'writeStoreToDisk' simpler to use by moving the deleting (before write) and
creating (after write) of the FileMonitor into the method, rather than requiring this
knowledge in multiple places.

Make sure that we write our statistics file out before exiting so that we do not
lose any data if we exit before the five-minute window has elapsed.

  • UIProcess/Storage/ResourceLoadStatisticsStore.cpp:

(WebKit::ResourceLoadStatisticsStore::setWritePersistentStoreCallback): Deleted.

  • UIProcess/WebResourceLoadStatisticsStore.cpp:

(WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords): Remove the stop
and start monitoring into 'writeStoreToDisk'. Also check if enough time has elapsed since
the last write to commit to disk.
(WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver): Remove the
stop and start monitoring into 'writeStoreToDisk'.
(WebKit::WebResourceLoadStatisticsStore::writeStoreToDisk): Add the stop and start monitoring
commands here, so callers don't have to know to do so.

Location:
trunk/Source/WebKit2
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r219219 r219220  
     12017-07-06  Brent Fulgham  <bfulgham@apple.com>
     2
     3        [WK2] ResourceLoadStatistics should batch its writes
     4        https://bugs.webkit.org/show_bug.cgi?id=174111
     5        <rdar://problem/33115894>
     6
     7        Reviewed by Chris Dumez.
     8
     9        Revise the data writing operation to only write on a specific interval (currently
     10        set to 5 minutes).
     11
     12        Also make 'writeStoreToDisk' simpler to use by moving the deleting (before write) and
     13        creating (after write) of the FileMonitor into the method, rather than requiring this
     14        knowledge in multiple places.
     15
     16        Make sure that we write our statistics file out before exiting so that we do not
     17        lose any data if we exit before the five-minute window has elapsed.
     18
     19        * UIProcess/Storage/ResourceLoadStatisticsStore.cpp:
     20        (WebKit::ResourceLoadStatisticsStore::setWritePersistentStoreCallback): Deleted.
     21        * UIProcess/WebResourceLoadStatisticsStore.cpp:
     22        (WebKit::WebResourceLoadStatisticsStore::processStatisticsAndDataRecords): Remove the stop
     23        and start monitoring into 'writeStoreToDisk'. Also check if enough time has elapsed since
     24        the last write to commit to disk.
     25        (WebKit::WebResourceLoadStatisticsStore::registerSharedResourceLoadObserver): Remove the
     26        stop and start monitoring into 'writeStoreToDisk'.
     27        (WebKit::WebResourceLoadStatisticsStore::writeStoreToDisk): Add the stop and start monitoring
     28        commands here, so callers don't have to know to do so.
     29
    1302017-07-06  Chris Dumez  <cdumez@apple.com>
    231
  • trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.cpp

    r219071 r219220  
    177177}
    178178   
    179 void ResourceLoadStatisticsStore::setWritePersistentStoreCallback(WTF::Function<void()>&& handler)
    180 {
    181     m_writePersistentStoreHandler = WTFMove(handler);
    182 }
    183 
    184179void ResourceLoadStatisticsStore::setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&& handler)
    185180{
  • trunk/Source/WebKit2/UIProcess/Storage/ResourceLoadStatisticsStore.h

    r219071 r219220  
    7575    void setNotificationCallback(WTF::Function<void()>&&);
    7676    void setShouldPartitionCookiesCallback(WTF::Function<void(const Vector<String>& domainsToRemove, const Vector<String>& domainsToAdd, bool clearFirst)>&&);
    77     void setWritePersistentStoreCallback(WTF::Function<void()>&&);
    7877    void setDeletePersistentStoreCallback(WTF::Function<void()>&&);
    7978    void setGrandfatherExistingWebsiteDataCallback(WTF::Function<void()>&&);
     
    108107    WTF::Function<void()> m_dataAddedHandler;
    109108    WTF::Function<void(const Vector<String>&, const Vector<String>&, bool clearFirst)> m_shouldPartitionCookiesForDomainsHandler;
    110     WTF::Function<void()> m_writePersistentStoreHandler;
    111109    WTF::Function<void()> m_grandfatherExistingWebsiteDataHandler;
    112110    WTF::Function<void()> m_deletePersistentStoreHandler;
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.cpp

    r219219 r219220  
    4141#include <wtf/MainThread.h>
    4242#include <wtf/MathExtras.h>
     43#include <wtf/MonotonicTime.h>
    4344#include <wtf/NeverDestroyed.h>
    4445#include <wtf/RunLoop.h>
     
    5960    return ResourceLoadStatistics::primaryDomain(value);
    6061}
     62
     63constexpr Seconds minimumStatisticsFileWriteInterval { 5_min };
    6164
    6265static bool notifyPagesWhenDataRecordsWereScanned = false;
     
    106109        processStatisticsAndDataRecords();
    107110    });
    108     m_resourceLoadStatisticsStore->setWritePersistentStoreCallback([this, protectedThis = makeRef(*this)] {
    109         m_statisticsQueue->dispatch([this, protectedThis = protectedThis.copyRef()] {
    110             stopMonitoringStatisticsStorage();
    111             writeStoreToDisk();
    112             startMonitoringStatisticsStorage();
    113         });
    114     });
    115111    m_resourceLoadStatisticsStore->setGrandfatherExistingWebsiteDataCallback([this, protectedThis = makeRef(*this)] {
    116112        grandfatherExistingWebsiteData();
     
    206202        }
    207203
    208         stopMonitoringStatisticsStorage();
    209 
    210         writeStoreToDisk();
    211 
    212         startMonitoringStatisticsStorage();
     204        scheduleOrWriteStoreToDisk();
    213205    });
    214206}
     
    320312{
    321313    BinarySemaphore semaphore;
    322     m_statisticsQueue->dispatch([&semaphore] {
     314    m_statisticsQueue->dispatch([&semaphore, this, protectedThis = makeRef(*this)] {
     315        // Write final file state to disk.
     316        if (m_didScheduleWrite)
     317            writeStoreToDisk();
     318
    323319        // Make sure any ongoing work in our queue is finished before we terminate.
    324320        semaphore.signal();
     
    346342    ASSERT(!RunLoop::isMain());
    347343   
     344    stopMonitoringStatisticsStorage();
     345
    348346    syncWithExistingStatisticsStorageIfNeeded();
    349347
     
    354352
    355353    m_lastStatisticsFileSyncTime = WallTime::now();
     354    m_lastStatisticsWriteTime = MonotonicTime::now();
     355
     356    startMonitoringStatisticsStorage();
     357    m_didScheduleWrite = false;
     358}
     359
     360void WebResourceLoadStatisticsStore::scheduleOrWriteStoreToDisk()
     361{
     362    ASSERT(!RunLoop::isMain());
     363
     364    auto timeSinceLastWrite = MonotonicTime::now() - m_lastStatisticsWriteTime;
     365    if (timeSinceLastWrite < minimumStatisticsFileWriteInterval) {
     366        if (!m_didScheduleWrite) {
     367            m_didScheduleWrite = true;
     368            Seconds delayUntil = minimumStatisticsFileWriteInterval - timeSinceLastWrite + 1_s;
     369            m_statisticsQueue->dispatchAfter(delayUntil, [this, protectedThis = makeRef(*this)] {
     370                writeStoreToDisk();
     371            });
     372        }
     373        return;
     374    }
     375
     376    writeStoreToDisk();
    356377}
    357378
  • trunk/Source/WebKit2/UIProcess/WebResourceLoadStatisticsStore.h

    r219219 r219220  
    4141
    4242namespace WTF {
     43class MonotonicTime;
    4344class WallTime;
    4445class WorkQueue;
     
    4647
    4748namespace WebCore {
     49class FileMonitor;
    4850class KeyedDecoder;
    4951class KeyedEncoder;
    50 class FileMonitor;
    5152struct ResourceLoadStatistics;
    5253}
     
    123124
    124125    void writeStoreToDisk();
     126    void scheduleOrWriteStoreToDisk();
    125127    void writeEncoderToDisk(WebCore::KeyedEncoder&, const String& path) const;
    126128    std::unique_ptr<WebCore::KeyedDecoder> createDecoderFromDisk(const String& path) const;
     
    149151    const String m_statisticsStoragePath;
    150152    WTF::WallTime m_lastStatisticsFileSyncTime;
     153    WTF::MonotonicTime m_lastStatisticsWriteTime;
    151154    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryOneShotTimer;
    152155    RunLoop::Timer<WebResourceLoadStatisticsStore> m_telemetryRepeatedTimer;
     156    bool m_didScheduleWrite { false };
    153157};
    154158
Note: See TracChangeset for help on using the changeset viewer.