* limit messages queue to ideal thread count

* move from QtScript to QJSEngine (first is deprecated since 5.6)
* drop unneeded includes in headers
* some changes inside queue managing
This commit is contained in:
arcan1s
2015-09-17 01:10:55 +03:00
parent 646e897058
commit 24eb548bb3
10 changed files with 64 additions and 52 deletions

View File

@ -20,7 +20,6 @@
#define AWACTIONS_H
#include <QObject>
#include <QVariant>
class QNetworkReply;

View File

@ -34,8 +34,8 @@ AWDataAggregator::AWDataAggregator(QObject *parent)
initScene();
connect(this, SIGNAL(const updateData(QHash<QString, QString>)),
this, SLOT(const dataUpdate(QHash<QString, QString>)));
connect(this, SIGNAL(updateData(const QHash<QString, QString>)),
this, SLOT(dataUpdate(const QHash<QString, QString>)));
}

View File

@ -21,10 +21,8 @@
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QHash>
#include <QObject>
#include <QPixmap>
#include <QVariant>
class AWDataAggregator : public QObject

View File

@ -20,12 +20,11 @@
#include <QtConcurrent/QtConcurrent>
#include <QDir>
#include <QInputDialog>
#include <QJSEngine>
#include <QNetworkInterface>
#include <QRegExp>
#include <QScriptEngine>
#include <QSettings>
#include <QStandardPaths>
#include <QThread>
#include "awdebug.h"
#include "awkeysaggregator.h"
@ -584,16 +583,16 @@ void AWKeys::calculateValues()
// lambdas
foreach(QString key, m_foundLambdas)
values[key] = [this](QString key) {
QScriptEngine engine;
QJSEngine engine;
// apply $this values
key.replace(QString("$this"), values[key]);
foreach(QString lambdaKey, m_foundKeys)
key.replace(QString("$%1").arg(lambdaKey), values[lambdaKey]);
qCInfo(LOG_AW) << "Expression" << key;
QScriptValue result = engine.evaluate(key);
if (engine.hasUncaughtException()) {
int line = engine.uncaughtExceptionLineNumber();
qCWarning(LOG_AW) << "Uncaught exception at line" << line << ":" << result.toString();
QJSValue result = engine.evaluate(key);
if (result.isError()) {
qCWarning(LOG_AW) << "Uncaught exception at line" << result.property("lineNumber").toInt()
<< ":" << result.toString();
return QString();
} else
return result.toString();
@ -646,8 +645,7 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
{
#ifdef BUILD_FUTURE
// check if data stream is locked
lock = ((lock) && (queue > 0));
if (lock) return;
// if ((lock = ((lock) && (queue > 0)))) return;
#endif /* BUILD_FUTURE */
qCDebug(LOG_AW);
@ -658,9 +656,11 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
if (sourceName == QString("update")) return emit(needToBeUpdated());
// drop if limits are reached
if (++queue > QUEUE_LIMIT) {
qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << QUEUE_LIMIT << ", lock";
lock = true;
// qDebug() << ++queue;
// if (queue > queueLimit) {
if (++queue > queueLimit) {
qCWarning(LOG_AW) << "Messages queue" << queue-- << "more than limits" << queueLimit;
// lock = true;
return;
}
@ -681,5 +681,9 @@ void AWKeys::setDataBySource(const QString sourceName, const QVariantMap data)
});
}
// volatile float n = 1.0;
// for (volatile float i=1.0; i<100000.0; i++)
// n *= i;
// qDebug() << queue-- << queueLimit;
queue--;
}

View File

@ -19,11 +19,11 @@
#ifndef AWKEYS_H
#define AWKEYS_H
#include <QHash>
#include <QObject>
#include <QVariant>
#include <QThread>
#include "extitemaggregator.h"
#include "version.h"
class AWDataAggregator;
@ -75,20 +75,27 @@ private:
void calculateValues();
QString parsePattern(QString pattern) const;
void setDataBySource(const QString sourceName, const QVariantMap data);
// objects
AWKeysAggregator *aggregator = nullptr;
AWDataAggregator *dataAggregator = nullptr;
bool m_wrapNewLines = false;
ExtItemAggregator<GraphicalItem> *graphicalItems = nullptr;
ExtItemAggregator<ExtQuotes> *extQuotes = nullptr;
ExtItemAggregator<ExtScript> *extScripts = nullptr;
ExtItemAggregator<ExtUpgrade> *extUpgrade = nullptr;
ExtItemAggregator<ExtWeather> *extWeather = nullptr;
// variables
QHash<QString, QStringList> m_devices;
QStringList m_foundBars, m_foundKeys, m_foundLambdas;
QString m_pattern;
QHash<QString, QString> values;
bool m_wrapNewLines = false;
// queue and stream lock properties
bool lock = false;
int queue = 0;
QString m_pattern;
QStringList m_foundBars, m_foundKeys, m_foundLambdas;
QHash<QString, QString> values;
QHash<QString, QStringList> m_devices;
// queue limit. It may be configured by using QUEUE_LIMIT cmake limit flag.
// In other hand since I'm using global thread pool, it makes sense to limit
// queue by QThread::idealThreadCount() value
const int queueLimit = QUEUE_LIMIT == 0 ? QThread::idealThreadCount() : QUEUE_LIMIT;
};

View File

@ -19,8 +19,8 @@
#ifndef AWKEYSAGGREGATOR_H
#define AWKEYSAGGREGATOR_H
#include <QHash>
#include <QObject>
#include <QVariant>
#include "version.h"