mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-17 11:30:49 +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;
|
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();
|
m_workerRW->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +27,7 @@ Database::~Database()
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
qDeleteAll( m_workersRO );
|
qDeleteAll( m_workers );
|
||||||
delete m_workerRW;
|
delete m_workerRW;
|
||||||
delete m_impl;
|
delete m_impl;
|
||||||
}
|
}
|
||||||
@@ -58,13 +50,23 @@ Database::enqueue( QSharedPointer<DatabaseCommand> lc )
|
|||||||
}
|
}
|
||||||
else
|
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;
|
int busyThreads = 0;
|
||||||
DatabaseWorker* happyThread = 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() )
|
if ( !worker->busy() )
|
||||||
{
|
{
|
||||||
@@ -83,7 +85,7 @@ Database::enqueue( QSharedPointer<DatabaseCommand> lc )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const QString&
|
QString
|
||||||
Database::dbid() const
|
Database::dbid() const
|
||||||
{
|
{
|
||||||
return m_impl->dbid();
|
return m_impl->dbid();
|
||||||
|
@@ -29,7 +29,7 @@ public:
|
|||||||
explicit Database( const QString& dbname, QObject* parent = 0 );
|
explicit Database( const QString& dbname, QObject* parent = 0 );
|
||||||
~Database();
|
~Database();
|
||||||
|
|
||||||
const QString& dbid() const;
|
QString dbid() const;
|
||||||
const bool indexReady() const { return m_indexReady; }
|
const bool indexReady() const { return m_indexReady; }
|
||||||
|
|
||||||
void loadIndex();
|
void loadIndex();
|
||||||
@@ -45,7 +45,7 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
DatabaseImpl* m_impl;
|
DatabaseImpl* m_impl;
|
||||||
DatabaseWorker* m_workerRW;
|
DatabaseWorker* m_workerRW;
|
||||||
QList<DatabaseWorker*> m_workersRO;
|
QHash< QString, DatabaseWorker* > m_workers;
|
||||||
bool m_indexReady;
|
bool m_indexReady;
|
||||||
|
|
||||||
static Database* s_instance;
|
static Database* s_instance;
|
||||||
|
@@ -55,7 +55,7 @@ public:
|
|||||||
// indexes entries from "table" where id >= pkey
|
// indexes entries from "table" where id >= pkey
|
||||||
void updateSearchIndex();
|
void updateSearchIndex();
|
||||||
|
|
||||||
const QString& dbid() const { return m_dbid; }
|
QString dbid() const { return m_dbid; }
|
||||||
|
|
||||||
void loadIndex();
|
void loadIndex();
|
||||||
|
|
||||||
|
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMutexLocker>
|
#include <QMutexLocker>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "functimeout.h"
|
#include "functimeout.h"
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
@@ -181,7 +182,8 @@ Pipeline::shuntNext()
|
|||||||
q->setLastPipelineWeight( 101 );
|
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()
|
qDebug() << "Query solved, pipeline aborted:" << q->toString()
|
||||||
<< "numresults:" << q->results().length();
|
<< "numresults:" << q->results().length();
|
||||||
|
|
||||||
|
shuntNext();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int lastweight = 0;
|
unsigned int lastweight = 0;
|
||||||
unsigned int lasttimeout = 0;
|
unsigned int lasttimeout = 0;
|
||||||
foreach( Resolver* r, m_resolvers )
|
foreach( Resolver* r, m_resolvers )
|
||||||
|
Reference in New Issue
Block a user