Embedded Linux Tool: libuhttpd, A Powerful, Lightweight, and Efficient HTTP Server Library

Are you tired of bulky HTTP server libraries struggling on resource-constrained embedded Linux systems? Do you crave a lightweight, high-performance, and easily extensible HTTP server solution? Then, allow me to introduce—libuhttpd!

What is libuhttpd?

libuhttpd is a super lightweight, high-performance HTTP server library based on libev and http-parser, specifically designed for embedded Linux systems. It features a flexible architecture, clean and understandable code, and stunning performance, even surpassing Nginx in some tests! Whether building a simple web server or integrating HTTP/HTTPS services into complex embedded systems, libuhttpd can easily handle it.

Embedded Linux Tool: libuhttpd, A Powerful, Lightweight, and Efficient HTTP Server Library

The Core Advantages of libuhttpd:

1. Lightweight and High Performance: libuhttpd fully utilizes the advantages of the libev event loop to achieve efficient event handling and resource utilization. Its lightweight nature makes it very suitable for resource-constrained embedded environments, while its high performance ensures stable operation in high-concurrency scenarios. We let actual benchmark data speak for itself: under the same testing conditions, the request handling speed of libuhttpd far exceeds that of Nginx, details below.

2. Support for Multiple SSL Backends: Security is a key consideration for HTTP servers. libuhttpd supports three mainstream SSL backend libraries: OpenSSL, mbedtls, and wolfSSL, allowing you to flexibly choose based on project requirements, ensuring your server has a high level of security.

3. A Powerful Feature Set: libuhttpd is not just a simple HTTP server library. It supports IPv6, CGI, plugin extensions, large file uploads, HTTP range requests, and a multi-process model similar to Nginx, making your development more convenient and your applications more flexible.

4. Flexible and Easily Extensible: The code structure of libuhttpd is clear and simple, easy to understand and extend. You can easily add custom features and plugins to meet specific needs. This makes libuhttpd an ideal platform for learning and development.

5. Simple and Easy Build and Installation: libuhttpd uses a standard cmake build system, making the compilation and installation process simple and fast. For OpenWrt systems, a convenient opkg installation method is also provided (if opkg installation fails, you can compile it yourself).

Performance Test Comparison:

To visually demonstrate the performance of libuhttpd, we conducted a performance comparison test with Nginx using the wrk tool for stress testing:

Nginx Test Results:

Requests/sec: 161390.39
Transfer/sec:     38.32MB

libuhttpd Test Results:

Requests/sec: 281328.83
Transfer/sec:     54.46MB

The results show that under the same testing conditions, the request handling speed and data transfer speed of libuhttpd are significantly higher than those of Nginx, fully proving the outstanding performance of libuhttpd.

Dependencies of libuhttpd:

To compile and run libuhttpd smoothly, you need to install the following dependencies:

  • libev: A fully-featured and high-performance event loop library.
  • http-parser: A high-performance HTTP message parser written in C.
  • mbedtls/wolfSSL/openssl (choose one): Your choice of SSL backend library.

Quick Start Guide:

  1. Compile:
    <span>mkdir build && cd build && cmake .. && make</span>
  2. Run Example Server:
    <span>./example/simple_server -v -a :8080</span>
  3. Test with curl:
    <span>curl 'http://127.0.0.1:8080/echo' -v</span>

Conclusion:

libuhttpd is a powerful, lightweight, and efficient HTTP server library that provides an ideal solution for embedded Linux developers. Its outstanding performance, rich features, and clean code make it an ideal choice for building high-performance embedded web servers. Whether learning the principles of HTTP server implementation or building actual embedded applications, libuhttpd is an excellent project worth trying.

Project Address:https://github.com/zhaojh329/libuhttpd

Leave a Comment