add test & update readme

This commit is contained in:
jie 2021-08-08 08:56:35 +08:00
parent 22c07227d2
commit b36d999300
5 changed files with 27 additions and 15 deletions

View File

@ -29,9 +29,9 @@ You can import the sample database:
```
### Routing
### Server & Routing
Configure routing in [routing.hpp](routing.hpp).
Configure server & routing in [main.cpp](main.cpp).
### Handlers

View File

@ -5,18 +5,20 @@
#include <string>
#include <cstddef>
#include <optional>
#include <thread>
namespace bserv {
const std::string NAME = "bserv";
const unsigned short PORT = 8080;
const int NUM_THREADS = 4;
const int NUM_THREADS =
std::thread::hardware_concurrency() > 0 ? std::thread::hardware_concurrency() : 1;
const std::size_t PAYLOAD_LIMIT = 1 * 1024 * 1024;
const std::size_t PAYLOAD_LIMIT = 8 * 1024 * 1024;
const int EXPIRY_TIME = 30; // seconds
const std::size_t LOG_ROTATION_SIZE = 4 * 1024 * 1024;
const std::size_t LOG_ROTATION_SIZE = 8 * 1024 * 1024;
const std::string LOG_PATH = "./log/" + NAME;
const int NUM_DB_CONN = 10;

View File

@ -45,7 +45,7 @@ private:
std::shared_ptr<session_manager_base> session_mgr_;
std::shared_ptr<db_connection_manager> db_conn_mgr_;
public:
server(const server_config& config, router&& routes, router&& ws_routes);
server(const server_config& config, router&& routes, router&& ws_routes = {});
};
} // bserv

View File

@ -12,8 +12,8 @@ void show_usage(const bserv::server_config& config) {
"Option:\n"
" -h, --help show help and exit\n"
" -p, --port port (default: 8080)\n"
" --threads number of threads (default: 4)\n"
" --rotation log rotation size in mega bytes (default: 4)\n"
" --threads number of threads (default: # of cpu cores)\n"
" --rotation log rotation size in mega bytes (default: 8)\n"
" --log-path log path (default: ./log/bserv)\n"
" --num-conn number of database connections (default: 10)\n"
" -c, --conn-str connection string (default: dbname=bserv)"
@ -125,11 +125,13 @@ int main(int argc, char* argv[]) {
bserv::placeholders::json_params),
bserv::make_path("/echo", &echo,
bserv::placeholders::json_params)
}, {
}
, {
bserv::make_path("/echo", &ws_echo,
bserv::placeholders::session,
bserv::placeholders::websocket_server_ptr)
}};
}
};
return EXIT_SUCCESS;
}

View File

@ -8,13 +8,21 @@ from pprint import pprint
from time import time
# session = requests.session()
# pprint(session.post("http://localhost:8080/send", json={"id": "abc"}).json())
# pprint(session.post("http://localhost:8080/send", json={"id": "def"}).json())
# pprint(session.post("http://localhost:8080/send", json={"id": "ghi"}).json())
def size_test():
session = requests.session()
length = 4 * 1024 * 1024 # ~4MB
data = {"id": "a" * length}
res = session.post("http://localhost:8080/echo", json=data).json()
if {"echo": data} != res:
print("size test: failed")
else:
print("size test: ok")
print()
size_test()
# exit()
P = 100 # number of concurrent processes
P = 500 # number of concurrent processes
N = 10 # for each process, the number of sessions
R = 10 # for each session, the number of posts