写多线程性能问题log4net的FileAppender [英] Writing to a log4net FileAppender with multiple threads performance problems

查看:225
本文介绍了写多线程性能问题log4net的FileAppender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TickZoom是使用它自己的并行库和多个O / S线程的多核计算机光滑的利用率非常高的性能应用程序。

TickZoom is a very high performance app which uses it's own parallelization library and multiple O/S threads for smooth utilization of multi-core computers.

该应用程序击中瓶颈,用户需要将信息写入到从不同的O / S线程LogAppender。

The app hits a bottleneck where users need to write information to a LogAppender from separate O/S threads.

FileAppender使用MinimalLock功能,以便每个线程可以锁定和写入文件和然后释放下一个线程来写。

The FileAppender uses the MinimalLock feature so that each thread can lock and write to the file and then release it for the next thread to write.

如果MinimalLock被禁用,有关文件的log4net报告错误,被已被其他进程(线程)锁定。

If MinimalLock gets disabled, log4net reports errors about the file being already locked by another process (thread).

有关log4net的一个更好的办法来做到这一点是有一个单独的线程需要写入FileAppender和任何其他线程只是他们的信息添加到队列的照顾。

A better way for log4net to do this would be to have a single thread that takes care of writing to the FileAppender and any other threads simply add their messages to a queue.

在这种方式,MinimalLock可以被禁用,以大大提高记录的性能。

In that way, MinimalLock could be disabled to greatly improve performance of logging.

此外,应用程序做了很多的CPU密集的工作,所以它也将提高性能,使用一个单独的线程写入到文件,以便对CPU的I / O完成从不等待。

Additionally, the application does a lot of CPU intensive work so it will also improve performance to use a separate thread for writing to the file so the CPU never waits on the I/O to complete.

所以,问题是,确实已经log4net的提供此功能?如果是这样,你是怎么做到使线程写入文件?有另一种,更先进的附加器,也许?

So the question is, does log4net already offer this feature? If so, how do you do enable threaded writing to a file? Is there another, more advanced appender, perhaps?

如果不是,则由于log4net的已包裹在平台上,这使得它能够实现一个单独的线程和队列。为此,在TickZoom代码

If not, then since log4net is already wrapped in the platform, that makes it possible to implement a separate thread and queue for this purpose in the TickZoom code.

真诚,
韦恩

编辑:

由于它似乎是答案指向的可能是发展我们自己的解决方案的扩展以某种方式log4net的。他们清楚地显示log4net的不会做这种类型的事情。

Thanks it seems the answers point to developing our own solution as perhaps an extension to log4net in some way. And they clearly show log4net doesn't do this type of thing.

此外,我们才意识到,我们可能是滥用的记录系统,它主要意味着人类对于重要事件通知或调试信息可读的消息。软件输出的这个特定部分仅真正用于自动化工具,验证系统的准确度。

Furthermore, we just realized that we might be "abusing" the logging system which is mainly meant for human readable messages for notifying of important events or debugging information. This particular part of the software output is only really used for automated tools that verify the accuracy of the system.

当然,我们还可以在正常的方式使用log4net的调试,警告和这样的。

Of course, we also use log4net in the "normal" ways for debugging, warnings, and such.

但这些更像是事务日志比调试或用户通知日志。更具体地,它是不需要这些日志是直接可读的。如果需要一个浏览器的某种可以显示ASCII格式的内容。

But these are more like "transaction logs" than debug or user notification logs. More specifically, it's unnecessary for these logs to be directly human readable. If necessary a "viewer" of some sort can show the contents in ASCII form.

因此,我们将在做这些交易类型日志计划得到写入高速二进制下面的存储。

So we will plan on making these transaction-type log get written to a high speed binary storage.

感谢看起来既答案都是对发展我们自己的解决方案极大的蹭。

Thanks it seems both of the answers below were great nudges toward developing our own solution.

推荐答案

log4net的不支持您所描述的确切的情况。但是它提供了不锁,比如数据库的appender,或UDP追加程序等追加程序。这里有几个想法:

Log4net doesn't support the exact scenario you describe. It does however offer other appenders that don't lock, like the database appender, or the UDP appender. Here are a couple of ideas:


  1. 登录您的消息到消息
    队列,然后有一个读卡器(或
    几个读者)读取消息了
    队列,并将其写入日志。
    这提供了一个可靠的机制
    发送/写消息。说实话
    我不知道是否已经有一个
    MSMQ附加目的地,但写它
    自己也不会太辛苦了。

  1. Log your messages to a message queue, and then have a reader (or several readers) read messages off the queue and write them to a log. This provides a reliable mechanism to send/write messages. To be honest I don't know if there's already a MSMQ appender, but writing it yourself wouldn't be too hard.

使用的UDP附加目的地发送
消息,然后编写侦听到这些
信息并将其写入到一个文件你自己的
服务。

Use the UDP appender to send messages and then write your own service that listens to these messages and writes them to a file.

我觉得你可以在这里发现一个主题...基本上使用非阻塞追加程序中的一个(或写你自己的),并实现自己的服务从附加目的地接收消息,并将其写入文件。

I think you can detect a theme here... basically use one of the non blocking appenders (or write your own) and implement your own service that receives the messages from the appenders and writes them to a file.

这篇关于写多线程性能问题log4net的FileAppender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆