Kimserver is an async tcp multiple processes (master & workers) high-performance server.
resources: Nebula / thunder / redis / hiredis / nginx / http-parser / jemalloc .
Enable C++11 and install third party libs.
3rd | version |
---|---|
g++ | 4.2.1 |
libev | 4.27 |
protobuf | 4.0.0 |
cryptopp | 8.1.0 |
hiredis | 0.14.0 |
jemalloc | 5.2.1 |
mariadb-connector-c | 3.1.9 |
[note] Install protobuf use script: install_protobuf.sh
Run on Linux / MacOS
./run.sh
{
"worker_cnt": 4,
"node_type": "gate",
"server_name": "kimserver",
"node_host": "127.0.0.1",
"node_port": 3344,
"gate_host": "127.0.0.1",
"gate_port": 3355,
"gate_codec": "http",
"keep_alive": 30,
"log_path": "kimserver.log",
"log_level": "debug",
"modules": [
"module_test.so"
],
"redis": {
"test": {
"host": "127.0.0.1",
"port": 6379
}
},
"database": {
"test": {
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "root123!@#",
"charset": "utf8mb4",
"max_conn_cnt": 1
}
}
}
name | desc |
---|---|
worker_cnt | child process's number. |
node_type | cluster node type. |
server_name | server manager process's name, and child process name format: name_w_number, like: kimserver_w_1. |
node_host | host for cluster inner contact. |
node_port | node port. |
gate_host | host for user's client contact. |
gate_port | gate server port. |
gate_codec | "protobuf", "http". |
keep_alive | connection keep alive time (seconds). |
log_path | log file. path. |
log_level | log level: debug, info, notice, warning, err, crit, alert, emerg. |
modules | protocol route container, work as so. |
redis | redis addr config. |
database | database (mysql) info. |
- request
curl -v -d '{"uid":"hello world"}' http://127.0.0.1:3355/kim/helloworld/ | python -m json.tool
- response
{
"code": 0,
"msg": "ok",
"data": {
"id": "123",
"name": "kimserver"
}
}
namespace kim {
class MoudleTest : public Module {
REGISTER_HANDLER(MoudleTest)
public:
void register_handle_func() {
HANDLE_HTTP_FUNC("/kim/test/", MoudleTest::func_test_cmd);
HANDLE_HTTP_FUNC("/kim/helloworld/", MoudleTest::func_hello_world);
}
private:
Cmd::STATUS func_test_cmd(std::shared_ptr<Request> req) {
// cmd for async/sync logic.
HANDLE_CMD(CmdHello);
}
Cmd::STATUS func_hello_world(std::shared_ptr<Request> req) {
const HttpMsg* msg = req->http_msg();
if (msg == nullptr) {
return Cmd::STATUS::ERROR;
}
LOG_DEBUG("cmd hello, http path: %s, data: %s",
msg->path().c_str(), msg->body().c_str());
CJsonObject data;
data.Add("id", "123");
data.Add("name", "kimserver");
CJsonObject obj;
obj.Add("code", 0);
obj.Add("msg", "ok");
obj.Add("data", data);
return response_http(req->conn(), obj.ToString());
}
};
} // namespace kim