yhirose / cpp-httplib

A C++ header-only HTTP/HTTPS server and client library
MIT License
12.82k stars 2.27k forks source link

If you were to make this server ASYNC, where would you change? #1690

Closed Fransferdy closed 11 months ago

Fransferdy commented 11 months ago

I have been testing a few http servers using Bombardier load testing tool, I tested express js, php with apache and cpp-httplib. I have found out that, as long as the server is not full, it is way faster than the alternatives (1.5ms vs 25ms node vs 23ms php), but once the requests start maxing out the thread switching, it becomes slower than both (at 90% percentile, 96ms vs 33ms node vs 44ms php). I assume this happens because the server is blocking, as per the README. A similar scenario happens with SpringBoot MVC in java vs SpringBoot Webflux(the async server version). I imagine that if we could make an async io fork of this project it would be amazing performance wise, so I wanted to discuss where we would be doing the changes to achieve that, maybe I will take this as a side hobby to do in my spare time.

yhirose commented 11 months ago

@Fransferdy thanks for the feedback. I intentionally made this library as a blocking I/O and multithreading server. It's because my projects require a http library for pretty heavy CPU bound tasks which expect relatively few concurrent requests. So I don't have any plan to move to the async server due to this reuirement.

If you need a HTTP library for small tasks that run at high concurrency level, please consider to use non-blocking I/O, async HTTP libraries below. They should perform better than the cpp-httplib server.

You can also find past issues that mentioned my decision about it. Hope it helps!