Skip to content

Commit 270025e

Browse files
committed
Added benchmark tests using ab to travis
1 parent 34f8219 commit 270025e

File tree

5 files changed

+106
-69
lines changed

5 files changed

+106
-69
lines changed

.travis.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ 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+
- if [ "$PERFORMANCE" = "select" ]; then cd examples; ./benchmark_select 8080 $(nproc) & ; fi;
96+
- if [ "$PERFORMANCE" = "select" ]; then ab -n 10000000 -c 1000 localhost:8080/plaintext; fi;
97+
- if [ "$PERFORMANCE" = "thread" ]; then cd examples; ./benchmark_threads 8080 & ; fi;
98+
- if [ "$PERFORMANCE" = "thread" ]; then ab -n 10000000 -c 1000 localhost:8080/plaintext; fi;
9599
after_success:
96100
- if [ "$DEBUG" = "debug" ] && [ "$COVERAGE" = "coverage" ] && [ "$TRAVIS_OS_NAME" = "linux" ]; then bash <(curl -s https://codecov.io/bash); fi
97101
matrix:
@@ -193,6 +197,26 @@ matrix:
193197
- valgrind-dbg
194198
env:
195199
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && VALGRIND=valgrind"
200+
- os: linux
201+
addons:
202+
apt:
203+
sources:
204+
- ubuntu-toolchain-r-test
205+
packages:
206+
- g++-7
207+
- apache2-utils
208+
env:
209+
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && PERFORMANCE=select"
210+
- os: linux
211+
addons:
212+
apt:
213+
sources:
214+
- ubuntu-toolchain-r-test
215+
packages:
216+
- g++-7
217+
- apache2-utils
218+
env:
219+
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7 && PERFORMANCE=threads"
196220
#- os: osx
197221
# osx_image: xcode8
198222
# 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)