add test & update readme
This commit is contained in:
parent
22c07227d2
commit
b36d999300
|
@ -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
|
### Handlers
|
||||||
|
|
|
@ -5,18 +5,20 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace bserv {
|
namespace bserv {
|
||||||
|
|
||||||
const std::string NAME = "bserv";
|
const std::string NAME = "bserv";
|
||||||
|
|
||||||
const unsigned short PORT = 8080;
|
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 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 std::string LOG_PATH = "./log/" + NAME;
|
||||||
|
|
||||||
const int NUM_DB_CONN = 10;
|
const int NUM_DB_CONN = 10;
|
||||||
|
|
|
@ -45,7 +45,7 @@ private:
|
||||||
std::shared_ptr<session_manager_base> session_mgr_;
|
std::shared_ptr<session_manager_base> session_mgr_;
|
||||||
std::shared_ptr<db_connection_manager> db_conn_mgr_;
|
std::shared_ptr<db_connection_manager> db_conn_mgr_;
|
||||||
public:
|
public:
|
||||||
server(const server_config& config, router&& routes, router&& ws_routes);
|
server(const server_config& config, router&& routes, router&& ws_routes = {});
|
||||||
};
|
};
|
||||||
|
|
||||||
} // bserv
|
} // bserv
|
||||||
|
|
10
main.cpp
10
main.cpp
|
@ -12,8 +12,8 @@ void show_usage(const bserv::server_config& config) {
|
||||||
"Option:\n"
|
"Option:\n"
|
||||||
" -h, --help show help and exit\n"
|
" -h, --help show help and exit\n"
|
||||||
" -p, --port port (default: 8080)\n"
|
" -p, --port port (default: 8080)\n"
|
||||||
" --threads number of threads (default: 4)\n"
|
" --threads number of threads (default: # of cpu cores)\n"
|
||||||
" --rotation log rotation size in mega bytes (default: 4)\n"
|
" --rotation log rotation size in mega bytes (default: 8)\n"
|
||||||
" --log-path log path (default: ./log/bserv)\n"
|
" --log-path log path (default: ./log/bserv)\n"
|
||||||
" --num-conn number of database connections (default: 10)\n"
|
" --num-conn number of database connections (default: 10)\n"
|
||||||
" -c, --conn-str connection string (default: dbname=bserv)"
|
" -c, --conn-str connection string (default: dbname=bserv)"
|
||||||
|
@ -125,11 +125,13 @@ int main(int argc, char* argv[]) {
|
||||||
bserv::placeholders::json_params),
|
bserv::placeholders::json_params),
|
||||||
bserv::make_path("/echo", &echo,
|
bserv::make_path("/echo", &echo,
|
||||||
bserv::placeholders::json_params)
|
bserv::placeholders::json_params)
|
||||||
}, {
|
}
|
||||||
|
, {
|
||||||
bserv::make_path("/echo", &ws_echo,
|
bserv::make_path("/echo", &ws_echo,
|
||||||
bserv::placeholders::session,
|
bserv::placeholders::session,
|
||||||
bserv::placeholders::websocket_server_ptr)
|
bserv::placeholders::websocket_server_ptr)
|
||||||
}};
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,21 @@ from pprint import pprint
|
||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
# session = requests.session()
|
def size_test():
|
||||||
# pprint(session.post("http://localhost:8080/send", json={"id": "abc"}).json())
|
session = requests.session()
|
||||||
# pprint(session.post("http://localhost:8080/send", json={"id": "def"}).json())
|
length = 4 * 1024 * 1024 # ~4MB
|
||||||
# pprint(session.post("http://localhost:8080/send", json={"id": "ghi"}).json())
|
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()
|
# exit()
|
||||||
|
|
||||||
P = 100 # number of concurrent processes
|
P = 500 # number of concurrent processes
|
||||||
N = 10 # for each process, the number of sessions
|
N = 10 # for each process, the number of sessions
|
||||||
R = 10 # for each session, the number of posts
|
R = 10 # for each session, the number of posts
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue