Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logging strategy vs. performance

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.

like image 655
vtortola Avatar asked Apr 12 '10 21:04

vtortola


People also ask

Can logging affect performance?

Logging can impact your application's performance in two ways. Firstly, the API you are using is probably creating a lot of strings in your application code which can take CPU cycles and create garbage that will need to be collected. Secondly, the logging thread(s) needs to format the string before writing it to disk.

What is performance logging?

Performance logging is designed to assist when you are troubleshooting performance issues. The reports are generated by a madconfig target and based on performance logs that are gathered by the application server.

What is a log strategy?

Logs contain critical data needed to detect threats, but not all logs are relevant when it comes to a strong detection and response strategy. A strong logging strategy can help you monitor your environment, identify threats faster, and help you determine where you can get the most value from your data.

What is difference between logging and monitoring?

Logging is a method of tracking and storing data to ensure application availability and to assess the impact of state transformations on performance. Monitoring is a diagnostic tool used for alerting DevOps to system-related issues by analyzing metrics.


1 Answers

  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.

like image 110
nos Avatar answered Oct 02 '22 12:10

nos