[KPhotoAlbum] (Re)building the EXIF database

Robert Krawitz rlk at alum.mit.edu
Mon Jan 18 23:08:44 GMT 2016


At least at first blush, this looks very inefficient:

void Exif::Database::insert( const DB::FileName& filename, Exiv2::ExifData data )
{
    if ( !isUsable() )
        return;

    QStringList formalList;
    Database::ElementList elms = elements();
    for( const DatabaseElement *e : elms )
    {
        formalList.append( e->queryString() );
    }

    QSqlQuery query( QString::fromLatin1( "INSERT into exif values (?, %1) " ).arg( formalList.join( QString::fromLatin1( ", " ) ) ), m_db );
    query.bindValue(  0, filename.absolute() );
    int i = 1;
    for( const DatabaseElement *e : elms )
    {
        e->bindValues( &query, i, data );
    }

    if ( !query.exec() )
        showError( query );
}

For each filename, it has to reconstruct the INSERT (which is a fixed
string), bind the values to it, and then exec the query.  I'm not
worried about the CPU consumption (which is negligible; kpa's barely
showing up on top, consuming maybe 2-5% of the CPU) as with the I/O,
which looks to be horrendously inefficient.  The relevant output I'm
getting from iostat is:

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.23    0.00    0.40    7.87    0.00   90.50

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sdb              93.60      1526.40       511.20       7632       2556

Notice how much writing it's doing, how poor the throughput is, and
how hard it's hitting the disk transactions.  No doubt I could do a
little better by storing my EXIF database on a separate disk (or an
SSD, but my collection is much too big for that to be affordable), but
that's not what kpa's set up for.  The database is presumably forcing
synchronous writes for each image's data insertion.

I'd think that using execBatch() to batch up the inserts (maybe 100
images at a time) would be a lot faster.  Thoughts, anyone?
-- 
Robert Krawitz                                     <rlk at alum.mit.edu>

***  MIT Engineers   A Proud Tradition   http://mitathletics.com  ***
Member of the League for Programming Freedom  --  http://ProgFree.org
Project lead for Gutenprint   --    http://gimp-print.sourceforge.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton



More information about the Kphotoalbum mailing list