日志策略与性能 [英] Logging strategy vs. performance

查看:255
本文介绍了日志策略与性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了能够支持大量的并发请求的Web应用程序,我想保持它的速度不够快。我现在实现一个日志策略,我会用log4net的,但是......什么,我应该怎么登录?我的意思是:

    在性能上
  1. 如何记录的影响?它是采用异步调用可能/ RECOMENDABLE记录?
  2. 最好使用一个文本文件或数据库?是否有可能做到这一点的条件?例如,默认的日志到数据库中,如果失败,则切换到一个文本文件中。
  3. 那么多线程?我应该关心的同步,当我使用log4net的?或者它是线程安全的开箱即用

在需求出现应用程序应该缓存一对夫妇的每个请求的事情,我怕的是对性能的影响。

干杯。

解决方案
  1. 这让较慢的事情 - 做一些需要比什么都不做更多的时间。通常由一个可忽略的量。不要担心。
  2. 请到一个文本文件海事组织。它们很容易移动/ grep的/ COM preSS /电子邮件等,你不担心记录到数据库中的事实数据库已关闭。有附加目的地的记录到数据库log4net的,如果你需要,虽然。
  3. ,log4net的是线程安全的。

有日志记录/跟踪是非常有价值的 - 在最起码你应该记录错误,否则你永远不知道他们。大多数日志记录API允许你打开和关闭的详细程度,你需要登陆。

不用担心性能,直到它成为一个问题。它不象你正在构建月球的火箭,并希望看到多少重量,可以通过测试它随身携带 - 这只是code,删除记录的语句充斥你的日志,并重新编译如果它成为一个问题。

I'm developing a web application that has to support lots of simultaneous requests, and I'd like to keep it fast enough. I have now to implement a logging strategy, I'm gonna use log4net, but ... what and how should I log? I mean:

  1. How logging impacts in performance? is it possible/recomendable logging using async calls?
  2. Is better use a text file or a database? Is it possible to do it conditional? for example, default log to the database, and if it fails, the switch to a text file.
  3. What about multithreading? should I care about synchronization when I use log4net? or it's thread safe out of the box?

In the requirements appear that the application should cache a couple of things per request, and I'm afraid of the performance impact of that.

Cheers.

解决方案

  1. It makes thing slower - doing something takes more time than doing nothing. Usually by a negligible amount. Don't worry about it.
  2. Log to a text file imo. They're easy to move/grep/compress/mail etc. and you don't have to worry about logging to a database the fact that the database is down. There's appenders for logging to a database for log4net if you need that though.
  3. Yes, log4net is thread safe.

Having logging/tracing is extremely valuable - at the very very least you should log errors, or you'll never know about them. Most logging apis let you turn on and off the level of detail you need logged.

Don't worry about performance until it becomes a problem. It's not like you're building moon rockets and wants to see how much weight it can carry by testing it - it's just code, remove the logging statements that flood your logs and recompile if it ever becomes a problem.

这篇关于日志策略与性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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