Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance Sample36 by UnixDomainSocket
- Loading branch information
pavel.mash
committed
Dec 8, 2018
1 parent
16e9c70
commit aaf22a9
Showing
4 changed files
with
153 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Simple mORMot server for REST benchmark | ||
|
||
## Socket based server | ||
|
||
- compile and run RESTBenchmark | ||
- test it with browser: | ||
- http://localhost:8888/root/abc | ||
- http://localhost:8888/root/xyz | ||
- test it with Apache Bench | ||
``` | ||
ab -n 10000 -c 1000 http://localhost:8888/root/abc | ||
``` | ||
|
||
## Keep alive | ||
By default mROMot HTTP server runs in KeepAlive mode. | ||
|
||
To disable KeepAlive run `RESTBenchmark` with secont parameter `false` | ||
``` | ||
./RESTBenchmark 8888 false | ||
``` | ||
|
||
Disabling KeepAlive make sence in case mORMotserver is behind the reverse proxy. | ||
In this case reverse proxy cares about KeepAlive connection pool and mormot can | ||
operate with fixed thread pool size. | ||
|
||
## Unix Domain Socket (Linux) | ||
|
||
### When to use | ||
In case mORMot is behind a local reverse proxy on the environment with a | ||
huge number of incoming connection it's make sence to use a UDS to minimize | ||
unnecessary TCP handshakes between mORMot and reverse proxy. | ||
|
||
To emulate such environment on the syntetic test we can disable keep alive | ||
in RESTBEnchmark by passing `false` to then second parameter | ||
``` | ||
./RESTBenchmark unix false | ||
./RESTBenchmark 8888 false | ||
``` | ||
|
||
### How to run | ||
|
||
- compile program and run with `unix` parameter | ||
``` | ||
./RESTBenchmark unix | ||
``` | ||
|
||
Benchmark will listen on Unix Domain Socket `/tmp/rest-bench.socket` | ||
|
||
- test it with curl | ||
``` | ||
curl --unix-socket /tmp/rest-bench.socket http://localhost/root/abc | ||
``` | ||
|
||
- setup nginx as a reverse proxy | ||
``` | ||
sudo ln -s "$(pwd)/mormot-rest-nginx.conf" /etc/nginx/sites-available | ||
sudo ln -s /etc/nginx/sites-available/mormot-rest-nginx.conf /etc/nginx/sites-enabled | ||
sudo nginx -s reload | ||
``` | ||
|
||
- test it using ab (or better - wrk) | ||
``` | ||
wrk http://localhost:8888/root/abc | ||
``` |
This file contains 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
This file contains 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
59 changes: 59 additions & 0 deletions
59
SQLite3/Samples/36 - Simple REST Benchmark/mormot-rest-nginx.conf
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
upstream mormot-uds { | ||
server unix:/tmp/rest-bench.socket; | ||
keepalive 32; | ||
} | ||
|
||
upstream mormot-sock { | ||
server localhost:8888; | ||
keepalive 32; | ||
} | ||
|
||
server { | ||
listen 8889; | ||
|
||
server_name localhost; | ||
|
||
access_log /dev/null; | ||
# prevent nginx version exposing in Server header | ||
server_tokens off; | ||
|
||
proxy_set_header Host $host; | ||
# Tell upstream real IP address of client | ||
proxy_set_header X-Real-IP $realip_remote_addr; | ||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
# Do not rewrite a URL while pass it to upstream | ||
proxy_redirect off; | ||
# Let's upstream handle errors | ||
proxy_intercept_errors on; | ||
tcp_nodelay on; | ||
|
||
# proxy all requests to the beckend | ||
location / { | ||
proxy_pass http://mormot-sock; | ||
} | ||
} | ||
|
||
server { | ||
listen 8887; | ||
|
||
server_name localhost; | ||
|
||
access_log /dev/null; | ||
# prevent nginx version exposing in Server header | ||
server_tokens off; | ||
|
||
proxy_set_header Host $host; | ||
# Tell upstream real IP address of client | ||
proxy_set_header X-Real-IP $realip_remote_addr; | ||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | ||
# Do not rewrite a URL while pass it to upstream | ||
proxy_redirect off; | ||
# Let's upstream handle errors | ||
proxy_intercept_errors on; | ||
tcp_nodelay on; | ||
|
||
# proxy all requests to the beckend | ||
location / { | ||
proxy_pass http://mormot-uds; | ||
} | ||
} |