【发布时间】:2017-11-08 02:41:52
【问题描述】:
我正在使用 FileChannel 和 AsyncChannel 异步记录 Poco 的市场数据,这会每秒创建大量的日志条目。 Poco 似乎将每条消息单独写入文件并且不缓冲。 我相信这给我的 HDD/文件系统带来了相当大的压力,而且我遇到了我认为相关的应用程序崩溃。
有没有办法让 Poco 只以 1Mb 的增量将日志保存到磁盘,并在记录器关闭时将缓冲区中剩余的任何内容写入文件?
另外,这是否有可能创建大量线程?从我读到的 AsyncChannel 只是将消息放入队列中,所以我猜只创建了 1 个额外的线程?
以下基本上是我正在使用的代码:
#include "Poco/Message.h"
#include "Poco/FormattingChannel.h"
#include "Poco/PatternFormatter.h"
#include "Poco/Logger.h"
#include "Poco/FileChannel.h"
#include "Poco/AutoPtr.h"
#include "Poco/AsyncChannel.h"
class APocoClass
{
private:
Poco::AutoPtr<Poco::FileChannel> pFileChannel;
Poco::AutoPtr<Poco::PatternFormatter> pPF;
Poco::AutoPtr<Poco::FormattingChannel> pFormattingChannel;
Poco::AutoPtr<Poco::AsyncChannel> pFileChannelAsync;
Poco::Logger & _pocoLogger;
public:
APocoClass() :
pFileChannel(new Poco::FileChannel()),
pPF(new Poco::PatternFormatter("%Y%m%d %H:%M:%S.%F: %t")),
pFormattingChannel(new Poco::FormattingChannel(pPF, pFileChannel)),
pFileChannelAsync(new Poco::AsyncChannel(pFormattingChannel)),
_pocoLogger(Poco::Logger::create("PocoLogger", pFileChannelAsync, Poco::Message::PRIO_INFORMATION))
{
pFileChannelAsync->setProperty("priority", "lowest");
pFileChannel->setProperty("path", "MsgStorage/poco.log");
pFileChannel->setProperty("rotation", "daily");
pFileChannel->setProperty("times", "utc");
pFileChannel->setProperty("archive", "timestamp");
}
~APocoClass() {
_pocoLogger.shutdown();
_pocoLogger.close();
pFileChannelAsync = nullptr;
pFileChannel = nullptr;
}
//following is called every time we have a new market data message to log
void MessageReceived(const string & message) {
Poco::Message m("PocoLogger", message, Poco::Message::Priority::PRIO_INFORMATION);
_pocoLogger.log(m);
}
}
【问题讨论】:
标签: multithreading logging poco-libraries