写入日志文件会严重减慢应用程序的速度吗?
我正在使用 Log4Net 将日志写入文件。这会严重减慢我的申请速度吗?我知道这取决于我写入的量,但假设每秒可以写入数百个日志。
I'm using Log4Net to write logs to files. Can this serioulsy slow down my application? I know it depends on how much I'm writing away, but let's say that some hundreds of logs can be written per second.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
它会减慢您的应用程序(显然),但如果减慢符合“严重”的标准,这在很大程度上取决于您的应用程序。我认为你需要让它运行,然后决定性能是否可以接受......
It will slow down your application (obviously) but it depends a lot on your application if the slow down qualifies as "serious". I think you need to let it run and then decide if the performance is acceptable...
当然可以。可以。
正如您已经说过的,这取决于您如何编写。
如果您登录到不同的硬盘驱动器,情况会更好。如果您通过基于消息的传输进行日志记录,则可能没问题。
Of course it can.
As you already said, it depends on how you write it.
If you are logging to a different hard-drive, things will be better. If you are logging via a message based transport, you will probably be OK.
是的,可以。考虑配置至关重要,因此您可以将其配置为不写入那么多日志,这样也不会产生太多开销。
例如。
仅当需要时才会执行 ToString。
事实上,当您启用它时,您需要将日志写入磁盘 - 您对此无能为力。但通常写太多日志是没有用的,因为无论如何也没有人会读它。
Yes it can. It is crucial to consider the configuration, so you can configure it to not write that much log and then also not have much overhead.
eg.
This will execute ToString only if needed.
The fact that you need to write the log to the disk when you enabled it - you can't do much against it. But usually it is not useful to write too much log, because nobody will ever read it anyway.
“慢”不是二元属性。这与你正在做的其他事情有关。
如果您正在做的其他事情花费的挂钟时间是日志记录的 10 倍,那么日志记录会将其增加 10%: (10/10 + 1/10 = 1.1)
如果还有其他事情您正在做的事情花费的挂钟时间是日志记录的 1/9,那么日志记录会将其增加 10 倍:(1/1 + 9/1 = 10)
"Slow" is not a binary property. It's relative to what else you're doing.
If whatever else you're doing takes 10 times as much wall-clock time as the logging, then logging will increase it by 10 percent: (10/10 + 1/10 = 1.1)
If whatever else you're doing takes 1/9 as much wall-clock time as the logging, then logging will increase it by 10 times: (1/1 + 9/1 = 10)
我不确定应用程序的缓慢程度。
但我可以说,如果您每秒写入数百个日志,并且也将其写入同一个文件中,那么请确保线程同步到位,因为您不希望在多个线程尝试访问同一文件时发生崩溃。
I am not sure regarding the slowness of application.
But i can say that if you are writing hundreds of logs per second and that too into a same file then make sure that thread synchronization is in place because you dont want crashes when multiple threads try to access same file.