Skip to content

Commit

Permalink
EIT event processing rate configurable
Browse files Browse the repository at this point in the history
The rate at which EIT events are processed in the backend is limited so
that there is always enough processing capacity for the other backend tasks.
For many years this limit is set to 20 events per 400 milliseconds.
Measuring CPU load on recent hardware shows that mythbackend can process
events at a much higher rate without a noticeable increase of CPU load.
A higher event procesing rate makes it possible to update the EPG faster.
The default value remains at 20 events but the value can now be
configured from 20 to 1000 events per 400 milliseconds.
  • Loading branch information
kmdewaal committed Jan 1, 2024
1 parent 90201f0 commit ee18fbc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
21 changes: 15 additions & 6 deletions mythtv/libs/libmythtv/eithelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
#include "programdata.h"
#include "scheduledrecording.h" // for ScheduledRecording

const uint EITHelper::kChunkSize = 20;
const uint EITHelper::kMaxSize = 1000;
const uint EITHelper::kMaxQueueSize = 10000;

EITCache *EITHelper::s_eitCache = new EITCache();

Expand All @@ -40,6 +39,13 @@ static void init_fixup(FixupMap &fix);
EITHelper::EITHelper(uint cardnum) :
m_cardnum(cardnum)
{
m_chunkSize = gCoreContext->GetNumSetting("EITEventChunkSize", 20);
m_queueSize = std::min(m_chunkSize * 50, kMaxQueueSize);

LOG(VB_EIT, LOG_INFO, LOC_ID +
QString("EIThelper chunk size %1 and queue size %2 events")
.arg(m_chunkSize).arg(m_queueSize));

// Save EIT cache in database table eit_cache iff true
bool persistent = gCoreContext->GetBoolSetting("EITCachePersistent", true);
s_eitCache->SetPersistent(persistent);
Expand All @@ -63,7 +69,7 @@ uint EITHelper::GetListSize(void) const
bool EITHelper::EventQueueFull(void) const
{
uint listsize = GetListSize();
bool full = listsize > kMaxSize;
bool full = listsize > m_queueSize;
return full;
}

Expand All @@ -78,13 +84,15 @@ bool EITHelper::EventQueueFull(void) const
uint EITHelper::ProcessEvents(void)
{
QMutexLocker locker(&m_eitListLock);
uint insertCount = 0;

if (m_dbEvents.empty())
return 0;

MSqlQuery query(MSqlQuery::InitCon());
for (uint i = 0; (i < kChunkSize) && (!m_dbEvents.empty()); i++)

uint eventCount = 0;
uint insertCount = 0;
for (; (eventCount < m_chunkSize) && (!m_dbEvents.empty()); eventCount++)
{
DBEventEIT *event = m_dbEvents.dequeue();
m_eitListLock.unlock();
Expand All @@ -111,7 +119,8 @@ uint EITHelper::ProcessEvents(void)
else
{
LOG(VB_EIT, LOG_INFO, LOC_ID +
QString("Added %1 events").arg(insertCount));
QString("Added %1/%2 events, queued: %3")
.arg(insertCount).arg(eventCount).arg(m_dbEvents.size()));
}

return insertCount;
Expand Down
5 changes: 3 additions & 2 deletions mythtv/libs/libmythtv/eithelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ class EITHelper
uint m_channelid {0}; // Channel ID
QDateTime m_maxStarttime; // Latest starttime of changed events
bool m_seenEITother {false}; // If false we only reschedule the active mplex
uint m_chunkSize {20}; // Maximum number of DB inserts per ProcessEvents call
uint m_queueSize {1000}; // Maximum number of events waiting to be processed

FixupMap m_fixup;
ATSCSRCToEvents m_incompleteEvents;
Expand All @@ -159,8 +161,7 @@ class EITHelper

QMap<uint,uint> m_languagePreferences;

static const uint kChunkSize; // Maximum number of DB inserts per ProcessEvents call
static const uint kMaxSize; // Maximum number of events waiting to be processed
static const uint kMaxQueueSize; // Maximum queue size for events waiting to be processed
};

#endif // EIT_HELPER_H
9 changes: 5 additions & 4 deletions mythtv/libs/libmythtv/tv_rec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1263,14 +1263,15 @@ V4LChannel *TVRec::GetV4LChannel(void)
#endif // USING_V4L2
}

// Check if EIT is enabled for the video source connected to this input
static bool get_use_eit(uint inputid)
{
MSqlQuery query(MSqlQuery::InitCon());
query.prepare(
"SELECT SUM(useeit) "
"FROM videosource, capturecard "
"WHERE videosource.sourceid = capturecard.sourceid AND"
" capturecard.cardid = :INPUTID");
" capturecard.cardid = :INPUTID");
query.bindValue(":INPUTID", inputid);

if (!query.exec() || !query.isActive())
Expand Down Expand Up @@ -1508,7 +1509,7 @@ void TVRec::run(void)
else if (!get_use_eit(GetInputId()))
{
LOG(VB_EIT, LOG_INFO, LOC +
QString("EIT scanning disabled for all inputs connected to video source %1")
QString("EIT scanning disabled for video source %1")
.arg(GetSourceID()));
m_eitScanStartTime = MythDate::current().addYears(10);
}
Expand Down Expand Up @@ -4098,8 +4099,8 @@ MPEGStreamData *TVRec::TuningSignalCheck(void)
else
{
LOG(VB_EIT, LOG_INFO, LOC +
"EIT scanning disabled for all sources on this input.");
}
QString("EIT scanning disabled for video source %1")
.arg(GetSourceID())); }
}
}

Expand Down
15 changes: 15 additions & 0 deletions mythtv/programs/mythtv-setup/backendsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,19 @@ static GlobalSpinBoxSetting *EITScanPeriod()
return gc;
}

static GlobalSpinBoxSetting *EITEventChunkSize()
{
auto *gc = new GlobalSpinBoxSetting("EITEventChunkSize", 20, 1000, 20);
gc->setLabel(QObject::tr("EIT event chunk size"));
gc->setValue(20);
QString helpText = QObject::tr(
"Maximum number of DB inserts per ProcessEvents call. "
"This limits the rate at which EIT events are processed "
"in the backend so that there is always enough processing "
"capacity for the other backend tasks.");
gc->setHelpText(helpText);
return gc;
}

static GlobalCheckBoxSetting *EITCachePersistent()
{
Expand All @@ -430,6 +443,7 @@ static GlobalCheckBoxSetting *EITCachePersistent()
gc->setHelpText(helpText);
return gc;
}

static GlobalSpinBoxSetting *WOLbackendReconnectWaitTime()
{
auto *gc = new GlobalSpinBoxSetting("WOLbackendReconnectWaitTime", 0, 1200, 5);
Expand Down Expand Up @@ -984,6 +998,7 @@ BackendSettings::BackendSettings()
group2a1->addChild(EITTransportTimeout());
group2a1->addChild(EITCrawIdleStart());
group2a1->addChild(EITScanPeriod());
group2a1->addChild(EITEventChunkSize());
group2a1->addChild(EITCachePersistent());
addChild(group2a1);

Expand Down

0 comments on commit ee18fbc

Please sign in to comment.