Skip to content
Permalink
Browse files

Merge pull request #4209 from nyalldawson/postgres_queue_size2

Dynamically adjust postgres feature queue size
  • Loading branch information
nyalldawson committed Mar 5, 2017
2 parents 9a747de + fbe4be8 commit 5a543e44de77bf1f07eb8429356eb2c1bbd8fda8
@@ -22,15 +22,12 @@
#include "qgsmessagelog.h"
#include "qgssettings.h"

#include <QElapsedTimer>
#include <QObject>


const int QgsPostgresFeatureIterator::FEATURE_QUEUE_SIZE = 2000;


QgsPostgresFeatureIterator::QgsPostgresFeatureIterator( QgsPostgresFeatureSource *source, bool ownSource, const QgsFeatureRequest &request )
: QgsAbstractFeatureIteratorFromSource<QgsPostgresFeatureSource>( source, ownSource, request )
, mFeatureQueueSize( FEATURE_QUEUE_SIZE )
, mFeatureQueueSize( 1 )
, mFetched( 0 )
, mFetchGeometry( false )
, mExpressionCompiled( false )
@@ -223,6 +220,9 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature &feature )

if ( mFeatureQueue.empty() && !mLastFetch )
{
QElapsedTimer timer;
timer.start();

QString fetch = QStringLiteral( "FETCH FORWARD %1 FROM %2" ).arg( mFeatureQueueSize ).arg( mCursorName );
QgsDebugMsgLevel( QString( "fetching %1 features." ).arg( mFeatureQueueSize ), 4 );

@@ -258,6 +258,15 @@ bool QgsPostgresFeatureIterator::fetchFeature( QgsFeature &feature )
} // for each row in queue
}
unlock();

if ( timer.elapsed() > 500 && mFeatureQueueSize > 1 )
{
mFeatureQueueSize /= 2;
}
else if ( timer.elapsed() < 50 && mFeatureQueueSize < 10000 )
{
mFeatureQueueSize *= 2;
}
}

if ( mFeatureQueue.empty() )
@@ -110,8 +110,6 @@ class QgsPostgresFeatureIterator : public QgsAbstractFeatureIteratorFromSource<Q

bool mIsTransactionConnection;

static const int FEATURE_QUEUE_SIZE;

private:
virtual bool providerCanSimplify( QgsSimplifyMethod::MethodType methodType ) const override;

0 comments on commit 5a543e4

Please sign in to comment.
You can’t perform that action at this time.