Log Management and Analytics

Explore the full capabilities of Log Management and Analytics powered by SolarWinds Loggly

View Product Info

FEATURES

Infrastructure Monitoring Powered by SolarWinds AppOptics

Instant visibility into servers, virtual hosts, and containerized environments

View Infrastructure Monitoring Info

Application Performance Monitoring Powered by SolarWinds AppOptics

Comprehensive, full-stack visibility, and troubleshooting

View Application Performance Monitoring Info

Digital Experience Monitoring Powered by SolarWinds Pingdom

Make your websites faster and more reliable with easy-to-use web performance and digital experience monitoring

View Digital Experience Monitoring Info

Blog Node.js

A benchmark of five Node.js logging libraries

By Lukas Rossi 30 Sep 2015

Logs are a valuable resource in analyzing application behavior and traffic. However, it’s important to choose a logging framework that is both efficient and reliable. Which Node.js logging library is the best choice for your application? This blog post compares performance and reliability among three popular debug logging libraries. It also compares performance between two popular Express request logging libraries. The goal was to measure the time required to log a large number of messages and compare the reliability of these libraries by recording message drop rates.

Libraries Tested

The following libraries were tested for DEBUG-level logging.

  1. Bunyan
  2. Log4js
  3. Winston

The following libraries were tested for HTTP request logging with Express.

  1. Express-winston
  2. Morgan

Setup and Configuration

Test Structure

Here’s how the test was performed:

Syslog (UDP and TCP) File
DEBUG Logging 100,000 DEBUG logs over 10 iterations 10,000 DEBUG logs over 100 iterations
HTTP Request Logging 100,000 requests over 10 iterations, maximum 500 concurrent connections N/A

All of the libraries were tested and compared using syslog UDP and TCP (rsyslog was used in the tests), as well as file transports for the DEBUG-level logging tests. Benchmarking with the file transport contained more iterations (with less runs per iteration) to eliminate overload. For each specific test, a total of 1 million log events was logged. Each specific test was run three times, and the results were then averaged. Log data was sent to a local server; therefore, the tests are not affected by network lag.

For the DEBUG-level logging tests, a list of prime numbers was being generated in the background to simulate a workload.

For the request logging tests, an Express app was created that returned the plain text “Hello World” when requested. The benchmark results were found using ApacheBench.

Server Hardware

All of the tests were performed on a server with burstable high frequency Intel Xeon processors and 4GiB of RAM. The Node.js processes, rsyslog, and ApacheBench were all running on this server, so there was no network latency affecting the tests.

Logging Format and Library Configuration

The standard logging format for each specific library was used for the tests. The configuration for each library was kept as close to default as possible, so keep in mind that customizing the configuration to suit your specific application may improve each library’s performance.

Many of the libraries used require additional code in order to log with syslog. The following libraries were added:

A Note on Drop Rates

Since the system was being pushed to its limits for testing purposes, the syslog drop rates seen below are greater than you should ever experience in a real-world application. Requests sent to a real-world application are normally spread out over time, which allows the system to catch up.


DEBUG Logging: Test Results

File Transport

Each library produced similar results with a file transport. Each library was able to complete an iteration in less than 500 milliseconds. Bunyan, the fastest of the three, ran 26% faster than Log4js and 34% faster than Winston. As expected with a file transport, there was a 0% drop rate for all three libraries.

1F-5NodeJs-DEBUG-FileTransport
Framework Time (ms) Drop Rate
Bunyan 282 0%
Log4js 381 0%
Winston 426 0%

 

Syslog Transport

TCP

As with UDP, Log4js is the fastest library for the TCP protocol. The tradeoff is a slight packet drop rate of less than 1%. Bunyan was the fastest library with a 0% drop rate. In addition to having the highest average time, Winston had the highest amount of fluctuation between tests.

2F-5NodeJs-DEBUG-SyslogTCP
Framework Time (ms) Drop Rate
Winston 12,210 0%
Log4js 9,022 < 1%
Bunyan 11,392 0%

 

UDP

For the UDP tests, the libraries proved to have striking differences in both efficiency and reliability. Log4js was not only the fastest library, but it also produced the smallest drop rate. Log4js ran 36% faster than Bunyan and 71% faster than Winston. Its drop rate was 16% less than Bunyan and 25% less than Winston.

3F-5NodeJs-DEBUG-SyslogUDP
Framework Time (ms) Drop Rate
Bunyan 4,769 43%
Log4js 3,537 27%
Winston 10,537 52%

 


HTTP Request Logging: Test Results

Syslog Transport

TCP

As expected with TCP, both libraries had a 0% drop rate. Morgan processed each request 56% faster than Winston, which suggests that it would be the ideal request logging library in a real-world application. The following chart shows the average time required to process each individual request.

Framework Time (ms)
Morgan 108
Winston 243

 

The following chart shows the average total request time per iteration of 100,000 requests.

Framework Time (ms) Drop Rate
Morgan 47,360 0%
Winston 91,628 0%

 

UDP

Both libraries evidenced an insignificant drop rate of less than 1%. As with TCP, Morgan runs more efficiently timewise compared to Winston. The following chart shows the average time required to process each individual request.

Framework Time (ms)
Morgan 129
Winston 163

 

The following chart shows the average total request time per iteration of 100,000 requests.

Framework Time (ms) Drop Rate
Morgan 50,002 < 1%
Winston 62,375 < 1%

 


Conclusion

When outputting debug logs to a file, the most efficient library timewise is Bunyan. When using the syslog protocol, Log4js turned out to be the fastest of the three libraries for both TCP and UDP. However, you may choose to use Bunyan over Log4js for TCP since Bunyan had a 0% drop rate. For request logging, Morgan always supersedes Winston for efficiency. With Node.js logging libraries, the tradeoff between efficiency and reliability is not always significant. As seen from the results, the most efficient library can also be the most reliable one.

The Loggly and SolarWinds trademarks, service marks, and logos are the exclusive property of SolarWinds Worldwide, LLC or its affiliates. All other trademarks are the property of their respective owners.
Lukas Rossi

Lukas Rossi Lukas Rossi is an experienced front- and back-end web designer and developer who has developed numerous mobile applications and websites. Lukas discovered an interest in web development during high school, and since then he hasn't stopped learning the latest technologies.

He is the manager of App Dimensions, a company that creates mobile apps to improve everyday life. In his free time, Lukas enjoys bike riding and various other outdoor activities. Lukas is also a contributor to the Ultimate Guide to Logging. Check out his contributions here.