Add a new thread pool for first index instead of using global thread pool.
This commit is contained in:
parent
aa12241e7c
commit
900b666154
|
@ -26,6 +26,8 @@
|
||||||
//#define DELETE_QUEUE(a )
|
//#define DELETE_QUEUE(a )
|
||||||
using namespace Zeeker;
|
using namespace Zeeker;
|
||||||
FirstIndex::FirstIndex() {
|
FirstIndex::FirstIndex() {
|
||||||
|
m_pool.setMaxThreadCount(2);
|
||||||
|
m_pool.setExpiryTimeout(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
FirstIndex::~FirstIndex() {
|
FirstIndex::~FirstIndex() {
|
||||||
|
@ -177,6 +179,7 @@ void FirstIndex::run() {
|
||||||
p_indexGenerator = IndexGenerator::getInstance(true, this);
|
p_indexGenerator = IndexGenerator::getInstance(true, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//TODO Fix these weird code.
|
||||||
QSemaphore sem(5);
|
QSemaphore sem(5);
|
||||||
QMutex mutex1, mutex2, mutex3;
|
QMutex mutex1, mutex2, mutex3;
|
||||||
mutex1.lock();
|
mutex1.lock();
|
||||||
|
@ -192,42 +195,41 @@ void FirstIndex::run() {
|
||||||
qDebug() << "max_index_count:" << FileUtils::_max_index_count;
|
qDebug() << "max_index_count:" << FileUtils::_max_index_count;
|
||||||
sem.release(5);
|
sem.release(5);
|
||||||
// });
|
// });
|
||||||
QtConcurrent::run([&]() {
|
QtConcurrent::run(&m_pool, [&]() {
|
||||||
sem.acquire(2);
|
sem.acquire(2);
|
||||||
mutex2.unlock();
|
mutex2.unlock();
|
||||||
qDebug() << "index start;";
|
qDebug() << "index start;";
|
||||||
QQueue<QVector<QString>>* tmp = new QQueue<QVector<QString>>();
|
QQueue<QVector<QString>>* tmp1 = new QQueue<QVector<QString>>();
|
||||||
while(!this->q_index->empty()) {
|
while(!this->q_index->empty()) {
|
||||||
for(size_t i = 0; (i < 8192) && (!this->q_index->empty()); ++i) {
|
for(size_t i = 0; (i < 8192) && (!this->q_index->empty()); ++i) {
|
||||||
tmp->enqueue(this->q_index->dequeue());
|
tmp1->enqueue(this->q_index->dequeue());
|
||||||
}
|
}
|
||||||
this->p_indexGenerator->creatAllIndex(tmp);
|
this->p_indexGenerator->creatAllIndex(tmp1);
|
||||||
tmp->clear();
|
tmp1->clear();
|
||||||
}
|
}
|
||||||
// this->p_indexGenerator->setSynonym();
|
delete tmp1;
|
||||||
delete tmp;
|
|
||||||
qDebug() << "index end;";
|
qDebug() << "index end;";
|
||||||
sem.release(2);
|
sem.release(2);
|
||||||
});
|
});
|
||||||
QtConcurrent::run([&]() {
|
QtConcurrent::run(&m_pool,[&]() {
|
||||||
sem.acquire(2);
|
sem.acquire(2);
|
||||||
mutex3.unlock();
|
mutex3.unlock();
|
||||||
QQueue<QString>* tmp = new QQueue<QString>();
|
QQueue<QString>* tmp2 = new QQueue<QString>();
|
||||||
qDebug() << "q_content_index:" << q_content_index->size();
|
qDebug() << "q_content_index:" << q_content_index->size();
|
||||||
while(!this->q_content_index->empty()) {
|
while(!this->q_content_index->empty()) {
|
||||||
// for (size_t i = 0; (i < this->u_send_length) && (!this->q_content_index->empty()); ++i){
|
// for (size_t i = 0; (i < this->u_send_length) && (!this->q_content_index->empty()); ++i){
|
||||||
qint64 fileSize = 0;
|
qint64 fileSize = 0;
|
||||||
//修改一次处理的数据量,从30个文件改为文件总大小为50M以下,50M为暂定值--jxx20210519
|
//修改一次处理的数据量,从30个文件改为文件总大小为50M以下,50M为暂定值--jxx20210519
|
||||||
for(size_t i = 0;/* (i < 30) && */(fileSize < 50*1024*1024) && (!this->q_content_index->empty()); ++i) {
|
for(size_t i = 0;/* (i < 30) && */(fileSize < 50*1024*1024) && (!this->q_content_index->empty()); ++i) {
|
||||||
QPair<QString,qint64> tempPair = this->q_content_index->dequeue();
|
QPair<QString,qint64> tempPair = this->q_content_index->dequeue();
|
||||||
fileSize += tempPair.second;
|
fileSize += tempPair.second;
|
||||||
tmp->enqueue(tempPair.first);
|
tmp2->enqueue(tempPair.first);
|
||||||
}
|
}
|
||||||
// qDebug() << ">>>>>>>>all fileSize:" << fileSize << "file num:" << tmp->size() << "<<<<<<<<<<<<<<<<<<<";
|
// qDebug() << ">>>>>>>>all fileSize:" << fileSize << "file num:" << tmp->size() << "<<<<<<<<<<<<<<<<<<<";
|
||||||
this->p_indexGenerator->creatAllIndex(tmp);
|
this->p_indexGenerator->creatAllIndex(tmp2);
|
||||||
tmp->clear();
|
tmp2->clear();
|
||||||
}
|
}
|
||||||
delete tmp;
|
delete tmp2;
|
||||||
qDebug() << "content index end;";
|
qDebug() << "content index end;";
|
||||||
sem.release(2);
|
sem.release(2);
|
||||||
});
|
});
|
||||||
|
|
|
@ -56,6 +56,7 @@ private:
|
||||||
bool bool_dataBaseStatusOK = false;
|
bool bool_dataBaseStatusOK = false;
|
||||||
bool bool_dataBaseExist = false;
|
bool bool_dataBaseExist = false;
|
||||||
IndexGenerator* p_indexGenerator = nullptr;
|
IndexGenerator* p_indexGenerator = nullptr;
|
||||||
|
QThreadPool m_pool;
|
||||||
|
|
||||||
//here should be refact
|
//here should be refact
|
||||||
// MessageListManager* mlm;
|
// MessageListManager* mlm;
|
||||||
|
|
|
@ -314,7 +314,7 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// Set threads which in global thread pool expiry time in 5ms, some prolems here
|
// Set threads which in global thread pool expiry time in 5ms, some prolems here
|
||||||
QThreadPool::globalInstance()->setExpiryTimeout(5);
|
// QThreadPool::globalInstance()->setExpiryTimeout(5);
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// First insdex start, the parameter us useless, should remove the parameter
|
// First insdex start, the parameter us useless, should remove the parameter
|
||||||
|
|
Loading…
Reference in New Issue