内容简介:mongols-0.9.2已经发布。mongols是一个主要针对c++服务器端开发的基础设施库。主要特性如下:
mongols-0.9.2已经发布。
主要更新:
-
添加zstd库
-
为http server优化会话和缓存管理
介绍:
mongols是一个主要针对c++服务器端开发的基础设施库。主要特性如下:
-
tcp sever (epoll)
-
tcp multi-threading server (epoll+multi-threading)
-
http server (epoll)
-
http multi-threading server (epoll+multi-threading)
-
websocket server (epoll+multi-threading)
-
utils
依赖:
-
linux
-
gcc(c11),g++(c++11)
-
pcre-devel
-
zlib-devel
-
openssl-devel
sudo yum install pcre-devel zlib-devel openssl-devel
或者:
sudo apt-get install libpcre3-dev zlib1g-dev libssl-dev
安装:
make clean && make -j2 && sudo make install && sudo ldconfig
使用:
pkg-config --libs --cflags mongols
例子:
#include <mongols/tcp_server.hpp> #include <mongols/tcp_threading_server.hpp> #include <mongols/http_server.hpp> #include <mongols/ws_server.hpp> #include <mongols/util.hpp> #include <iostream> /* //websocket server int main(int,char**){ int port=9090; const char* host="127.0.0.1"; mongols::ws_server server(host,port); auto f=[](const std::string& input , bool& keepalive , bool& send_to_other , std::pair<size_t, size_t>& g_u_id , mongols::tcp_server::filter_handler_function& send_to_other_filter){ keepalive = KEEPALIVE_CONNECTION; send_to_other=true; return input; }; server.run(f); server.run(); } */ /* //tcp server or tcp multi-threading server int main(int,char**) { auto f=[](const std::string& input , bool& send_to_other , std::pair<size_t, size_t>& g_u_id , mongols::tcp_server::filter_handler_function& send_to_other_filter){ send_to_other=true; return std::make_pair(input,KEEPALIVE_CONNECTION); }; int port=9090; const char* host="127.0.0.1"; mongols::tcp_threading_server //mongols::tcp_server server(host,port); server.run(f); } */ //http server or multi-threading server int main(int,char**) { auto f=[](const mongols::request&){ return true; }; auto g=[](const mongols::request& req,mongols::response& res){ /*std::unordered_map<std::string, std::string>::const_iterator i; if((i=req.session.find("test"))!=req.session.end()){ long test=std::stol(i->second)+1; res.content=std::to_string(test); res.session["test"]=res.content; }else{ res.content=std::to_string(0);; res.session["test"]=res.content; }*/ res.content=std::move("hello,world"); res.status=200; }; int port=9090; const char* host="127.0.0.1"; mongols::http_server //server(host,port,5000,1024,4); server(host,port); server.set_enable_session(false); server.set_enable_cache(false); server.run(f,g); }
压力测试:
2核4G,centos7
ab -c1000 -n100000 http://127.0.0.1:9090/
RPS: 10000+
ab -kc1000 -n100000 -H'Connection: keep-alive' http://127.0.0.1:9090/
RPS: 50000+
在ubuntu 18.04上RPS更高,keep-alive,高达80000-120000。
-
websocket demo: http://fusheng.hi-nginx.com/
-
demo source: https://github.com/webcpp/fusheng
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Head First WordPress
Siarto Jeff / O'Reilly Media / 2010-02-15 / USD 34.99
Whether you're promoting your business or writing about your travel adventures, "Head First WordPress" will teach you not only how to make your blog look unique and attention-grabbing, but also how to......一起来看看 《Head First WordPress》 这本书的介绍吧!