mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2026-11-22 20:11:46 +00:00
Run the test suite with keep-alive parking on in CI, and mark it experimental
CPPHTTPLIB_KEEPALIVE_PARKING makes every Server start with parking on. The OpenSSL jobs on Ubuntu (epoll) and macOS (kqueue) now also run the whole suite built with it, which used to be done only locally. The two tests that check the blocking path turn parking off explicitly. README and the cookbook call the feature experimental and say that a server whose event loop cannot be set up serves as it does without it.
This commit is contained in:
1 parent
f09081e320
commit
51b186974b
8 files changed
+42
-4
No files matched your search
@@ -109,6 +109,11 @@ jobs:
|
|||||||
run: cd test && make test_split && make test_openssl_parallel
|
run: cd test && make test_split && make test_openssl_parallel
|
||||||
env:
|
env:
|
||||||
LSAN_OPTIONS: suppressions=lsan_suppressions.txt
|
LSAN_OPTIONS: suppressions=lsan_suppressions.txt
|
||||||
|
- name: build and run tests with keep-alive parking on (OpenSSL)
|
||||||
|
if: matrix.tls_backend == 'openssl'
|
||||||
|
run: cd test && make test_parking_parallel
|
||||||
|
env:
|
||||||
|
LSAN_OPTIONS: suppressions=lsan_suppressions.txt
|
||||||
- name: build and run tests (Mbed TLS)
|
- name: build and run tests (Mbed TLS)
|
||||||
if: matrix.tls_backend == 'mbedtls'
|
if: matrix.tls_backend == 'mbedtls'
|
||||||
run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
|
run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
|
||||||
@@ -417,6 +422,11 @@ jobs:
|
|||||||
run: cd test && make test_split && make test_openssl_parallel
|
run: cd test && make test_split && make test_openssl_parallel
|
||||||
env:
|
env:
|
||||||
LSAN_OPTIONS: suppressions=lsan_suppressions.txt
|
LSAN_OPTIONS: suppressions=lsan_suppressions.txt
|
||||||
|
- name: build and run tests with keep-alive parking on (OpenSSL)
|
||||||
|
if: matrix.tls_backend == 'openssl'
|
||||||
|
run: cd test && make test_parking_parallel
|
||||||
|
env:
|
||||||
|
LSAN_OPTIONS: suppressions=lsan_suppressions.txt
|
||||||
- name: build and run tests (Mbed TLS)
|
- name: build and run tests (Mbed TLS)
|
||||||
if: matrix.tls_backend == 'mbedtls'
|
if: matrix.tls_backend == 'mbedtls'
|
||||||
run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
|
run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ test/test
|
|||||||
test/test_mbedtls
|
test/test_mbedtls
|
||||||
test/test_wolfssl
|
test/test_wolfssl
|
||||||
test/test_no_tls
|
test/test_no_tls
|
||||||
|
test/test_parking
|
||||||
test/server_fuzzer
|
test/server_fuzzer
|
||||||
test/client_fuzzer
|
test/client_fuzzer
|
||||||
test/header_parser_fuzzer
|
test/header_parser_fuzzer
|
||||||
|
|||||||
@@ -921,10 +921,15 @@ svr.set_keep_alive_timeout(10); // Default is 5
|
|||||||
|
|
||||||
#### Keep-alive parking
|
#### Keep-alive parking
|
||||||
|
|
||||||
|
> [!NOTE]
|
||||||
|
> Keep-alive parking is experimental. Its behavior may change in a future release.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
svr.set_keep_alive_parking(true); // Call it before listen()
|
svr.set_keep_alive_parking(true); // Call it before listen()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Defining `CPPHTTPLIB_KEEPALIVE_PARKING` as `true` turns it on for every `Server` from the start. If the event loop cannot be set up, the server serves as it does without it.
|
||||||
|
|
||||||
By default, a kept-alive connection holds a worker thread while it waits for its next request, so connections beyond the thread count wait for one to be closed. With keep-alive parking, a connection waiting for its next request is handed to an event loop instead, and goes back to a worker when the request arrives. An idle connection then costs a socket and a few kilobytes instead of a thread, and connections that outnumber the threads take turns.
|
By default, a kept-alive connection holds a worker thread while it waits for its next request, so connections beyond the thread count wait for one to be closed. With keep-alive parking, a connection waiting for its next request is handed to an event loop instead, and goes back to a worker when the request arrives. An idle connection then costs a socket and a few kilobytes instead of a thread, and connections that outnumber the threads take turns.
|
||||||
|
|
||||||
With it:
|
With it:
|
||||||
|
|||||||
@@ -56,11 +56,13 @@ By default, a Keep-Alive connection holds a worker thread for its entire lifetim
|
|||||||
|
|
||||||
## Keep idle connections off the threads
|
## Keep idle connections off the threads
|
||||||
|
|
||||||
|
> **Note:** Keep-alive parking is experimental. Its behavior may change in a future release.
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
svr.set_keep_alive_parking(true); // call it before listen()
|
svr.set_keep_alive_parking(true); // call it before listen()
|
||||||
```
|
```
|
||||||
|
|
||||||
With keep-alive parking, a connection waiting for its next request is handed to an event loop instead of keeping its worker thread, and goes back to a worker when the request arrives. An idle connection then costs a socket and some memory (a few kilobytes, more with TLS) instead of a thread, and connections that outnumber the threads take turns instead of waiting for one to close. `SSLServer` supports it too.
|
With keep-alive parking, a connection waiting for its next request is handed to an event loop instead of keeping its worker thread, and goes back to a worker when the request arrives. An idle connection then costs a socket and some memory (a few kilobytes, more with TLS) instead of a thread, and connections that outnumber the threads take turns instead of waiting for one to close. `SSLServer` supports it too. Defining `CPPHTTPLIB_KEEPALIVE_PARKING` as `true` turns it on for every server.
|
||||||
|
|
||||||
What changes with it:
|
What changes with it:
|
||||||
|
|
||||||
|
|||||||
@@ -56,11 +56,13 @@ svr.set_keep_alive_max_count(1000);
|
|||||||
|
|
||||||
## アイドル接続にスレッドを持たせない
|
## アイドル接続にスレッドを持たせない
|
||||||
|
|
||||||
|
> **Note:** Keep-Aliveのパーキングは実験的な機能です。今後のリリースで挙動が変わることがあります。
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
svr.set_keep_alive_parking(true); // listen()の前に呼ぶ
|
svr.set_keep_alive_parking(true); // listen()の前に呼ぶ
|
||||||
```
|
```
|
||||||
|
|
||||||
Keep-Aliveのパーキングを有効にすると、次のリクエストを待っている接続はワーカースレッドを手放してイベントループに預けられ、リクエストが届くとまたワーカーに戻ります。アイドル接続のコストはスレッド1つではなく、ソケットと少しのメモリ(数KB、TLSではもう少し多い)になり、スレッド数より多い接続も、どれかが閉じるのを待たずに順番に処理されます。`SSLServer`でも使えます。
|
Keep-Aliveのパーキングを有効にすると、次のリクエストを待っている接続はワーカースレッドを手放してイベントループに預けられ、リクエストが届くとまたワーカーに戻ります。アイドル接続のコストはスレッド1つではなく、ソケットと少しのメモリ(数KB、TLSではもう少し多い)になり、スレッド数より多い接続も、どれかが閉じるのを待たずに順番に処理されます。`SSLServer`でも使えます。`CPPHTTPLIB_KEEPALIVE_PARKING`を`true`と定義すると、すべてのサーバーで最初から有効になります。
|
||||||
|
|
||||||
有効にすると変わること:
|
有効にすると変わること:
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,11 @@
|
|||||||
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5
|
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_SECOND 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Whether a Server starts with set_keep_alive_parking(true).
|
||||||
|
#ifndef CPPHTTPLIB_KEEPALIVE_PARKING
|
||||||
|
#define CPPHTTPLIB_KEEPALIVE_PARKING false
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_CHECK_INTERVAL_USECOND
|
#ifndef CPPHTTPLIB_KEEPALIVE_TIMEOUT_CHECK_INTERVAL_USECOND
|
||||||
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_CHECK_INTERVAL_USECOND 10000
|
#define CPPHTTPLIB_KEEPALIVE_TIMEOUT_CHECK_INTERVAL_USECOND 10000
|
||||||
#endif
|
#endif
|
||||||
@@ -14552,6 +14557,7 @@ inline Server::Server()
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
#endif
|
#endif
|
||||||
|
set_keep_alive_parking(CPPHTTPLIB_KEEPALIVE_PARKING);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Server::~Server() = default;
|
inline Server::~Server() = default;
|
||||||
|
|||||||
+10
-2
@@ -100,7 +100,7 @@ define run_parallel
|
|||||||
echo "All shards passed."
|
echo "All shards passed."
|
||||||
endef
|
endef
|
||||||
|
|
||||||
.PHONY: test_openssl_parallel test_mbedtls_parallel test_wolfssl_parallel test_no_tls_parallel
|
.PHONY: test_openssl_parallel test_mbedtls_parallel test_wolfssl_parallel test_no_tls_parallel test_parking_parallel
|
||||||
|
|
||||||
test_openssl_parallel : test
|
test_openssl_parallel : test
|
||||||
$(call run_parallel,test)
|
$(call run_parallel,test)
|
||||||
@@ -114,6 +114,9 @@ test_wolfssl_parallel : test_wolfssl
|
|||||||
test_no_tls_parallel : test_no_tls
|
test_no_tls_parallel : test_no_tls
|
||||||
$(call run_parallel,test_no_tls)
|
$(call run_parallel,test_no_tls)
|
||||||
|
|
||||||
|
test_parking_parallel : test_parking
|
||||||
|
$(call run_parallel,test_parking)
|
||||||
|
|
||||||
proxy : test_proxy
|
proxy : test_proxy
|
||||||
@echo "Starting proxy server..."
|
@echo "Starting proxy server..."
|
||||||
cd proxy && \
|
cd proxy && \
|
||||||
@@ -201,6 +204,11 @@ test_no_tls : test.cc include_httplib.cc ../httplib.h Makefile
|
|||||||
$(CXX) -o $@ -I.. $(CXXFLAGS) test.cc include_httplib.cc $(TEST_ARGS_NO_TLS)
|
$(CXX) -o $@ -I.. $(CXXFLAGS) test.cc include_httplib.cc $(TEST_ARGS_NO_TLS)
|
||||||
@file $@
|
@file $@
|
||||||
|
|
||||||
|
# The whole suite with keep-alive parking on by default
|
||||||
|
test_parking : test.cc include_httplib.cc ../httplib.h Makefile cert.pem
|
||||||
|
$(CXX) -o $@ -I.. $(CXXFLAGS) -DCPPHTTPLIB_KEEPALIVE_PARKING=true test.cc include_httplib.cc $(TEST_ARGS)
|
||||||
|
@file $@
|
||||||
|
|
||||||
test_split_no_tls : test.cc ../httplib.h httplib.cc Makefile
|
test_split_no_tls : test.cc ../httplib.h httplib.cc Makefile
|
||||||
$(CXX) -o $@ $(CXXFLAGS) test.cc httplib.cc $(TEST_ARGS_NO_TLS)
|
$(CXX) -o $@ $(CXXFLAGS) test.cc httplib.cc $(TEST_ARGS_NO_TLS)
|
||||||
|
|
||||||
@@ -321,5 +329,5 @@ cert.pem:
|
|||||||
./gen-certs.sh
|
./gen-certs.sh
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf test test_split test_mbedtls test_split_mbedtls test_wolfssl test_split_wolfssl test_no_tls, test_split_no_tls test_proxy test_proxy_mbedtls test_proxy_wolfssl test_benchmark server_fuzzer client_fuzzer header_parser_fuzzer url_parser_fuzzer *.pem *.0 *.o *.1 *.srl httplib.h httplib.cc _build* *.dSYM *_shard_*.log cpp-httplib
|
rm -rf test test_split test_parking test_mbedtls test_split_mbedtls test_wolfssl test_split_wolfssl test_no_tls, test_split_no_tls test_proxy test_proxy_mbedtls test_proxy_wolfssl test_benchmark server_fuzzer client_fuzzer header_parser_fuzzer url_parser_fuzzer *.pem *.0 *.o *.1 *.srl httplib.h httplib.cc _build* *.dSYM *_shard_*.log cpp-httplib
|
||||||
|
|
||||||
@@ -5864,6 +5864,8 @@ TEST(SSLClientServerTest, ClientSessionIsNotResumedPastItsCA) {
|
|||||||
TEST(SSLClientServerTest, UpdateCertsPemWaitsForHandshakeInProgress) {
|
TEST(SSLClientServerTest, UpdateCertsPemWaitsForHandshakeInProgress) {
|
||||||
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
|
SSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE);
|
||||||
ASSERT_TRUE(svr.is_valid());
|
ASSERT_TRUE(svr.is_valid());
|
||||||
|
// Keep-alive parking would wait for the ClientHello without a handshake.
|
||||||
|
svr.set_keep_alive_parking(false);
|
||||||
svr.Get("/test", [](const Request &, Response &res) {
|
svr.Get("/test", [](const Request &, Response &res) {
|
||||||
res.set_content("ok", "text/plain");
|
res.set_content("ok", "text/plain");
|
||||||
});
|
});
|
||||||
@@ -17495,6 +17497,8 @@ TEST(SSLClientServerTest, SSLConnectTimeout) {
|
|||||||
NoListenSSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE,
|
NoListenSSLServer svr(SERVER_CERT_FILE, SERVER_PRIVATE_KEY_FILE,
|
||||||
CLIENT_CA_CERT_FILE);
|
CLIENT_CA_CERT_FILE);
|
||||||
ASSERT_TRUE(svr.is_valid());
|
ASSERT_TRUE(svr.is_valid());
|
||||||
|
// Keep-alive parking would bypass the override.
|
||||||
|
svr.set_keep_alive_parking(false);
|
||||||
|
|
||||||
svr.Get("/test", [&](const Request &, Response &res) {
|
svr.Get("/test", [&](const Request &, Response &res) {
|
||||||
res.set_content("test", "text/plain");
|
res.set_content("test", "text/plain");
|
||||||
|
|||||||
Reference in new issue
Block a user