Skip to content

Commit 19e3f31

Browse files
authored
Merge pull request #139 from etr/apache_bench
Add apache benchmark to travis
2 parents 45cf791 + daa221b commit 19e3f31

File tree

5 files changed

+114
-69
lines changed

5 files changed

+114
-69
lines changed

.travis.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ script:
9292
- ls -l /usr/local/lib/
9393
- ls -l /usr/lib/
9494
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then cd ../src/; cppcheck --error-exitcode=1 .; cd ../build; fi
95+
- |
96+
if [ "$PERFORMANCE" = "select" ]; then
97+
cd examples
98+
./benchmark_select 8080 $(nproc) &
99+
sleep 5 && ab -n 10000000 -c 100 localhost:8080/plaintext
100+
fi
101+
- |
102+
if [ "$PERFORMANCE" = "threads" ]; then
103+
cd examples
104+
./benchmark_threads 8080 &
105+
sleep 5 && ab -n 10000000 -c 100 localhost:8080/plaintext
106+
fi
95107
after_success:
96108
- if [ "$DEBUG" = "debug" ] && [ "$COVERAGE" = "coverage" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then bash <(curl -s https://codecov.io/bash); fi
97109
matrix:
@@ -193,6 +205,26 @@ matrix:
193205
- valgrind-dbg
194206
env:
195207
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && VALGRIND=valgrind"
208+
- os: linux
209+
addons:
210+
apt:
211+
sources:
212+
- ubuntu-toolchain-r-test
213+
packages:
214+
- g++-7
215+
- apache2-utils
216+
env:
217+
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && PERFORMANCE=select"
218+
- os: linux
219+
addons:
220+
apt:
221+
sources:
222+
- ubuntu-toolchain-r-test
223+
packages:
224+
- g++-7
225+
- apache2-utils
226+
env:
227+
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && PERFORMANCE=threads"
196228
#- os: osx
197229
# osx_image: xcode8
198230
# env:

examples/Makefile.am

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
LDADD = $(top_builddir)/src/libhttpserver.la
2020
AM_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/src/httpserver/
2121
METASOURCES = AUTO
22-
noinst_PROGRAMS = hello_world service minimal_hello_world custom_error allowing_disallowing_methods handlers hello_with_get_arg setting_headers custom_access_log basic_authentication digest_authentication minimal_https minimal_file_response minimal_deferred url_registration minimal_ip_ban
22+
noinst_PROGRAMS = hello_world service minimal_hello_world custom_error allowing_disallowing_methods handlers hello_with_get_arg setting_headers custom_access_log basic_authentication digest_authentication minimal_https minimal_file_response minimal_deferred url_registration minimal_ip_ban benchmark_select benchmark_threads
2323

2424
hello_world_SOURCES = hello_world.cpp
2525
service_SOURCES = service.cpp
@@ -37,3 +37,5 @@ minimal_file_response_SOURCES = minimal_file_response.cpp
3737
minimal_deferred_SOURCES = minimal_deferred.cpp
3838
url_registration_SOURCES = url_registration.cpp
3939
minimal_ip_ban_SOURCES = minimal_ip_ban.cpp
40+
benchmark_select_SOURCES = benchmark_select.cpp
41+
benchmark_threads_SOURCES = benchmark_threads.cpp

examples/benchmark.cpp

Lines changed: 0 additions & 68 deletions
This file was deleted.

examples/benchmark_select.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <httpserver.hpp>
2+
#include <cstdlib>
3+
#include <memory>
4+
5+
#define PATH "/plaintext"
6+
#define BODY "Hello, World!"
7+
8+
using namespace httpserver;
9+
10+
class hello_world_resource : public http_resource {
11+
public:
12+
hello_world_resource(const std::shared_ptr<http_response>& resp):
13+
resp(resp)
14+
{
15+
}
16+
17+
const std::shared_ptr<http_response> render(const http_request&) {
18+
return resp;
19+
}
20+
21+
private:
22+
std::shared_ptr<http_response> resp;
23+
};
24+
25+
int main(int argc, char** argv)
26+
{
27+
webserver ws = create_webserver(atoi(argv[1]))
28+
.start_method(http::http_utils::INTERNAL_SELECT)
29+
.max_threads(atoi(argv[2]));
30+
31+
std::shared_ptr<http_response> hello = std::shared_ptr<http_response>(new string_response(BODY, 200));
32+
hello->with_header("Server", "libhttpserver");
33+
34+
hello_world_resource hwr(hello);
35+
ws.register_resource(PATH, &hwr, false);
36+
37+
ws.start(true);
38+
39+
return 0;
40+
}

examples/benchmark_threads.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <httpserver.hpp>
2+
#include <cstdlib>
3+
#include <memory>
4+
5+
#define PATH "/plaintext"
6+
#define BODY "Hello, World!"
7+
8+
using namespace httpserver;
9+
10+
class hello_world_resource : public http_resource {
11+
public:
12+
hello_world_resource(const std::shared_ptr<http_response>& resp):
13+
resp(resp)
14+
{
15+
}
16+
17+
const std::shared_ptr<http_response> render(const http_request&) {
18+
return resp;
19+
}
20+
21+
private:
22+
std::shared_ptr<http_response> resp;
23+
};
24+
25+
int main(int argc, char** argv)
26+
{
27+
webserver ws = create_webserver(atoi(argv[1]))
28+
.start_method(http::http_utils::THREAD_PER_CONNECTION);
29+
30+
std::shared_ptr<http_response> hello = std::shared_ptr<http_response>(new string_response(BODY, 200));
31+
hello->with_header("Server", "libhttpserver");
32+
33+
hello_world_resource hwr(hello);
34+
ws.register_resource(PATH, &hwr, false);
35+
36+
ws.start(true);
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)