From c0dca252825481a30b299fa6db3e97a991a75bf1 Mon Sep 17 00:00:00 2001 From: gaowanlu <2209120827@qq.com> Date: Mon, 8 Apr 2024 17:23:38 +0800 Subject: [PATCH 1/2] feat: write_end_callback for stream and ws connection --- src/connection/stream_connection.cpp | 6 ++++++ src/connection/stream_connection.h | 1 + src/connection/websocket_connection.cpp | 5 +++++ src/connection/websocket_connection.h | 3 ++- 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/connection/stream_connection.cpp b/src/connection/stream_connection.cpp index d1ae92f..ffce134 100644 --- a/src/connection/stream_connection.cpp +++ b/src/connection/stream_connection.cpp @@ -143,6 +143,10 @@ bool stream_connection::buf2sock(bool &closed) } else { + if (this->write_end_callback) + { + return this->write_end_callback(*this); + } return false; // nothing m_waiting_send_pack to m_send_buffer } } @@ -250,4 +254,6 @@ void stream_connection::reuse() this->should_send_idx = -1; this->should_send_size = 0; this->sock2buf_data_len = 0; + + write_end_callback = nullptr; } \ No newline at end of file diff --git a/src/connection/stream_connection.h b/src/connection/stream_connection.h index 80bbaba..c43b2cd 100644 --- a/src/connection/stream_connection.h +++ b/src/connection/stream_connection.h @@ -43,6 +43,7 @@ namespace tubekit buffer::buffer m_send_buffer; buffer::buffer m_recv_buffer; buffer::buffer m_wating_send_pack; + std::function write_end_callback{nullptr}; private: int should_send_idx{-1}; diff --git a/src/connection/websocket_connection.cpp b/src/connection/websocket_connection.cpp index 875fe7b..3f2ad66 100644 --- a/src/connection/websocket_connection.cpp +++ b/src/connection/websocket_connection.cpp @@ -58,6 +58,7 @@ void websocket_connection::reuse() this->m_wating_send_pack.set_limit_max(mem_buffer_size_max); this->destory_callback = nullptr; + this->write_end_callback = nullptr; http_parser_init(&m_http_parser, HTTP_REQUEST); m_http_parser.data = this; @@ -209,6 +210,10 @@ bool websocket_connection::buf2sock(bool &closed) } else { + if (this->write_end_callback) + { + return this->write_end_callback(*this); + } return false; // noting m_waiting_send_pack to m_send_buffer } } diff --git a/src/connection/websocket_connection.h b/src/connection/websocket_connection.h index 4d3bf3f..64ad7dc 100644 --- a/src/connection/websocket_connection.h +++ b/src/connection/websocket_connection.h @@ -78,7 +78,8 @@ namespace tubekit buffer::buffer m_send_buffer; buffer::buffer m_wating_send_pack; - std::function destory_callback; + std::function destory_callback{nullptr}; + std::function write_end_callback{nullptr}; private: int should_send_idx{-1}; From ba2c1d4e74f5089088b7f2031078b81c02982940 Mon Sep 17 00:00:00 2001 From: gaowanlu <2209120827@qq.com> Date: Mon, 8 Apr 2024 22:32:42 +0800 Subject: [PATCH 2/2] Update README.md --- README.md | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 41fe1cb..c841046 100644 --- a/README.md +++ b/README.md @@ -68,14 +68,13 @@ support tcp keep-alive stream (protobuf) and http app (http-parser)、websocket ## Requests Per Second -CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60 GHz -Mem: 8GB -OS : WSL2 Ubuntu (Windows 11) +CPU: Intel(R) Core(TM) i5-9600KF CPU @ 3.70 GHz +OS : WSL2 Ubuntu Mem 8GB (Windows 11) ```ini config/main.ini - theads:8 - max_conn:2000 + theads:6 + max_conn:10000 ``` apache2-utils testing @@ -91,30 +90,29 @@ $ ab -c {{concurrency}} -n {{httpRequest}} http://IP:20025/ # apache2-utils ab report concurrency bin/tubekit test/node_http_server.js httpRequest responseBodySize -10 11959.51/sec 3636.00 /sec 10000 890bytes -10 7897.85 /sec 3244.76 /sec 100000 890bytes -10 8050.12 /sec 3047.05 /sec 500000 890bytes +10 14051.34/sec 3004.74 /sec 10000 1072bytes +10 13594.83/sec 3456.10 /sec 100000 1072bytes +10 13208.49/sec 3519.01 /sec 500000 1072bytes -50 9571.97 /sec 3484.50 /sec 10000 890bytes -50 7679.47 /sec 3453.35 /sec 100000 890bytes -50 7744.02 /sec 3389.12 /sec 500000 890bytes +50 14080.68/sec 3860.68 /sec 10000 1072bytes +50 14643.93/sec 3852.66 /sec 100000 1072bytes +50 14618.96/sec 3827.33 /sec 500000 1072bytes -100 10784.61/sec 3819.69 /sec 10000 890bytes -100 7715.26 /sec 3447.19 /sec 100000 890bytes -100 7361.67 /sec 3566.64 /sec 500000 890bytes +100 13570.44/sec 3902.76 /sec 10000 1072bytes +100 14651.17/sec 3940.42 /sec 100000 1072bytes +100 14592.67/sec 3811.21 /sec 500000 1072bytes -500 7744.84 /sec 4101.63 /sec 10000 890bytes -500 7813.42 /sec 3593.05 /sec 100000 890bytes -500 7663.37 /sec 3654.70 /sec 500000 890bytes +500 13165.41/sec 3863.30 /sec 10000 1072bytes +500 14612.57/sec 3896.56 /sec 100000 1072bytes +500 14491.29/sec 3911.07 /sec 500000 1072bytes -1000 10670.04/sec 3381.92 /sec 10000 890bytes -1000 7682.88 /sec 3459.71 /sec 100000 890bytes -1000 7754.77 /sec 3667.54 /sec 500000 890bytes -1000 7519.90 /sec 3691.43 /sec 1000000 890bytes +1000 14195.35/sec 3271.67 /sec 10000 1072bytes +1000 14648.93/sec 3685.15 /sec 100000 1072bytes +1000 14601.71/sec 3879.07 /sec 500000 1072bytes +1000 14655.50/sec 3666.36 /sec 1000000 1072bytes ``` ## Third-Party 1、[@http-parser](https://github.com/nodejs/http-parser) 2、[@lua](https://github.com/lua/lua) 3、[@protobuffer](https://github.com/protocolbuffers/protobuf) 4、[@openssl](https://github.com/openssl/openssl) -