Skip to content

Commit

Permalink
Apply patch for fixing high CPU load and disk IO (jpnurmi#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
MAGICCC committed Feb 23, 2017
1 parent af4cdff commit dd848d4
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions clientbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@
#error The clientbuffer module requires ZNC version 1.6.0 or later.
#endif

class CClientBufferCacheJob : public CTimer
{
public:
CClientBufferCacheJob(CModule* pModule, unsigned int uInterval, unsigned int uCycles, const CString& sLabel, const CString& sDescription)
: CTimer(pModule, uInterval, uCycles, sLabel, sDescription) {}
virtual ~CClientBufferCacheJob() {}

protected:
virtual void RunJob();
};

void CClientBufferCacheJob::RunJob() {
GetModule()->SaveRegistry();
}

class CClientBufferMod : public CModule
{
public:
Expand All @@ -38,6 +53,7 @@ class CClientBufferMod : public CModule
AddCommand("AddClient", static_cast<CModCommand::ModCmdFunc>(&CClientBufferMod::OnAddClientCommand), "<identifier>", "Add a client.");
AddCommand("DelClient", static_cast<CModCommand::ModCmdFunc>(&CClientBufferMod::OnDelClientCommand), "<identifier>", "Delete a client.");
AddCommand("ListClients", static_cast<CModCommand::ModCmdFunc>(&CClientBufferMod::OnListClientsCommand), "", "List known clients.");
AddTimer(new CClientBufferCacheJob(this, 60 /* sec */, 0, "ClientBufferCache", "Periodically save ClientBuffer registry to disk"));
}

void OnAddClientCommand(const CString& line);
Expand Down Expand Up @@ -211,7 +227,7 @@ CModule::EModRet CClientBufferMod::OnPrivBufferPlayLine2(CClient& client, CStrin
// returns true if the new client was successfully written to disk
bool CClientBufferMod::AddClient(const CString& identifier)
{
return SetNV(identifier, "");
return SetNV(identifier, "", false);
}

bool CClientBufferMod::DelClient(const CString& identifier)
Expand All @@ -224,7 +240,7 @@ bool CClientBufferMod::DelClient(const CString& identifier)
}
bool success = true;
for (const CString& key : keys)
success &= DelNV(key);
success &= DelNV(key, false);
return success;
}

Expand Down Expand Up @@ -270,7 +286,7 @@ bool CClientBufferMod::SetTimestamp(const CString& identifier, const CString& ta
{
char timestamp[32];
std::snprintf(timestamp, 32, "%ld.%06ld", tv.tv_sec, tv.tv_usec);
return SetNV(identifier + "/" + target, timestamp);
return SetNV(identifier + "/" + target, timestamp, false);
}

timeval CClientBufferMod::GetTimestamp(const CString& identifier, const CString& target)
Expand Down

0 comments on commit dd848d4

Please sign in to comment.