Glaze vs Boost.Beast HTTP server benchmarks and optimizations#2384
Merged
stephenberry merged 17 commits intomainfrom Mar 20, 2026
Merged
Glaze vs Boost.Beast HTTP server benchmarks and optimizations#2384stephenberry merged 17 commits intomainfrom
stephenberry merged 17 commits intomainfrom
Conversation
|
Glaze is 🔥 |
|
@stephenberry, Hello! It's not entirely clear whether Glaze is faster or not. And to be honest, it would be nice to see benchmarks not against Boost.Beast, but specifically against nghttp2, cpp-httplib, and curl. It would also be great to see a comparison of the WebSocket components, particularly the client-side ones. Of all the open-source libraries, libwebsockets is the fastest (I’m not including uWebSockets, since it doesn’t have a client-side component, but for server-side it may be fastest). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Glaze vs Boost.Beast HTTP Server Performance
Adds an HTTP benchmark suite comparing Glaze's HTTP server against Boost.Beast, and optimizes Glaze's server to outperform Beast on 8 of 9 benchmarks.
Benchmark Results
HTTP Server Optimizations (
http_server.hpp)Single-pass request parser
Replaced
async_read_until+asio::streambuf+ separateprocess_request_datawithasync_read_until+ flatstd::stringbuffer + a single-pass parser (try_parse_request) that finds line boundaries and parses HTTP semantics simultaneously. Eliminates thestreambufoverhead and redundant delimiter scan.Direct socket and timer members
connection_statenow holdssocket_type socketandasio::steady_timer idle_timeras direct members instead ofshared_ptrs, eliminating 2 heap allocations per connection.Zero-copy scatter-gather response write
Response headers and body are written as two separate buffers via
asio::async_writewith scatter-gather I/O, avoiding the ~960KBmemcpyfor large response bodies. A custom completion condition removes the default 64KB-per-chunk cap inasync_write.Connection-persistent response objects
responseandheader_bufare members ofconnection_state, reusing allocated capacity across keep-alive requests instead of allocating per-request.Response header construction
appendinstead of 5)glz::to_charsreplacesstd::to_stringfor zero-allocation integer formattingunordered_map::find()lookupsthread_localRequest parsing
std::from_charsreplacesstd::stoulfor Content-Length (no exception overhead)to_lower_case()ci_containsfor Connection/Upgrade header checksfrom_stringalready validates)Other
shutdown_sendinstead ofshutdown_bothfor connection close (matches Beast)close()callremote_ipresolution (deferred from accept to handler invocation)response::clear()called between keep-alive requests to prevent stale header leakageResponse struct changes (
http_router.hpp)header_flagenum anduser_headers_setbitfield toresponsefor tracking which default headers the user has overriddenresponse::header()lowercases names in-place and sets bitflagsresponse::clear()resets the bitfieldresponse::body()usesassign()for capacity reuseBenchmark suite (
http_benchmark/)New benchmark comparing Glaze and Boost.Beast HTTP servers across: