⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 185452 in webkit


Ignore:
Timestamp:
Jun 11, 2015, 5:05:25 AM (11 years ago)
Author:
Antti Koivisto
Message:

3% cold PLT regression from network cache on iOS
https://bugs.webkit.org/show_bug.cgi?id=145694
rdar://problem/21158245

Reviewed by Chris Dumez.

Cache does not help in cold page loads but it shouldn't' be hurting either. Write I/O needs to be toned down a bit.

  • NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:

(WebKit::NetworkCache::IOChannel::IOChannel):
(WebKit::NetworkCache::IOChannel::open):

Dispatch channels inherit their I/O priority from the target queue. Use background queue for write I/O.

  • NetworkProcess/cache/NetworkCacheStorage.cpp:

(WebKit::NetworkCache::Storage::Storage):
(WebKit::NetworkCache::Storage::dispatchPendingReadOperations):
(WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):

Only write one file at a time instead of maximum of three.

(WebKit::NetworkCache::Storage::retrieve):

For consistency with store prepend new entries here too.

(WebKit::NetworkCache::Storage::store):

Delay start of the first write operation by 1s.
Prepend instead of append to the pending write deque so retrieveFromMemory lookup finds newest entries first in case of duplicates

(WebKit::NetworkCache::Storage::traverse):

  • NetworkProcess/cache/NetworkCacheStorage.h:
Location:
trunk/Source/WebKit2
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r185448 r185452  
     12015-06-11  Antti Koivisto  <antti@apple.com>
     2
     3        3% cold PLT regression from network cache on iOS
     4        https://bugs.webkit.org/show_bug.cgi?id=145694
     5        rdar://problem/21158245
     6
     7        Reviewed by Chris Dumez.
     8
     9        Cache does not help in cold page loads but it shouldn't' be hurting either. Write I/O needs to be toned down a bit.
     10
     11        * NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm:
     12        (WebKit::NetworkCache::IOChannel::IOChannel):
     13        (WebKit::NetworkCache::IOChannel::open):
     14
     15            Dispatch channels inherit their I/O priority from the target queue. Use background queue for write I/O.
     16
     17        * NetworkProcess/cache/NetworkCacheStorage.cpp:
     18        (WebKit::NetworkCache::Storage::Storage):
     19        (WebKit::NetworkCache::Storage::dispatchPendingReadOperations):
     20        (WebKit::NetworkCache::Storage::dispatchPendingWriteOperations):
     21
     22            Only write one file at a time instead of maximum of three.
     23
     24        (WebKit::NetworkCache::Storage::retrieve):
     25
     26            For consistency with store prepend new entries here too.
     27
     28        (WebKit::NetworkCache::Storage::store):
     29
     30            Delay start of the first write operation by 1s.
     31            Prepend instead of append to the pending write deque so retrieveFromMemory lookup finds newest entries first in case of duplicates
     32
     33        (WebKit::NetworkCache::Storage::traverse):
     34        * NetworkProcess/cache/NetworkCacheStorage.h:
     35
    1362015-06-10  Yongjun Zhang  <yongjun_zhang@apple.com>
    237
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheIOChannelCocoa.mm

    r185412 r185452  
    4747    int oflag;
    4848    mode_t mode;
     49    bool useLowIOPriority = false;
    4950
    5051    switch (m_type) {
     
    5455        oflag = O_RDWR | O_CREAT | O_NONBLOCK;
    5556        mode = S_IRUSR | S_IWUSR;
     57        useLowIOPriority = true;
    5658        break;
    5759    case Type::Write:
    5860        oflag = O_WRONLY | O_NONBLOCK;
    5961        mode = S_IRUSR | S_IWUSR;
     62        useLowIOPriority = true;
    6063        break;
    6164    case Type::Read:
     
    7174    }));
    7275    ASSERT(m_dispatchIO.get());
     76
    7377    // This makes the channel read/write all data before invoking the handlers.
    7478    dispatch_io_set_low_water(m_dispatchIO.get(), std::numeric_limits<size_t>::max());
     79
     80    if (useLowIOPriority) {
     81        // The target queue of a dispatch I/O channel specifies the priority of the global queue where its I/O operations are executed.
     82        dispatch_set_target_queue(m_dispatchIO.get(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));
     83    }
    7584}
    7685
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp

    r185412 r185452  
    127127    : m_basePath(baseDirectoryPath)
    128128    , m_recordsPath(makeRecordsDirectoryPath(baseDirectoryPath))
     129    , m_writeOperationDispatchTimer(*this, &Storage::dispatchPendingWriteOperations)
    129130    , m_ioQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage", WorkQueue::Type::Concurrent))
    130131    , m_backgroundIOQueue(WorkQueue::create("com.apple.WebKit.Cache.Storage.background", WorkQueue::Type::Concurrent, WorkQueue::QOS::Background))
     
    544545        if (pendingRetrieveQueue.isEmpty())
    545546            continue;
    546         auto readOperation = pendingRetrieveQueue.takeFirst();
     547        auto readOperation = pendingRetrieveQueue.takeLast();
    547548        auto& read = *readOperation;
    548549        m_activeReadOperations.add(WTF::move(readOperation));
     
    570571    ASSERT(RunLoop::isMain());
    571572
    572     const int maximumActiveWriteOperationCount { 3 };
     573    const int maximumActiveWriteOperationCount { 1 };
    573574
    574575    while (!m_pendingWriteOperations.isEmpty()) {
     
    577578            return;
    578579        }
    579         auto writeOperation = m_pendingWriteOperations.takeFirst();
     580        auto writeOperation = m_pendingWriteOperations.takeLast();
    580581        auto& write = *writeOperation;
    581582        m_activeWriteOperations.add(WTF::move(writeOperation));
     
    660661        return;
    661662
    662     m_pendingReadOperationsByPriority[priority].append(new ReadOperation { key, WTF::move(completionHandler) } );
     663    m_pendingReadOperationsByPriority[priority].prepend(new ReadOperation { key, WTF::move(completionHandler) } );
    663664    dispatchPendingReadOperations();
    664665}
     
    672673        return;
    673674
    674     m_pendingWriteOperations.append(new WriteOperation { record, WTF::move(mappedBodyHandler) });
     675    m_pendingWriteOperations.prepend(new WriteOperation { record, WTF::move(mappedBodyHandler) });
    675676
    676677    // Add key to the filter already here as we do lookups from the pending operations too.
    677678    addToRecordFilter(record.key);
    678679
    679     dispatchPendingWriteOperations();
     680    bool isInitialWrite = m_pendingWriteOperations.size() == 1;
     681    if (!isInitialWrite)
     682        return;
     683
     684    // Delay the start of writes a bit to avoid affecting early page load.
     685    // Completing writes will dispatch more writes without delay.
     686    static const auto initialWriteDelay = 1_s;
     687    m_writeOperationDispatchTimer.startOneShot(initialWriteDelay);
    680688}
    681689
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.h

    r185412 r185452  
    3232#include "NetworkCacheData.h"
    3333#include "NetworkCacheKey.h"
     34#include <WebCore/Timer.h>
    3435#include <wtf/BloomFilter.h>
    3536#include <wtf/Deque.h>
     
    151152    Deque<std::unique_ptr<WriteOperation>> m_pendingWriteOperations;
    152153    HashSet<std::unique_ptr<WriteOperation>> m_activeWriteOperations;
     154    WebCore::Timer m_writeOperationDispatchTimer;
    153155
    154156    Ref<WorkQueue> m_ioQueue;
Note: See TracChangeset for help on using the changeset viewer.