Data Block Copy Question
-
I have a quick question. I have a data backup program that reads source files in QByteArray blocks of at most 1,000,000 bytes in size. Might I be able to irk out more performance by using a smaller or larger block size? Does it depend on the source and target media and/or the file size?
Thanks! -
Hi,
You should do benchmarks.
Speed depends on:
- device type (Hard Drive, SSD, Flash, NAND, MMC, etc.)
- bus type (USB, FireWire, ATA, SATA, etc.)
- storage technology (RAID0-5, JBOD, etc.)
- File system type (ext2,3,4, ReiserFS, ZFS, exFAT, APFS, HFS+, etc)
- System load
- Network load if using a NAS
-
Yes they will but it will also depend on your file system. Having lots of small files means that you will have more IOCTL calls to open and close the files so more "times lost" there.
-
@Crag_Hack said in Data Block Copy Question:
I need to track progress so have to use block by block.
UNTESTED
#include <QCoreApplication> #include <QTimer> #include <QFile> #include <QFileInfo> #include <QFuture> #include <QDebug> #include <QFutureWatcher> #include <QtConcurrent> int main(int argc, char *argv[]) { QCoreApplication a(argc,argv); QTimer progressTimer; const QString source("mySourceFile.dat"); const QString destination("myDestFile.dat"); const qint64 sourceSize = QFileInfo(source).size(); QEventLoop pauser; QFutureWatcher<void> signaler; QObject::connect(&signaler,&QFutureWatcher<void>::finished,&pauser,&QEventLoop::quit); QFileInfo destInfo(destination); QObject::connect(&progressTimer,&QTimer::timeout,[&destInfo,&sourceSize]()->void{ destInfo.refresh(); qDebug() << "Progress: " << static_cast<qint64>(100)*destInfo.size()/sourceSize << "%"; }); const QFuture<void> future = QtConcurrent::run(std::bind(&QFile::copy,source,destination)); signaler.setFuture(future); progressTimer.start(50); pauser.exec(); progressTimer.stop(); return 0; }
-
@Crag_Hack said in Data Block Copy Question:
I need to track progress so have to use block by block.
UNTESTED
#include <QCoreApplication> #include <QTimer> #include <QFile> #include <QFileInfo> #include <QFuture> #include <QDebug> #include <QFutureWatcher> #include <QtConcurrent> int main(int argc, char *argv[]) { QCoreApplication a(argc,argv); QTimer progressTimer; const QString source("mySourceFile.dat"); const QString destination("myDestFile.dat"); const qint64 sourceSize = QFileInfo(source).size(); QEventLoop pauser; QFutureWatcher<void> signaler; QObject::connect(&signaler,&QFutureWatcher<void>::finished,&pauser,&QEventLoop::quit); QFileInfo destInfo(destination); QObject::connect(&progressTimer,&QTimer::timeout,[&destInfo,&sourceSize]()->void{ destInfo.refresh(); qDebug() << "Progress: " << static_cast<qint64>(100)*destInfo.size()/sourceSize << "%"; }); const QFuture<void> future = QtConcurrent::run(std::bind(&QFile::copy,source,destination)); signaler.setFuture(future); progressTimer.start(50); pauser.exec(); progressTimer.stop(); return 0; }
Interesting approach. One could probably also monitor the file changes through
QFileSystemWatcher
instead of a timer.