mongols 是一个 C++ 库。
linux
pcre-devel
hiredis-devel
zlib-devel
openssl-devel
curl-devel
sudo yum install pcre-devel zlib-devel openssl-devel hiredis-devel libcurl-devel
或者:
sudo apt-get install libpcre3-dev zlib1g-dev libssl-dev libhiredis-dev libcurl4-openssl-dev
epoll or epoll + multi-threading
tcp sever
http server
websocket server
web server
leveldb server
lua server
sqlite server
utils
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/web_server.hpp>#include<mongols/leveldb_server.hpp>#include<mongols/util.hpp>#include/* //websocket server int main(int,char**){ int port=9090; const char* host="127.0.0.1"; mongols::ws_server server(host,port,5000,2048,4); auto f=[](const std::string& input , bool& keepalive , bool& send_to_other , mongols::tcp_server::client_t& client , mongols::tcp_server::filter_handler_function& send_to_other_filter){ keepalive = KEEPALIVE_CONNECTION; send_to_other=true; if(input=="close"){ keepalive = CLOSE_CONNECTION; send_to_other = false; } }; server.run(f); //server.run(); } */ /* //tcp server or tcp multi-threading server int main(int,char**) { auto f=[](const std::string& input , bool & keepalive , bool& send_to_other , mongols::tcp_server::client_t& client , mongols::tcp_server::filter_handler_function& send_to_other_filter){ keepalive= KEEPALIVE_CONNECTION; send_to_other=true; return input; }; 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::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); } /* //web server or multi-threading server int main(int,char**) { auto f=[](const mongols::request&){ if(req.method=="GET"&&req.uri.find("..")==std::string::npos){ return true; } return false; }; int port=9090; const char* host="127.0.0.1"; mongols::web_server //server(host,port,5000,1024,4); server(host,port); server.set_root_path("html"); server.set_mime_type_file("mime.conf"); server.set_list_directory(true); server.run(f); } */ /* //leveldb_server or multi-threading server int main(int,char**){ int port=9090; const char* host="127.0.0.1"; mongols::leveldb_server //server(host,port,5000,1024,4); server(host,port); server.run("html/leveldb"); } */
压力测试:
[centos@localhost demo]$ uname -a Linux localhost 3.10.0-862.9.1.el7.x86_64 #1 SMP Mon Jul 16 16:29:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux [centos@localhost demo]$ cat /proc/cpuinfo| grep "processor"| wc -l 4 [centos@localhost demo]$ cat /proc/cpuinfo| grep "cpu cores"| uniq cpu cores: 2 [centos@localhost demo]$ cat /proc/cpuinfo| grep "physical id"| sort| uniq| wc -l 1
ab -c1000 -n100000 http://127.0.0.1:9090/
Server Software: mongols/0.9.0 Server Hostname: 127.0.0.1 Server Port: 9090 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 8.180 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 0 Total transferred: 13300000 bytes HTML transferred: 1300000 bytes Requests per second: 12225.00 [#/sec] (mean) Time per request: 81.800 [ms] (mean) Time per request: 0.082 [ms] (mean, across all concurrent requests) Transfer rate: 1587.82 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 66 263.3 7 3020 Processing: 2 11 11.9 9 831 Waiting: 0 8 11.5 7 829 Total: 6 77 265.8 16 3033 Percentage of the requests served within a certain time (ms) 50% 16 66% 20 75% 22 80% 23 90% 29 95% 1017 98% 1025 99% 1030 100% 3033 (longest request)
ab -kc1000 -n100000 -H'Connection: keep-alive' http://127.0.0.1:9090/
Server Software: mongols/0.9.0 Server Hostname: 127.0.0.1 Server Port: 9090 Document Path: / Document Length: 13 bytes Concurrency Level: 1000 Time taken for tests: 1.935 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Keep-Alive requests: 100000 Total transferred: 13800000 bytes HTML transferred: 1300000 bytes Requests per second: 51671.74 [#/sec] (mean) Time per request: 19.353 [ms] (mean) Time per request: 0.019 [ms] (mean, across all concurrent requests) Transfer rate: 6963.57 [Kbytes/sec] received Connection Times (ms) min mean[+/-sd] median max Connect: 0 0 3.2 0 48 Processing: 8 19 1.4 18 48 Waiting: 0 19 1.4 18 25 Total: 8 19 3.1 18 64 Percentage of the requests served within a certain time (ms) 50% 18 66% 19 75% 19 80% 19 90% 20 95% 21 98% 23 99% 28 100% 64 (longest request)
release-1.8.4.16 release-1.8.4.15 release-1.8.4.14 release-1.8.4.13 release-1.8.4.12 release-1.8.4.11 release-1.8.4.10 release-1.8.4.9 release-1.8.4.8 release-1.8.4.7 release-1.8.4.6 release-1.8.4.5 r
Rest is not idleness, and to lie sometimes on the grass under trees on a summer’s day, listening to the murmur of the water, or watching the clouds float across the sky, is by no means a waste of time
Config配置类 StaticCache静态缓存类 Route路由类 Controller控制器类 View视图类 Request请求类 Response响应类 Event事件类 Listener监听类 Subscriber多事件监听 EventDispatcher事件调度
Controller控制器 第一个控制器 {#1第一个控制器} <?php namespace src\Web\Controller\Group; use Controller; use Request; use JsonResponse; class GroupController extends Controller { public function indexAction()
在本节中,我们将进行服务器端攻击。首先我们将使用信息收集,用于显示已安装的程序,目标的操作系统,目标上的运行服务以及与这些服务关联的端口。从这些已安装的服务中,我们可以尝试进入系统,可以通过尝试默认密码来完成此操作。 有很多人安装服务并错误配置它们,所以我们还有通过一个例子来演示。这些服务的第一个问题是,有时,许多服务旨在让某人远程访问该计算机,但他们显然需要一些安全实现。人们经常错误配置这些服务
本文向大家介绍微服务设计的基础是什么?相关面试题,主要包含被问及微服务设计的基础是什么?时的应答技巧和注意事项,需要的朋友参考一下 这可能是最常见的微服务面试问题之一。在回答这个问题时,你需要记住以下内容: 定义范围。 结合低耦合和高内聚。 创建一个有唯一标识的服务,唯一标识将充当识别源,非常像数据库表中的唯一键。 创建正确的API并在集成过程中特别注意。 限制对数据的访问并将其限制到所需级别。
Listener 原型 <?php namespace Group\Listeners; abstract class Listener { abstract function setMethod(); public function getMethod() { return $this->setMethod(); } } 实现一个监听类 <?php
Event事件 自定义事件 事件对象Event,自定义Event {#事件对象event与如何定义一个event,例如:} <?php namespace Group\Events; class Event { protected $property; public function __construct($property = null) { $th
Response 参照symfony2的Response服务 常规 {#常规} public function testAction(Request $request, $id) { yield new \Response('这是文本'); } json格式 {#json格式} public function testAction(Request $