mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-16 11:04:01 +02:00
* Spawn a maximum of x-WORKER_THREADS threads per db-command. Prevents mass-resolving from blocking all other commands.
This commit is contained in:
@@ -19,14 +19,6 @@ Database::Database( const QString& dbname, QObject* parent )
|
||||
{
|
||||
s_instance = this;
|
||||
|
||||
for ( int i = 0; i < WORKER_THREADS; i++ )
|
||||
{
|
||||
DatabaseWorker* worker = new DatabaseWorker( m_impl, this, false );
|
||||
worker->start();
|
||||
|
||||
m_workersRO << worker;
|
||||
}
|
||||
|
||||
m_workerRW->start();
|
||||
}
|
||||
|
||||
@@ -35,7 +27,7 @@ Database::~Database()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
|
||||
qDeleteAll( m_workersRO );
|
||||
qDeleteAll( m_workers );
|
||||
delete m_workerRW;
|
||||
delete m_impl;
|
||||
}
|
||||
@@ -58,13 +50,23 @@ Database::enqueue( QSharedPointer<DatabaseCommand> lc )
|
||||
}
|
||||
else
|
||||
{
|
||||
// qDebug() << Q_FUNC_INFO << "RO" << lc->commandname();
|
||||
// find existing amount of worker threads for commandname
|
||||
// create new thread if < WORKER_THREADS
|
||||
if ( m_workers.count( lc->commandname() ) < WORKER_THREADS )
|
||||
{
|
||||
DatabaseWorker* worker = new DatabaseWorker( m_impl, this, false );
|
||||
worker->start();
|
||||
|
||||
m_workers.insertMulti( lc->commandname(), worker );
|
||||
}
|
||||
|
||||
// find thread for commandname with lowest amount of outstanding jobs and enqueue job
|
||||
int busyThreads = 0;
|
||||
DatabaseWorker* happyThread = 0;
|
||||
for ( int i = 0; i < m_workersRO.count(); i++ )
|
||||
QList< DatabaseWorker* > workers = m_workers.values( lc->commandname() );
|
||||
for ( int i = 0; i < workers.count(); i++ )
|
||||
{
|
||||
DatabaseWorker* worker = m_workersRO.at( i );
|
||||
DatabaseWorker* worker = workers.at( i );
|
||||
|
||||
if ( !worker->busy() )
|
||||
{
|
||||
@@ -83,7 +85,7 @@ Database::enqueue( QSharedPointer<DatabaseCommand> lc )
|
||||
}
|
||||
|
||||
|
||||
const QString&
|
||||
QString
|
||||
Database::dbid() const
|
||||
{
|
||||
return m_impl->dbid();
|
||||
|
@@ -29,7 +29,7 @@ public:
|
||||
explicit Database( const QString& dbname, QObject* parent = 0 );
|
||||
~Database();
|
||||
|
||||
const QString& dbid() const;
|
||||
QString dbid() const;
|
||||
const bool indexReady() const { return m_indexReady; }
|
||||
|
||||
void loadIndex();
|
||||
@@ -45,7 +45,7 @@ public slots:
|
||||
private:
|
||||
DatabaseImpl* m_impl;
|
||||
DatabaseWorker* m_workerRW;
|
||||
QList<DatabaseWorker*> m_workersRO;
|
||||
QHash< QString, DatabaseWorker* > m_workers;
|
||||
bool m_indexReady;
|
||||
|
||||
static Database* s_instance;
|
||||
|
@@ -55,7 +55,7 @@ public:
|
||||
// indexes entries from "table" where id >= pkey
|
||||
void updateSearchIndex();
|
||||
|
||||
const QString& dbid() const { return m_dbid; }
|
||||
QString dbid() const { return m_dbid; }
|
||||
|
||||
void loadIndex();
|
||||
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMutexLocker>
|
||||
#include <QTimer>
|
||||
|
||||
#include "functimeout.h"
|
||||
#include "database/database.h"
|
||||
@@ -180,8 +181,9 @@ Pipeline::shuntNext()
|
||||
q = m_queries_pending.takeFirst();
|
||||
q->setLastPipelineWeight( 101 );
|
||||
}
|
||||
|
||||
shunt( q ); // bump into next stage of pipeline (highest weights are 100)
|
||||
|
||||
if ( !q.isNull() )
|
||||
shunt( q ); // bump into next stage of pipeline (highest weights are 100)
|
||||
}
|
||||
|
||||
|
||||
@@ -192,8 +194,11 @@ Pipeline::shunt( const query_ptr& q )
|
||||
{
|
||||
qDebug() << "Query solved, pipeline aborted:" << q->toString()
|
||||
<< "numresults:" << q->results().length();
|
||||
|
||||
shuntNext();
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int lastweight = 0;
|
||||
unsigned int lasttimeout = 0;
|
||||
foreach( Resolver* r, m_resolvers )
|
||||
|
Reference in New Issue
Block a user