With or without log?

SianLoong
2 min readMar 16, 2023

In the production environment, we always enabled log to log down our data and error, this is to ease our application debugging and error finding in the future.

But somehow logging is pretty bad for our application performance. Is that really true? Let’s deep dive into it with a benchmark test:

Requirements

In this experiment, we have :

  • MacBook Pro with M1 Max CPU (32GB Ram)
  • Go (Fairly fast programming language)
  • An API server returns JSON record, which small data size with only 1 record, big with 100 records.
  • Jaeger is the component for tracing.

Benchmark & Result

Benchmark results

Conclusion

  • Logging is bad even with the tiny size of the message because it depends on the I/O of the machine.
  • Tracing is far better than logging.
  • Even though tracing comes with a cost, it’s just slightly expensive than the normal operation.
  • Avoid logging if possible, trace only when you required it. (For example, we trace the whole API call when it hits those critical endpoints, such as payment, refund, etc)

--

--

SianLoong

Frontend most of the time. Sometime backend. Sometime low-level.