Results 1 to 5 of 5

Thread: QNetworkAccessManager + DiskCache => use Thread?

  1. #1
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post QNetworkAccessManager + DiskCache => use Thread?

    I use QNetworkAccessManager and related classes to stream texture and geometry data from an internet server. Using this data the application renders an interactive 3D-scene. When a button is pressed I use a QTimer at 10 ms interval to update the scene. There is only one thread, besides possible internal threads of QNetworkAccessManager. It is intended to get a smooth movement, while geometry and textures popup as soon as they are available.

    To speedup the slow download from the server I'm using QNetworkDiskCache. However, when using a directory on my hard disk for caching I experience heavy lags every few seconds. This lags have a duration from 0.5 to 1 second. While I'm not sure about this, I assume this is caused by blocking disk accesses in my primary thread. To test the hypothesis I created a RAM drive and used it as cache location. Movement and animation are still not smooth, but these heavy lags are gone. (QNetworkDiskCache is the only location where I'm doing frequent disk accesses)

    => Does QNetworkDiskCache do a blocking hard disk access in the primary thread?
    => Could I solve the problem by creating my own Network-Thread which does handle everything related to QNetworkAccessManager?
    => Other suggestions?

    Thanks in advance.
    Beware of bugs in the above code; I have only proved it correct, not tried it. (Donald Knuth)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager + DiskCache => use Thread?

    In my opinion you should implement your own subclass of QAbstractNetworkCache. The problem you are having is that the disk cache needs to update its indexes which is painfull if you have lots of data cached.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager + DiskCache => use Thread?

    The problem you are having is that the disk cache needs to update its indexes which is painfull if you have lots of data cached.
    Ok, that's possible. My cache is limited to 50 MB (default) and currently contains 7346 files / 45.3 MB. If it uses an inefficient index this is indeed the problem.

    However, I checked the source code and QNetworkDiskCache seems to use just a SHA1 hash of the URL as filename. So this is a problem of the file system with too many files in a single directory, right? I will try if an updated method QNetworkDiskCachePrivate::cacheFileName(QUrl) which introduces two directory levels (first two chars from the hash) solves the problem. (Sadly the method is private...not protected....)
    Beware of bugs in the above code; I have only proved it correct, not tried it. (Donald Knuth)

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QNetworkAccessManager + DiskCache => use Thread?

    First question should be - do you need the cache to be persistent? If not then your best choice is to cache in memory.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager + DiskCache => use Thread?

    I have implemented a non-persistent cache. Runs much faster since I'm using QHash as index. Also expire() does not scan the whole cache. I'm using a QLinkedList as index for the least recently used heuristic, where each cache item stores an iterator to its position in the list. So all operations are just O(1) in average.

    Thanks
    Beware of bugs in the above code; I have only proved it correct, not tried it. (Donald Knuth)

Similar Threads

  1. Replies: 9
    Last Post: 28th November 2009, 20:31
  2. Replies: 16
    Last Post: 7th October 2009, 08:17
  3. Replies: 6
    Last Post: 29th April 2009, 18:17
  4. Main thread - worker thread communication.
    By kikapu in forum Newbie
    Replies: 25
    Last Post: 23rd May 2007, 22:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.