TL;DR
Use the blocking
branch if:
- You need Windows support
- You're an existing happy user of the
master
branch
Use the master
branch if:
- You need better performance and scaling
- Expect thousands+ of concurrent requests
- Are on linux/bsd/macos
In either case, http.zig should be deployed behind a robust reverse proxy (e.g. NGINX).
Background
http.zig was created directly as a result of async being removed from Zig. At the time most (all?) existing implementations broke and updates didn't seem forthcoming. I wrote http.zig to fill the gap.
Blocking
http.zig initially used a thread-per-connection with blocking sockets. It's simple to understand and develop and works on all platforms. Under moderate load, this version of http.zig performed well. However, under high concurrency, thread thrashing becomes a problem, memory usage is high, and latency increases. The thread_pool
option was added (as a PR, thank you) to make the performance more predictable.
This version of http.zig, previously on the master
branch, is now on the blocking
branch. If you need Windows support, are an existing happy user of http.zig, aren't overly concerned about load or malicious clients (which can largely be mitigated by using a properly configured reversed proxy), then consider using the blocking
branch. It's simpler and, relatively speaking, more battle tested.
My own concern with blocking sockets has always been exposure to real-world networking: slow and malicious clients.
Nonblocking
The master
branch now uses nonblocking sockets (epoll on linux and kqueue on BSD and MacOS). This creates a more robust server - a slow client won't impact other clients. The new timeout
configurations, while basic, can help protect http.zig from simple DOS attacks.
Your application handlers continue to be executed synchronously. This isn't efficient, but I don't see a realistic solution. We have to wait for async to be re-added to the language. At least now the performance/latency is largely a matter of the application code, as opposed to those untrustworthy clients!
Future enhancements are more likely to happen on the master
branch.